Agent Task Platform separates durable orchestration from Agent implementation. PostgreSQL owns execution state; processes can disappear and later recover eligible work without making an HTTP connection the unit of reliability.
The platform uses a one-way dependency direction:
interfaces -> orchestration -> framework -> infra -> domain
Read the arrow as “may depend on.” Inner layers must not import outer layers.
| Layer | Responsibility | Typical entry points |
|---|---|---|
domain |
Transport-independent models, enums, policies, and identifiers | AgentRun, AgentStage, AgentSpec, ToolSpec, SkillSpec |
infra |
PostgreSQL repositories, coordination, rate limiting, and outbound URL policy | infra/store/, infra/coordination.py |
framework |
Reusable Agent, Tool, Skill, stage, and model execution mechanisms | AgentRuntime, ToolGateway, SkillRuntime, ModelGateway |
orchestration |
Submission, scheduling, attempts, recovery, workers, and callbacks | RunService, RunManager, RunExecutor, RunWorker |
interfaces |
HTTP, CLI, settings, logging, and application composition | create_app(), route modules, CLI commands |
agent_hub/ and plugins/ contain public examples. Production extensions can live in a separate package that depends on the platform.
The architecture test guards important import boundaries. Run uv run pytest --noconftest -q tests/test_layering.py after moving modules.
interfaces/http/server.py:create_app() is the composition root. It:
- Loads and validates bootstrap settings.
- Connects to PostgreSQL.
- Loads database-backed Agent, Tool, and Skill registries, using YAML only to seed missing versions.
- Constructs coordination, Tool Gateway, Skill Runtime, Model Gateway, scheduler, Run manager, worker, callback service, and configuration watcher.
- Installs HTTP middleware, error handlers, and routes.
- On lifespan startup, registers MCP Tools, recovers incomplete work, compensates callbacks, and starts watchers when enabled.
Keep construction and cross-layer wiring here rather than hiding service location inside domain or framework code.
HTTP/CLI caller
-> RunManager.submit
-> RunService: idempotency, route/version resolution, snapshots, persistence
-> RunScheduler: global + route + caller + Agent admission
-> queue/lease ownership
-> RunExecutor: attempts, timeout, cancellation, error classification
-> AgentRuntime: select adapter and build AgentContext
-> durable stages
-> ToolGateway -> Python | HTTP | MCP | built-in Tool
-> SkillSession -> immutable instructions/resources/scripts
-> ModelGateway or Pi worker
-> persisted result/error/logs/model calls
-> optional signed callback delivery
In more detail:
POST /v1/runsvalidates the request andrunsAPI-key scope.RunServiceapplies idempotency on(caller, route_tag, request_id), resolves a concrete Agent version, snapshots assigned Skills, and persists the Run.RunSchedulerapplies global, route, caller, Agent, nesting-depth, and active-child limits.- The API process can start new work in-process. A standalone worker instead claims ready work with a time-bounded queue lease. In both paths,
RunExecutorowns attempts, timeout, cancellation, retry classification, and terminal transitions. AgentRuntimeselects the configured adapter and builds anAgentContextwith governed clients.- Tool calls pass through Tool Gateway. Durable stage state, Tool events, model calls, and logs are stored as execution proceeds.
- The result or structured error is persisted. Optional callbacks are delivered and tracked independently.
| Runtime type | Use case | Boundary |
|---|---|---|
echo |
Health and deterministic examples | In-process |
python |
Trusted custom workflow | In-process Python |
python_subprocess / python_isolated |
Python target with process separation | Local subprocess; not a complete sandbox |
http |
Independently deployed Agent | HTTP endpoint subject to outbound policy |
model_gateway |
One direct governed model completion | Python Model Gateway |
pi |
Multi-turn model-directed Tool/Skill loop | Task-scoped local Node process |
The runtime adapter changes how an Agent executes, not who owns the Run. Routing, retries, cancellation, stages, Tool policy, Skill snapshots, logs, and callbacks remain platform responsibilities.
For runtime.type: pi, Python owns the Run and starts one task-scoped local Node process containing Pi agent core. The child performs the model/tool loop, but every capability request crosses a bounded JSONL bridge back to Python. Platform Tools still pass through Tool Gateway, Skills remain Run-scoped snapshots, and the complete loop is wrapped in one durable pi-agent stage. See Pi Agent Runtime.
Persisted data includes Run state, queue ownership, attempts, durable stages, Skill snapshots, logs, model-call records, callback attempts, and registry versions. Recovery can requeue abandoned work and reuse completed durable stages whose identity still matches.
Persistence does not make arbitrary code replay-safe. In-process Python code must cooperate with cancellation, external side effects need idempotency protection, and an interrupted Pi loop restarts from the loop boundary rather than an individual model turn. See Durable Stages.
Bootstrap settings come from defaults, YAML, .env profiles, and process environment. Agent, Tool, and Skill definitions are database-backed after YAML seeding. An optional normalized database configuration layer can hot-reload selected runtime settings, but connection details and process-local settings remain bootstrap-owned.
See Configuration for precedence and reload boundaries.
- API keys and scopes protect HTTP control surfaces.
- Tool Gateway is the policy boundary for registered capabilities.
- Outbound URL policy and callback allowlists restrict network destinations.
- Skill artifacts are verified and snapshotted per Run.
- Python extensions and the Pi worker are trusted code, not security sandboxes.
- Model output and Skill reference content remain untrusted input.
Read the Security Model before adding a new execution or network boundary.
| If you change… | Also inspect… |
|---|---|
| Run fields or status transitions | repositories, migration, API schema, retry/recovery tests |
| Agent runtime behavior | adapter loading, cancellation, health checks, packaging |
| Tool execution | schemas, permissions, side-effect handling, audit logs |
| Skill artifacts | loader, snapshot hash, session activation, stage definition versions |
| Settings | typed settings, examples, database-managed allowlist, reload behavior |
| HTTP routes | scope dependency, error envelope, OpenAPI, docs |
For a file-oriented contributor workflow, continue with Development.