Spec API¶
SubAgentSpec is the validated, serialisable form of a SubAgentConfig, for
loading subagent definitions from YAML or JSON.
SubAgentSpec¶
subagents_pydantic_ai.SubAgentSpec
¶
Bases: BaseModel
Declarative subagent configuration for YAML/JSON specs.
A Pydantic model that mirrors SubAgentConfig (a TypedDict) but
provides validation, defaults, and serialization support. This makes
it suitable for loading subagent definitions from YAML or JSON files.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Unique identifier for the subagent. |
description |
str
|
Brief description shown to the parent agent. |
instructions |
str
|
System prompt for the subagent. |
model |
str | None
|
LLM model identifier (e.g. |
can_ask_questions |
bool | None
|
Whether the subagent can ask the parent questions. |
max_questions |
int | None
|
Maximum number of questions per task. |
preferred_mode |
Literal['sync', 'async', 'auto'] | None
|
Default execution mode preference. |
typical_complexity |
Literal['simple', 'moderate', 'complex'] | None
|
Typical task complexity for this subagent. |
typically_needs_context |
bool | None
|
Whether this subagent typically needs user context. |
context_files |
list[str] | None
|
List of context file paths to inject into system prompt. |
agent_kwargs |
dict[str, Any] | None
|
Extra keyword arguments for the |
max_retries |
int | None
|
Extra attempts after a transient failure. |
retry_initial_delay |
float | None
|
Seconds before the first retry. |
retry_max_delay |
float | None
|
Cap for the backoff delay. |
retry_backoff_multiplier |
float | None
|
Delay growth factor per attempt. |
retry_jitter |
bool | None
|
Randomise the backoff delay to avoid a thundering herd. |
on_failure |
str | None
|
Message returned to the parent instead of a |
contain_errors |
bool | None
|
Whether a crash is contained as a |
extra |
dict[str, Any]
|
Generic extensibility dict for consumer libraries. |
The SubAgentConfig keys that cannot survive a round trip through YAML --
agent, agent_factory, toolsets, and retry_on, all of which hold live
Python objects -- have no field here. tests/test_spec.py fails if a new
serialisable key is added to the config without being mirrored.
Source code in src/subagents_pydantic_ai/spec.py
| Python | |
|---|---|
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 | |
to_config()
¶
Convert to a SubAgentConfig TypedDict.
Only fields that were explicitly set (non-None) are included, so a
subagent inherits the library defaults for everything the spec left out.
extra is included when non-empty.
Returns:
| Type | Description |
|---|---|
SubAgentConfig
|
A SubAgentConfig dict suitable for |
Source code in src/subagents_pydantic_ai/spec.py
from_config(config)
classmethod
¶
Create a SubAgentSpec from a SubAgentConfig dict.
Keys holding live Python objects (agent, agent_factory, toolsets,
retry_on) are dropped: they cannot be serialised, and carrying them
would make a spec that does not round-trip.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
SubAgentConfig
|
A SubAgentConfig TypedDict. |
required |
Returns:
| Type | Description |
|---|---|
SubAgentSpec
|
A new SubAgentSpec instance. |