trading_agent.subagents.subagent_definition
¶
One subagent: a helper a desk can hand a task to, defined in a Markdown file.
The format is Claude Code's subagent format, so definitions can be shared with it. YAML frontmatter, then the subagent's instructions:
name: news_reader description: Reads recent news about a company or index and reports what matters for trading. tools: web_search, web_fetch, search_knowledge model: qwen max_turns: 12 timeout: 300
You read news for a trading desk...
toolsis a comma-separated list or a YAML list. Without it the subagent gets a safe, read-only set. Order tools are given only when listed by name.modelis a backend name from trading_agent.toml, a list of them in order of preference, or "inherit" for the desk's own order. Claude Code's aliases opus, sonnet and haiku mean the Claude backend with that model.max_turnsandtimeout(seconds) are trading-agent's additions; Claude Code ignores them.
Typical usage example:
definition = SubagentParser().parse(Path('workspace/shared/agents/news_reader.md'))
SubagentFormatError
¶
Bases: ValueError
A subagent file has no frontmatter, or a field is not valid.
SubagentDefinition
dataclass
¶
SubagentDefinition(name, description, instructions, tool_names, models, maximum_turns, timeout_seconds, path)
One subagent.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
The subagent's name, used by delegate_task. |
description |
str
|
When to use it, shown to the desk. |
instructions |
str
|
Its system prompt, the Markdown after the frontmatter. |
tool_names |
tuple[str, ...] | None
|
The tools it asked for, or None for the default read-only set. |
models |
tuple[str, ...] | None
|
The backends or Claude aliases it asked for, in order, or None to inherit the desk's order. |
maximum_turns |
int
|
The most model calls one task may make. |
timeout_seconds |
int
|
How long one task may run before it is stopped. |
path |
Path
|
The file it was read from. |
SubagentParser
¶
Reads subagent files.
parse
¶
Reads one subagent file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
The Markdown file. |
required |
Returns:
| Type | Description |
|---|---|
SubagentDefinition
|
The subagent. |
Raises:
| Type | Description |
|---|---|
SubagentFormatError
|
The file has no frontmatter, or its name, description, model or limits are not valid. |