agentpool
AGENTS.md191 starsChanged 9 months agoMITView on GitHub
AgentPool is a unified agent orchestration framework that enables YAML-based configuration of heterogeneous AI agents. It bridges multiple protocols (ACP, AG-UI, OpenCode, MCP) and supports native PydanticAI agents, Claude Code agents, Goose, and other external agents. Core Philosophy: Define once in YAML, expose through multiple protocols, enable seamless inter-agent collaboration. The codebase is organized into focused packages under src/:
Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about checking a change actually works.
Of the AGENTS.md files we read, the 11,773 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository5 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- .github/copilot-instructions.mdCopilot instructions
- sync-acp-specSkill
- sync-skills-specSkill
- Example SkillSkill
The file
Show its rules and text
We split this AGENTS.md into the rules it gives an agent
19 rules. About 0 are common, 6 are distinctive, and 13 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈6
Distinctive · estimate
This author's own choices. Worth a look.
13
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 147
All processing units (Agents, Teams) inherit from MessageNode[TInputType, TOutput].
- Distinctive: line 252
Follow PEP 8 via Ruff
- Very specific: line 255
Use from __future__ import annotations for forward references
- Distinctive: line 278
When adding new tools:
- Very specific: line 279
Create implementation in agentpool/tool_impls/<tool_name>/
- Very specific: line 282
Add tests in tests/tool_impls/
- Very specific: line 288
Add to AnyAgentConfig union in manifest.py
- Very specific: line 289
Update manifest loading in pool.py
- Very specific: line 295
Use AggregatingServer if wrapping multiple agents
- Very specific: line 296
Add CLI command in agentpool_cli/
- Distinctive: line 321
Check storage database for interaction history
- Very specific: line 322
Use TestModel for isolated testing
- Very specific: line 323
Add --log-cli-level=DEBUG to pytest
- Very specific: line 342
Use ProcessManager from anyenv for external process management.
- Very specific: line 345
Use UPath (universal_pathlib) not Path - supports remote filesystems (s3://, gs://, etc.)
- Very specific: line 348
Prefer string shorthand in YAML: model: "openai:gpt-4o" Fallback models: type: fallback, models: [primary, backup]
- Distinctive: line 471
ALWAYS use uv for all python related tasks.
- Distinctive: line 472
DO NOT USE getattr and hasattr in very rare exceptions.
- Distinctive: line 474
never resort to shortcuts, never leave out stuff with TODOs unless explicitely asked.
≈ “Common” is an estimate: at least 1 in 5 of the 16,595 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Project Overview
AgentPool is a unified agent orchestration framework that enables YAML-based configuration of heterogeneous AI agents. It bridges multiple protocols (ACP, AG-UI, OpenCode, MCP) and supports native PydanticAI agents, Claude Code agents, Goose, and other external agents.
Core Philosophy: Define once in YAML, expose through multiple protocols, enable seamless inter-agent collaboration.
Development Commands
Installation & Setup
# Install with uv (recommended)
uv sync --all-extras
# Install specific extras
uv sync --extra coding --extra serverTesting
# Run all tests (excludes slow and acp_snapshot by default)
uv run pytest
# Run with coverage
uv run pytest --cov-report=xml --cov=src/agentpool/ --cov-report=term-missing
# Run specific test markers
uv run pytest -m unit # Unit tests only
uv run pytest -m integration # Integration tests only
uv run pytest -m slow # Include slow tests
uv run pytest -m acp_snapshot # ACP snapshot tests
# Run single test file
uv run pytest tests/test_specific.py
# Run with verbose output
uv run pytest -vv
# Run tests in parallel
uv run pytest -n autoCode Quality
# Main command: runs all
duty lint
# Lint with ruff
uv run ruff check src/
# Format check
uv run ruff format --check
# Format code
uv run ruff format src/
# Type checking with mypy
uv run --no-group docs mypy src/Running AgentPool
# Run agent directly
agentpool run <agent_name> "prompt text"
# Start ACP server (for IDEs like Zed)
agentpool serve-acp config.yml
# Start OpenCode server
agentpool serve-opencode config.yml
# Start MCP server
agentpool serve-mcp config.yml
# Start AG-UI server
agentpool serve-agui config.yml
# Start OpenAI-compatible API server
agentpool serve-api config.yml
# Watch for triggers
agentpool watch --config agents.yml
# View analytics
agentpool history stats --group-by modelCode Architecture
Module Structure
The codebase is organized into focused packages under src/:
agentpool/- Core agent frameworkagents/- Agent implementations (native, ACP, AG-UI, Claude Code)delegation/- AgentPool orchestration, Team coordination, message routingmessaging/- Message processing, MessageNode abstraction, compactiontools/- Tool framework and implementationstool_impls/- Concrete tool implementations (bash, read, grep, etc.)models/- Pydantic data models and configuration schemasprompts/- Prompt management and templatingstorage/- Interaction tracking and analyticsmcp_server/- MCP server integrationrunning/- Agent execution runtimesessions/- Session managementhooks/- Event hooks systemobservability/- Logging and telemetry (Logfire)
agentpool_config/- Configuration models (separated for clean imports)- YAML schema definitions for agents, teams, tools, MCP servers
agentpool_server/- Protocol serversacp_server/- Agent Communication Protocol serveropencode_server/- OpenCode TUI/Desktop serveragui_server/- AG-UI protocol serveropenai_api_server/- OpenAI-compatible API servermcp_server/- Model Context Protocol server
agentpool_toolsets/- Reusable toolset implementationsbuiltin/- Built-in toolsets (code, debug, subagent, file_edit, workers)mcp_discovery/- MCP server discovery with semantic search- Specialized toolsets (composio, search, streaming, etc.)
agentpool_storage/- Storage providerssql_provider/- SQLAlchemy-based storagezed_provider/- Zed IDE storage integrationclaude_provider/- Claude storage integrationopencode_provider/- OpenCode storage integration
agentpool_cli/- Command-line interfaceagentpool_commands/- Command implementationsagentpool_prompts/- Prompt templatesacp/- Agent Communication Protocol implementationclient/- ACP client implementationsagent/- Agent-side protocol implementationschema/- Protocol schemas and typesbridge/- ACP bridge for connecting agentstransports/- Transport layer (stdio, websocket)
Key Architectural Patterns
MessageNode Abstraction
All processing units (Agents, Teams) inherit from MessageNode[TInputType, TOutput]. This provides:
- Unified interface for message processing via
process() - Connection management (forwarding outputs between nodes)
- Hook system for intercepting messages
- Type-safe input/output handling
# Both agents and teams are MessageNodes
agent: MessageNode[ChatMessage, ChatMessage]
team: MessageNode[ChatMessage, TeamRun]
# Nodes can be connected
agent.add_connection(other_agent) # Forward messages to other_agentAgentPool as Registry
AgentPool is a BaseRegistry[NodeName, MessageNode] that:
- Manages lifecycle of all agents and teams
- Provides dependency injection (shared_deps)
- Handles connection setup from YAML config
- Coordinates resource cleanup
Team Patterns
Teams combine multiple agents:
- Sequential (chain):
agent1 | agent2 | agent3- Output flows through pipeline - Parallel:
agent1 & agent2 & agent3- All process same input concurrently - YAML configuration: Define teams in manifest with mode and members
Tool System
Tools follow PydanticAI's tool pattern with AgentPool extensions:
- Tools are typed functions with Pydantic schemas
- Can access
AgentContextfor agent-specific state - Support
subagenttool for delegation - Built-in toolsets provide common functionality (code editing, bash, grep)
Protocol Bridging
AgentPool acts as a protocol adapter:
- Agent defined once in YAML (with type: native/acp/agui/claude)
- Pool loads and manages agent lifecycle
- Server exposes agent through chosen protocol (ACP/AG-UI/OpenCode/OpenAI API)
- Client interacts via standardized protocol
Agent Types
Native Agents (type: native)
- PydanticAI-based agents with full framework features
- Direct model integration (OpenAI, Anthropic, Google, Mistral, etc.)
- Tool support, structured output, streaming
- Most flexible and feature-rich
ACP Agents (type: acp)
- External agents implementing Agent Communication Protocol
- Examples: Goose, Codex, custom ACP servers
- Communicate via stdio or websocket
Claude Code Agents (type: claude)
- Direct integration with Claude Code CLI
- Specialized for code-related tasks
- Access to Claude Code's tool ecosystem
AG-UI Agents (type: agui)
- Remote agents implementing AG-UI protocol
- HTTP-based communication
- Useful for distributed agent architectures
File Agents (type: file)
- Agent behavior defined by file content/prompts
- Lightweight for simple use cases
Storage and Observability
Storage Providers: Track all agent interactions
- SQL-based with SQLModel/SQLAlchemy
- Per-agent or shared database
- Analytics via CLI:
agentpool history stats
Observability: Logfire integration
- Structured logging with context
- Trace agent execution
- Performance monitoring
- Disabled in tests via env vars
Configuration System
YAML-First Design:
AgentsManifestis the root config model- Supports inheritance via
INHERITfield - Inline schema definitions with Schemez
- Environment variable substitution
- Jinja2 templating in prompts
Key Config Sections:
agents: Agent definitionsteams: Multi-agent teamsresponses: Structured output schemasmcp_servers: MCP server configurationsstorage: Interaction tracking configobservability: Logging/telemetry configworkers: Background worker definitionsjobs: Scheduled tasks
Development Guidelines
Code Style
- Python 3.13+ required (use modern syntax: match/case, walrus operator)
- Follow PEP 8 via Ruff
- Google-style docstrings (no types in Args section)
- Type hints required (checked with mypy --strict)
- Use
from __future__ import annotationsfor forward references
Testing
- Tests use pytest (not in classes)
- Fixtures in
tests/conftest.py - TestModel from pydantic-ai for agent testing
- Disable observability in tests (see conftest.py)
- Markers:
@pytest.mark.unit,@pytest.mark.integration,@pytest.mark.slow
Import Patterns
# Avoid circular imports - use TYPE_CHECKING
from __future__ import annotations
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from agentpool.delegation import AgentPool
# Config models are in agentpool_config to avoid circular deps
from agentpool_config.teams import TeamConfigTool Implementation
When adding new tools:
- Create implementation in
agentpool/tool_impls/<tool_name>/ - Define config model in
agentpool_config/if complex - Register in appropriate toolset (
agentpool_toolsets/) - Add tests in
tests/tool_impls/
Adding Agent Types
New agent types require:
- Config model in
agentpool/models/(inherit from base, settypediscriminator) - Implementation in
agentpool/agents/ - Add to
AnyAgentConfigunion inmanifest.py - Update manifest loading in
pool.py
Server Implementation
New protocol servers:
- Inherit from
BaseServerinagentpool_server/base.py - Implement protocol-specific handlers
- Use
AggregatingServerif wrapping multiple agents - Add CLI command in
agentpool_cli/
Common Patterns
Creating an AgentPool
async with AgentPool("config.yml") as pool:
agent = pool.get_agent("agent_name")
result = await agent.run("prompt")Running Tests on Modified Code
# Find relevant tests
pytest tests/path/to/test_file.py -k "test_pattern"
# Quick sanity check (unit tests only)
pytest -m unit --no-cov
# Full validation
pytest && mypy src/ && ruff check src/Debugging Agent Issues
- Enable verbose logging (set
OBSERVABILITY_ENABLED=true) - Check storage database for interaction history
- Use
TestModelfor isolated testing - Add
--log-cli-level=DEBUGto pytest
Working with YAML Configs
- Examples in
site/examples/*/config.yml - Schema reference auto-generated from Pydantic models
- Validate with:
python -m agentpool_config.manifest config.yml
Special Considerations
Async Context Managers
AgentPool and Agents use async context managers - always use async with:
async with AgentPool(manifest) as pool:
async with pool.get_agent("name") as agent:
result = await agent.run("prompt")MCP Server Lifecycle
MCP servers are spawned as subprocesses - pool cleanup handles termination.
Use ProcessManager from anyenv for external process management.
UPath for File Operations
Use UPath (universal_pathlib) not Path - supports remote filesystems (s3://, gs://, etc.)
Model Configuration
Prefer string shorthand in YAML: model: "openai:gpt-4o"
Fallback models: type: fallback, models: [primary, backup]
Entry Points
The project uses entry points for extensibility:
agentpool_toolsets- Register custom toolsetsfsspec.specs- Filesystem implementations (ACP)universal_pathlib.implementations- Path implementations
Key Files to Understand
src/agentpool/delegation/pool.py- AgentPool orchestrationsrc/agentpool/agents/agent.py- Native agent implementationsrc/agentpool/messaging/messagenode.py- Base abstractionsrc/agentpool/models/manifest.py- Configuration schemasrc/agentpool/tools/tool.py- Tool frameworksrc/agentpool_server/acp_server/acp_agent.py- ACP server agent wrappersrc/acp/client/protocol.py- ACP client interfacesrc/acp/agent/protocol.py- ACP agent interface
Documentation
- Main docs: phil65.github.io/agentpool
- Built with MkNodes (see
mkdocs.yml) - Auto-generated from docstrings and examples. Utilities in agentpool/docs/
Complete Usage Examples
Direct Agent Instantiation
Native Agent
from agentpool.agents import Agent
def greet(name: str) -> str:
"""Greet someone."""
return f"Hello, {name}!"
async with Agent(
name="my_agent",
model="openai:gpt-4o-mini", # Required: model string or Model instance
system_prompt="You are a helpful assistant",
tools=[greet], # Callables or import paths like "mymodule:my_tool"
) as agent:
async for event in agent.run_stream("Greet Alice"):
...ACP Agent
from agentpool.agents.acp_agent import ACPAgent
async with ACPAgent(
command="goose", # Required: executable name
args=["acp"], # Required: command arguments
name="goose_agent",
cwd="/path/to/project",
) as agent:
async for event in agent.run_stream("Write code"):
...Claude Code Agent
from agentpool.agents.claude_code_agent import ClaudeCodeAgent
async with ClaudeCodeAgent(
name="claude_coder",
model="claude-sonnet-4-20250514", # Optional: defaults to latest
cwd="/path/to/project", # Optional: defaults to current directory
) as agent:
async for event in agent.run_stream("Refactor this code"):
...Agent from Config with Streaming
Config (config.yml)
agents:
coder:
type: native
model: "openai:gpt-4o-mini"
system_prompt: "You are an expert Python developer"
tools:
- name: bash
enabled: true
- name: read
enabled: truePython Code
from agentpool.delegation import AgentPool
from agentpool.agents.events import (
PartDeltaEvent,
ToolCallStartEvent,
ToolCallCompleteEvent,
StreamCompleteEvent,
)
async with AgentPool("config.yml") as pool:
agent = pool.get_agent("coder")
# Stream events (run_stream returns AsyncIterator, not a context manager)
async for event in agent.run_stream("Read setup.py and list dependencies"):
match event:
case PartDeltaEvent(delta=text):
# Stream text chunks as they arrive
print(text, end="", flush=True)
case ToolCallStartEvent(tool_name=name):
print(f"\n[Tool starting: {name}]")
case ToolCallCompleteEvent(tool_name=name, tool_result=result):
print(f"\n[Tool {name} completed: {result}]")
case StreamCompleteEvent(message=msg):
# Final complete message with full content
print(f"\n\nComplete response: {msg.content}")Rules:
- ALWAYS use uv for all python related tasks.
- DO NOT USE getattr and hasattr in very rare exceptions. Always provide full type safety.
- Maximum type safety.
- never resort to shortcuts, never leave out stuff with TODOs unless explicitely asked.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

