Skip to content

Architecture ​

Poo is a modular Go agent harness designed as a library first. The core package owns the agent loop, tool registry, hook points, event stream, and session lifecycle. Everything else—tools, executors, providers, persistence stores, and the wire server—is an opt-in package wired at compile time. What a binary does not link cannot be reached at runtime.

Package layout ​

Packages are grouped by subsystem:

Core and contracts ​

PackageRole
pooCore agent loop FSM, tool registry, hooks, event stream, and session lifecycle
poo/promptSystem prompt vocabulary: named sections, variants, and template environment
poo/decideDecision-model contract: questions, answers, Decider, and recording wrapper
poo/execExecutor contract (Executor, Command, Process), registry, and env scrubbing
poo/protectProtected-path matcher shared by tools and permission policy
poo/pootestExported test helpers: scripted transport, in-memory sink, stub decider, scripted compactor

Tools and execution ​

PackageRole
poo/tool/*Opt-in tools: read, edit, write, grep, bash, cliregistry, callmcp, codemode, fetch, finish
poo/exec/bwrapLinux bubblewrap sandboxing executor
poo/codemode/*Opt-in codemode engines (quickjs, starlark)
poo/profile/*Named tool profiles (code, search, etc.) with default prompt and permission posture

Providers, permissions, and persistence ​

PackageRole
poo/provider/*Provider seam, model catalog (provider/catalog), and wire transports (OpenAI, Anthropic, etc.)
poo/permPermission engine: tool call policy, doom-loop detection, and asker chain
poo/perm/decidePermission asker backed by a decision model
poo/sessionSession persistence seam: store, versioned codec, history projection, and locking
poo/session/sqliteOpt-in SQLite session store

Capabilities and integrations ​

PackageRole
poo/cliCLI registry catalog and manifest loader
poo/feedFeed manifest loader, environment builder, and stdout record runner
poo/mcpMCP client: server lifecycle, tool dispatch, resource feeds, and relaunch loop
poo/mcp/manifestmcp.json manifest loader, launch templates, and resource feed declarations
poo/skillSkill directory discovery and SKILL.md frontmatter loader

Server, wire, and CLI ​

PackageRole
poo/wire/protocolPublic JSON-RPC 2.0 wire contract: method names, error codes, and request/result DTOs
poo/wireJSON-RPC 2.0 server over stdio
poo/wire/conformanceBlack-box protocol conformance suite and exported fake provider endpoint
poo/serverwire.Factory implementation bridging config and wire
poo/configOpt-in settings loading, schema validation, and runtime assembly
poo/cmd/pooReference headless CLI and poo serve binary

Stdlib-only core rule ​

The core package (poo) depends only on the Go standard library plus poo/prompt, poo/decide, and poo/scopeschema—each of which imports only the standard library. Several contract packages are also strictly standard-library-only so clients and extensions can depend on them without pulling in the rest of the module:

  • poo/wire/protocol
  • poo/prompt and poo/prompt/agentsmd
  • poo/decide
  • poo/exec
  • poo/protect
  • poo/caps
  • poo/scopeschema
  • poo/mcp/wire

internal/depcheck enforces these boundaries during go test. It inspects each checked package's non-test dependency closure via go list -e -deps -json. The test suite fails if any package imports an unapproved internal or third-party dependency. For example, only poo/mcp may import the MCP Go SDK. A binary that omits an MCP launcher never links that SDK.

See Build Your Own Binary for how custom binaries enforce their own dependency exclusions.

Session FSM ​

A session moves through a closed set of explicit states (poo.State). Consumers add behavior through hooks rather than introducing new states.

StateMeaning
idleThe session has no active run.
requestingThe run is requesting a response from the provider.
streamingThe provider's response stream is arriving.
executingThe run is executing tool calls requested by the model.
compactingThe run is compacting the conversation view before the next request.
waitingThe run is open while waiting on background jobs it started.
settlingThe run is finalizing and recording its settle outcome.
settledThe run has completed; a new prompt transitions back to requesting.

All state changes pass through a single transition function checked against the legal transition table (poo.IsLegal):

FromAllowed next states
idlerequesting
requestingstreaming, executing, compacting, requesting, waiting, settling
streamingexecuting, requesting, compacting, waiting, settling
executingexecuting, requesting, compacting, waiting, settling
compactingrequesting, waiting, settling
waitingrequesting, compacting, settling
settlingsettled
settledrequesting

Once a run enters settling or settled, background work from the ending run cannot move it backwards; only a subsequent run moves settled back to requesting.

Hook points ​

Hooks extend the session lifecycle without altering the FSM. Every hook receives a poo.HookContext carrying the session ID, run ID, turn number, read-only HistoryView, ContextBudget, and optional Decider. Hooks may append to history through their return decisions, never mutate prior messages in place.

Option / InterfaceWhen it runsDecisions / Effect
WithSessionStart (SessionStartHook)Once when the session is built, before the first runAppend messages, edit system prompt sections (StartDecision)
WithBeforeRun (BeforeRunHook)At the start of every run, before the first provider requestAppend messages, edit system prompt sections (StartDecision)
WithPolicy (PolicyHook)Before all other BeforeTool hooks; reserved for the permission engineAllow() or Deny(detail) only; exempt from hook deadline
WithBeforeTool (BeforeToolHook)After argument preparation and policy check, before tool executionAllow(), Deny(detail), or ShortCircuit(ToolResult)
WithAfterTool (AfterToolHook)After a tool call finishes, before the model sees the resultKeep(), Annotate(text), Replace(ToolResult), or Redact(ToolResult)
WithAfterTurn (AfterTurnHook)At the end of every turn, including interrupted turnsAppendMessages(...) or StopTurn(detail)
WithBeforeSettle (BeforeSettleHook)When the model stops on its ownAccept(), Continue(Message), or StopSettle(detail)
WithStopCondition (StopCondition)At every turn end after the tool batch finishesEnds the run when matched
WithObserver (Observer)On every session event, in orderRead-only observation; never settles a run
WithSessionAttach (AttachFunc)Once during live session construction (including resume), before feeds or runsAttach session-owned subsystems (such as MCP servers) and return a close function

Hooks that are safe to re-run after a crash mid-hook on durable sessions may implement poo.IdempotentHook. Hooks that do not implement it are never re-executed on recovery.

Provider-neutral message model ​

The core maintains a single provider-neutral message representation for all supported wire APIs. It carries text, tool calls, tool results, reasoning or thinking blocks, opaque provider blocks, and image attachments. Transports translate this model to and from Chat Completions, OpenAI Responses, and Anthropic Messages without leaking provider-specific types into the core.

For the exact round-trip mapping across all three APIs, see Wire API Mapping.

Released under the Apache-2.0 License. Machine-readable index: llms.txt · llms-full.txt