trading_agent.skills.skill_writer
¶
Creates, patches and archives the skills a desk writes for itself.
Every change is snapshotted first, so it can be undone with trading-agent checkpoints restore, and recorded as one JSON line in the desk's skill ledger, workspace/desks/<desk>/skills/ledger.jsonl. The ledger sits outside skills/agent/, so restoring a checkpoint never erases the record of what happened. An archived skill moves to skills/agent/.archive/
Typical usage example:
writer = SkillWriter(library, checkpoints, ledger_file) writer.create('gap-down-playbook', 'What to do when NIFTY gaps down.', body, [], [], 'learned on 19 Oct')
SkillWriteError
¶
Bases: ValueError
A skill change was refused, with a reason the desk can act on.
SkillWriter
¶
Changes one desk's own skills.
Creates the writer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
library
|
SkillLibrary
|
The desk's skills, for name checks. |
required |
checkpoints
|
Checkpoints | None
|
Snapshots the desk's files before each change, or None to take none. |
required |
ledger_file
|
Path
|
The JSON-lines record of every change. |
required |
Source code in src/trading_agent/skills/skill_writer.py
create
¶
Writes a new skill.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The skill's name. |
required |
description
|
str
|
When to use it. |
required |
body
|
str
|
The Markdown instructions. |
required |
required_programs
|
list[str]
|
Programs it needs. |
required |
required_environment
|
list[str]
|
Environment variables it needs. |
required |
reason
|
str
|
Why it was written, for the ledger. |
required |
Returns:
| Type | Description |
|---|---|
Path
|
The new SKILL.md. |
Raises:
| Type | Description |
|---|---|
SkillWriteError
|
The name or description is not valid, or a skill of that name exists. |
Source code in src/trading_agent/skills/skill_writer.py
patch
¶
Replaces exact text in one of the desk's skills, frontmatter included.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The skill's name. |
required |
old_text
|
str
|
The text to replace, which must appear exactly once. |
required |
new_text
|
str
|
The replacement. |
required |
reason
|
str
|
Why, for the ledger. |
required |
Returns:
| Type | Description |
|---|---|
int
|
The skill file's new length in characters. |
Raises:
| Type | Description |
|---|---|
SkillWriteError
|
The skill is not the desk's own, old_text is missing or repeated, or the result is not a valid skill. |
Source code in src/trading_agent/skills/skill_writer.py
archive
¶
Moves one of the desk's skills out of use, into the archive.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The skill's name. |
required |
reason
|
str
|
Why, for the ledger. |
required |
Returns:
| Type | Description |
|---|---|
Path
|
Where the skill now lives. |
Raises:
| Type | Description |
|---|---|
SkillWriteError
|
The skill is not the desk's own. |