Agents
Agent Types¶
Every agent in a pool implements the same interface (BaseAgent), whatever runs it:
type |
Name | Description |
|---|---|---|
native |
Agent Configuration | Configuration for a single agent in the system. |
agui |
AGUIAgentConfig | Configuration for AG-UI protocol agents. |
antigravity |
AntigravityAgentConfig | Configuration for Google Antigravity SDK agents. |
opencode_v2 |
OpenCodeV2AgentConfig | Configuration for OpenCode V2 (v2.3+) agents. |
t3 |
T3AgentConfig | An agent that runs as a thread in a T3 Code environment. |
claude_code |
ClaudeCodeAgentConfig | Configuration for Claude Code agents. |
codex |
Codex Agent Configuration | Configuration for Codex app-server agent. |
acp (provider: custom) |
ACPAgentConfig | Configuration for a custom ACP agent with explicit command. |
acp (provider: registry) |
RegistryACPAgentConfig | Configuration for an ACP agent resolved from the ACP registry. |
acp (provider: remote) |
RemoteACPAgentConfig | Configuration for a remote ACP agent (experimental). |
So a Claude Code agent, a Codex agent and a native PydanticAI agent can be run, streamed, steered, delegated to, combined into teams and served over any protocol the same way. See Node Types for their configuration.
Running an Agent¶
from agentpool import AgentPool
async def main():
async with AgentPool("agents.yml") as pool:
agent = pool.get_agent("assistant")
# Run and get the final message
message = await agent.run("What is 2+2?")
print(message.content)
# Stream events (text deltas, tool calls, ...)
async for event in agent.run_stream("Count to 10"):
print(event)
# Run a turn and inspect how it ended
turn = await agent.run_turn("Summarize the README")
print(turn.outcome, turn.usage)
A native agent can also be created directly:
from agentpool import Agent
async def main():
async with Agent(model="openai:gpt-5-mini", system_prompt="Be brief.") as agent:
message = await agent.run("Hello!")
Runs belong to a session: pass session= to run in a specific conversation;
otherwise the agent's default session is used.
Structured Output¶
Native agents return typed results when given an output_type:
from pydantic import BaseModel
from agentpool import Agent
class AnalysisResult(BaseModel):
sentiment: float
topics: list[str]
async def main():
async with Agent(model="openai:gpt-5-mini", output_type=AnalysisResult) as agent:
message = await agent.run("Analyze: 'I love this product!'")
result: AnalysisResult = message.content
In YAML, output_type either names a shared response definition
or defines the response inline:
agents:
analyzer:
model: openai:gpt-5-mini
output_type: AnalysisResult # shared definition from `responses`
validator:
model: openai:gpt-5-mini
output_type: # inline definition
response_schema:
type: inline
fields:
is_valid:
type: bool
description: Whether the input is valid
issues:
type: list[str]
description: List of validation issues
output_retries: 2
responses:
AnalysisResult:
response_schema:
type: inline
description: Text analysis result
fields:
sentiment:
type: float
description: Sentiment score between -1 and 1
topics:
type: list[str]
description: Main topics discussed
Runtime Control¶
| Method | Purpose |
|---|---|
set_model(model) / get_available_models() |
Switch the model, list the models the agent can use |
get_modes() / set_mode(mode, category_id=...) |
Modes and config options (permission mode, reasoning effort, ...) |
steer(text) / queue_prompt(prompt) / interrupt() |
Talk to or stop a running turn |
compact() / fork_session() / start_new_session() |
Manage the conversation |
get_stats() / get_message_history() |
Usage statistics and stored history |
to_tool() |
Use the agent as a tool of another agent |
run_in_background(prompt, interval=..., max_count=...) |
Run repeatedly in the background |
Signals¶
Agents emit signals that can be connected to: