Learn Pi Agent

Learn Pi Agent

Real agent harness engineering. pi already turns the loop; you just hang mechanisms on it.

The core pattern

pi runs the same loop inside: call the model, run tools, feed results back. Your job is to hang mechanisms on that loop — tools, permission, events, knowledge, sessions, delegation, integration.

s01_agent_session/code.ts
const { session } = await createAgentSession({ sessionManager: SessionManager.inMemory() })

// 观察循环的每一次呼吸
session.subscribe((event) => {
  if (event.type === "message_update") process.stdout.write(event.assistantMessageEvent.delta)
})

// 一次 prompt = 一整个 agent loop
await session.prompt("看看当前目录,告诉我这是什么项目")

Learning path

12 progressive chapters, from a single minimal session to many mechanisms in one AgentSession

Mechanism layers

Four orthogonal concerns combine into a complete harness