Registry API¶
DynamicAgentRegistry stores the specialists created at runtime by create_agent,
so task can resolve them by name later. See
Dynamic agents.
DynamicAgentRegistry¶
subagents_pydantic_ai.DynamicAgentRegistry
dataclass
¶
Registry for dynamically created agents.
Provides storage and management for agents created at runtime. Used by the agent factory toolset to track created agents.
Attributes:
| Name | Type | Description |
|---|---|---|
agents |
dict[str, Any]
|
Dictionary mapping agent names to Agent instances. |
configs |
dict[str, SubAgentConfig]
|
Dictionary mapping agent names to their configurations. |
max_agents |
int | None
|
Maximum number of agents allowed. |
Example
Source code in src/subagents_pydantic_ai/registry.py
| Python | |
|---|---|
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 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 188 189 190 191 192 193 194 195 196 197 198 199 200 | |
register(config, agent)
¶
Register a new agent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
SubAgentConfig
|
The agent's configuration. |
required |
agent
|
Any
|
The Agent instance. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If agent name already exists or max_agents reached. |
Source code in src/subagents_pydantic_ai/registry.py
get(name)
¶
Get an agent by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The agent name. |
required |
Returns:
| Type | Description |
|---|---|
Any | None
|
The Agent instance, or None if not found. |
get_config(name)
¶
Get an agent's configuration by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The agent name. |
required |
Returns:
| Type | Description |
|---|---|
SubAgentConfig | None
|
The SubAgentConfig, or None if not found. |
Source code in src/subagents_pydantic_ai/registry.py
get_compiled(name)
¶
Get a compiled agent by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The agent name. |
required |
Returns:
| Type | Description |
|---|---|
CompiledSubAgent | None
|
The CompiledSubAgent, or None if not found. |
Source code in src/subagents_pydantic_ai/registry.py
remove(name)
¶
Remove an agent from the registry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The agent name to remove. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if agent was removed, False if not found. |
Source code in src/subagents_pydantic_ai/registry.py
| Python | |
|---|---|
list_agents()
¶
Get list of all registered agent names.
Returns:
| Type | Description |
|---|---|
list[str]
|
List of agent names. |
list_configs()
¶
Get list of all agent configurations.
Returns:
| Type | Description |
|---|---|
list[SubAgentConfig]
|
List of SubAgentConfig for all registered agents. |
list_compiled()
¶
Get list of all compiled agents.
Returns:
| Type | Description |
|---|---|
list[CompiledSubAgent]
|
List of CompiledSubAgent for all registered agents. |
exists(name)
¶
Check if an agent exists.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The agent name. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if agent exists, False otherwise. |
count()
¶
Get the number of registered agents.
Returns:
| Type | Description |
|---|---|
int
|
Number of agents in the registry. |
clear()
¶
get_summary()
¶
Get a formatted summary of all registered agents.
Returns:
| Type | Description |
|---|---|
str
|
Multi-line string describing all agents. |