SDK reference
Resolve a recipe and construct its Pi session from your own code.
Construct a session
createAgentSession(options) is the only session constructor. Root sessions, default in-process child sessions, conformance tests and external hosts all call it, and it always takes one options object. Both it and resolveRecipe() are on the package root, so the whole construction flow is one import.
Hold the snapshot
Resolve once, then inspect the plan and construct every session, root and child, from that same graph. See Recipes for what resolution produces.
Options
Types for every option are exported from /session. Construction resolves the agent, resolves credentials fail-closed, materializes required MCP bindings fail-closed, loads skills, prompts and extensions, registers the subagent tool, creates the Pi session, and returns one idempotent dispose().
Every option after recipe and agentName replaces transport or a materialized resource, never the portable definition. modelOverride is checked against the agent's declared model.name and supplies the transport for it, so a host cannot quietly swap the model a recipe asked for.
The handle
| Member | What it is |
|---|---|
session | Pi prompt, steer, follow-up, abort, messages, events |
agent | The selected resolved definition |
agentRuns | The agent-run controller behind the agent tool |
dispose() | Child, session, instrumentation, and MCP cleanup |
Agent runs
Recipes defines AgentRunController in /agents as a portable contract and ships one lightweight in-process implementation. See Agents for what a child inherits.
An injected controller owns child selection and execution once the root session exists. dispose() calls its shutdown() exactly once, while close(id) ends a single run.
Inspection
Inspection reports effective model and prompt provenance, what each step of a from: chain declared, authored versus root and delegated tools, selected skills, visible subagents, MCP policy, expected credential variables, and the ordered extension and prompt closure. Binding files are host state and are excluded.
OpenTelemetry
otel takes tracer, meter, meta, and the runSpans and getParentContext seams for hosts that create their own turn spans. See Telemetry for the spans, attributes and metrics this produces.
Environment leases
In CLI mode, default MCP provisioning leases the supplied env object until the handle is disposed, then restores its prior state. Concurrent CLI sessions need separate environment objects. A host that provisions MCP itself passes mcpProvisioning: "host".
Conformance
Passing the suite means your host uses the same session-construction contract as Pi. Protocol behavior, persistence, tenancy and deployment remain host-specific and need their own tests.
Public exports
| Path | Provides |
|---|---|
. | resolveRecipe(), createAgentSession(), and their errors |
/recipe | The resolution graph and recipe types |
/session | Session-construction host bindings |
/agents | AgentRunController, run summaries, createAgentTool() |
/extensions | Extension context for an agent or recipe session |
/mcp | Policy, binding, and materialization contracts |
/interactions | Portable questions and approvals |
/inspect | inspectRecipe() |
/pi-extension | Pi TUI integration |
/test-utils | Host conformance cases |
Not included
No HTTP server or wire protocol, no task database or state machine, no scheduler or queue, no sandbox or tenant isolation, no deployment CLI, no provider-specific hosting integrations. Those layers compose above the session boundary.