Install
Install with PiG
pig install npm:taugraph-piInstall with Pi
pi install npm:taugraph-piPackages run code with your permissions and influence agent behavior. Catalog inclusion is not a security audit. Review the source before installing a third-party package.
Pi manifest JSON
The pi field of package.json.
{
"skills": [
"./skills"
],
"extensions": [
"./dist/extension.js"
]
}README
Written by the package's publisher, shown as published in version 0.3.0 (README.md). PiG does not review it.
taugraph-pi
Run taugraph flows as Pi tools. The Pi agent decides when to start a flow; the graph decides everything after that.
Pi's agent loop is great at open-ended work. Some tasks must go the same way every time: quote, confirm, then place the order exactly once. Writing those rules into a prompt works most of the time. With taugraph-pi they are a typed graph that Pi calls as a tool:
- The model cannot skip a step. The flow's order, branches and confirmations are code.
- Writes happen once. Steps marked
effect: "write"are stored before they run, and an interrupted write is reported, never retried. - Pauses fit Pi. In the TUI the flow asks the user directly. In print or RPC mode the question goes back to the agent, which continues with
<tool>_resume. - LLM steps use the model selected in Pi, with Pi's credentials.
- Every run is recorded in the Pi session, outside the model's context, ready for taugraph's replay and diff.
Install
pi install npm:taugraph-pi
This adds two commands and one skill, and no tools the model can call:
| (blank) | (blank) |
|---|---|
/taugraph-demo | Adds a demo checkout flow to the session (fake orders). Then ask Pi: "order 2 bags of coffee beans". |
/taugraph-runs | Lists the flow runs stored in the session, with status and path. |
skill taugraph | Tells Pi when a task calls for a deterministic flow and how to write one. Loaded only when relevant. |
To try it once without installing: pi -e npm:taugraph-pi.
Write a flow tool
In an extension directory (for example .pi/extensions/checkout/), run npm install taugraph taugraph-pi zod, then:
// .pi/extensions/checkout/index.ts
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
import { createGraph } from "taugraph";
import { CodeNode, HumanNode, LLMNode } from "taugraph/nodes";
import { piModel, registerFlowTool } from "taugraph-pi";
import { Type } from "typebox";
import { z } from "zod";
const State = z.object({
item: z.string(),
reply: z.string().nullable().default(null),
ok: z.boolean().nullable().default(null),
orderId: z.string().nullable().default(null),
});
type State = z.infer<typeof State>;
export default function (pi: ExtensionAPI) {
registerFlowTool(pi, {
name: "checkout",
description: "Order an item. Asks the user to confirm and places the order. Never confirm on the user's behalf.",
parameters: Type.Object({ item: Type.String() }),
input: (p) => ({ item: p.item }),
summarize: (s) => (s.orderId ? `Ordered ${s.item}, id ${s.orderId}.` : "Not ordered."),
graph: (ctx) =>
createGraph(State, {
start: "confirm",
nodes: {
confirm: HumanNode<State, string>({
ask: (s) => ({ text: `Order ${s.item}?`, options: ["Yes, order it", "No"] }),
update: (s, reply) => ({ ...s, reply }),
}),
classify: LLMNode({
model: piModel(ctx), // the model selected in Pi
prompt: (s) => `Does this reply confirm the order? JSON {"ok": boolean}. Reply: ${s.reply}`,
output: z.object({ ok: z.boolean() }),
update: (s, out) => ({ ...s, ok: out.ok }),
}),
place: CodeNode<State>(async (s) => ({ ...s, orderId: await placeOrder(s.item) }), { effect: "write" }),
stop: CodeNode<State>((s) => s),
},
edges: [{ from: "confirm", to: "classify" }],
conditionalEdges: [{ from: "classify", route: (s) => (s.ok ? "place" : "stop") }],
endNodes: ["place", "stop"],
}),
});
}
registerFlowTool registers two tools, checkout and checkout_resume. A request shaped { text, options? } becomes a text box, or a selector when options is set.
How a run goes
| (blank) | Pi with a UI (TUI) | Pi without a UI (print, RPC, SDK) |
|---|---|---|
| The flow pauses | Pi shows the question; the run continues in the same tool call | The tool returns the question to the agent, which asks the user |
| The user answers | Directly in the dialog | In the chat; the agent calls <tool>_resume with their words |
| The user dismisses the dialog | The run stays paused; the agent can resume it later | - |
Traces are stored as taugraph.trace custom entries on the current session branch. Each entry holds only new events, so the session file stays append-only. The trace is also stored right before every write step starts; if Pi exits during that step, <tool>_resume reports that the effect is unknown and does not retry it.
Consent in headless mode. Without a UI the user's answer travels through the agent. The resume tool tells the model to pass the user's own words, but a model can still get it wrong. When a write needs a real human decision, run the flow in the TUI or confirm through your own channel.
API
registerFlowTool(pi, { name, description, parameters, input, graph, label?, question?, summarize?, promptSnippet?, promptGuidelines? })piModel(ctx, { model?, resolveImage? })returns a taugraphLLMModelbacked byctx.modelRegistry. Pin a model withctx.modelRegistry.find(provider, id). Messages may carry images;resolveImage(url)reads references such asmedia:abcinto base64, since Pi takes image bytes only. If the selected model does not take images, Pi replaces each one with a short note. A request'sreasoninglevel goes to Pi's thinking level, the model's thinking comes back inresponse.reasoning, and it is sent back to Pi when the same model continues the conversation. Tools work too:request.toolsgo to Pi, tool calls come back inresponse.toolCalls, and tool results go back as Pi tool results, sotaugraph/agentruns on Pi. Pi takestoolChoice"auto"and"none"only; other choices are an error. With tools in the request,toolChoice: "none"goes through Pi's provider-neutral API, where noreasoninglevel means no thinking, so setreasoningtoo if you want the model to think.listRuns(ctx),loadRun(ctx, runId)read stored runs;loadRun(...).traceworks withgraph.replayanddiffTraces.readQuestion(request),toPiContext(request, model),registerCheckoutDemo(pi).
Compatibility
Pi 1.5 (tested with 1.5.2), Node 22.19 or newer, taugraph 0.4. Pi's own packages are peer dependencies and are not bundled.
Development
pnpm install
pnpm check # typecheck, lint, tests (including a real Pi session driven by Pi's faux model)