Files
scientific-agent-skills/skills/pi-agent/references/json.md
T
Timothy Kassis ef1b2d8026 Update pi-agent skill to latest Pi docs
Refresh every reference against https://pi.dev/docs/latest and the four
ecosystem package pages, cross-checked with the published npm READMEs.

New reference pages (docs added them; the site nav does not surface them):
- environment-variables.md: PI_* process config, the PI_CODING_AGENT child
  marker, and the session variables injected into the bash tool. The old
  env-var list lived in usage.md, which no longer has that section.
- llama-cpp.md: llama.cpp router setup, /login llama.cpp, /llama.

Notable upstream drift now reflected:
- SDK: ModelRuntime.create() replaces AuthStorage + ModelRegistry;
  createAgentSessionServices/FromServices runtime factory; resolveCliModel
  and resolveModelScopeWithDiagnostics.
- Providers: full 30+ API-key table with env vars and auth.json keys;
  xAI/OpenRouter/Radius subscription logins; provider-scoped env blocks in
  credentials; models-store.json; Bedrock proxy variables.
- New thinking level "max" across settings, CLI, RPC, thinkingLevelMap, and
  the themes' thinkingMax token.
- New commands: /trust, /import, /llama; pi update --all/--models/--self;
  pi config; .pi/SYSTEM.md and APPEND_SYSTEM.md; trust.json.
- RPC: get_entries (with since cursor), get_tree,
  get_available_thinking_levels, agent_settled, bash_execution_update,
  summarization_retry_*, and the extension UI sub-protocol.
- Extensions: expanded from a summary to the real API surface, including
  session-replacement semantics and footguns, withFileMutationQueue,
  terminate, prepareArguments, and dynamic tool loading.
- Session format: retainedTail checkpoints and buildContextEntries().
- Packages: pi-web-access gained source_check and nine search providers and
  dropped code_search, which the old reference still documented;
  pi-mcp-adapter gained six config locations, lazy-keep-alive, the output
  guard, and MCP_STATUS_EVENT; pi-subagents gained the watchdog, profiles,
  modelScope, per-agent memory, the fleet inspector, and RPC v1.

Also fixes escape sequences that had been corrupted in earlier versions:
the Git Bash path in windows.md, the shellCommandPrefix JSON in
shell-aliases.md, and the CSI-u sequences in tmux.md and terminal-setup.md.

Bumps metadata.version to 1.2.
2026-07-26 15:50:24 -07:00

2.0 KiB

JSON Event Stream Mode

Source: https://pi.dev/docs/latest/json

Use JSON mode for one-shot prompts that output all session events as JSON lines to stdout.

pi --mode json "Your prompt"

Event Types

AgentSessionEvent is AgentEvent plus session-level events:

  • queue_update — { steering: readonly string[], followUp: readonly string[] }, emitted whenever either queue changes
  • compaction_start — { reason: "manual" | "threshold" | "overflow" }
  • compaction_end — { reason, result: CompactionResult | undefined, aborted, willRetry, errorMessage? }
  • auto_retry_start — { attempt, maxAttempts, delayMs, errorMessage }
  • auto_retry_end — { success, attempt, finalError? }
  • summarization_retry_scheduled — { attempt, maxAttempts, delayMs, errorMessage }
  • summarization_retry_attempt_start — { source: "branchSummary" } or { source: "compaction", reason }
  • summarization_retry_finished

Base AgentEvent types:

  • agent_start, agent_end (messages)
  • turn_start, turn_end (message, toolResults)
  • message_start (message), message_update (message, assistantMessageEvent), message_end (message)
  • tool_execution_start (toolCallId, toolName, args), tool_execution_update (+ partialResult), tool_execution_end (result, isError)

Output Format

First line is the session header:

{"type":"session","version":3,"id":"uuid","timestamp":"...","cwd":"/path"}

Then events as they occur:

{"type":"agent_start"}
{"type":"turn_start"}
{"type":"message_start","message":{"role":"assistant","content":[]}}
{"type":"message_update","message":{},"assistantMessageEvent":{"type":"text_delta","delta":"Hello"}}
{"type":"message_end","message":{}}
{"type":"turn_end","message":{},"toolResults":[]}
{"type":"agent_end","messages":[]}

Example

pi --mode json "List files" 2>/dev/null | jq -c 'select(.type == "message_end")'

For bidirectional control, use RPC instead of JSON mode.