Coco

Coco Framework documentation

Build stateful, tool-calling agents in Python, with every model call and tool call passing through middleware where Coco's check attaches.

Build stateful, tool-calling agents in Python, with every model call and tool call passing through middleware where Coco's check attaches.

New to the framework? Start with the Quickstart.


How it works

create_agent compiles a state graph which calls the model, runs each tool call the model proposes through the wrap_tool_call middleware, and loops until the model answers. Every step can be checkpointed, paused with interrupt(), and resumed.

CocoGuard from the Coco SDK is one such middleware, and the framework carries no Coco enforcement code. Architecture says what the guard does with each call.

ImportHolds
cococreate_agent, init_chat_model, the middleware, and structured output
coco_graphStateGraph, interrupt(), Command, Send, streaming, and the checkpointers
coco_coreMessages, tools, runnables, prompts, and CocoTracer
coco_openai, coco_anthropicThe OpenAI and Anthropic chat models

pip install "coco-framework[all]" installs all of them. See Install.

Get started

  • Quickstart: Install the framework, run an agent with two tools, and add Coco's check.
  • Install: Choose extras, see every package and its import, and set model keys.

Build agents

  • Models: Switch between OpenAI and Anthropic, and configure each provider.
  • Conversations: Keep a conversation in memory, in SQLite, or in PostgreSQL.
  • Streaming: Stream node updates and model tokens.
  • Structured output: Return a validated Pydantic object.
  • Human in the loop: Pause a tool call until a person decides, and resume.
  • Middleware: See the order hooks run in, and write your own.
  • Built-in middleware: Add call limits, retries, fallbacks, PII redaction, and context management.
  • Custom graphs: Build your own workflow with StateGraph.
  • Tracing: Inspect runs in memory with CocoTracer, with nothing sent over the network.

Understand the framework

  • Architecture: The layers, the agent loop, state channels, checkpointing, tracing, and where Coco attaches.

Look something up

On this page