Skip to content

Pi: agent type and PiAgent implementation for tasks, with full persisted execution events #3832

Done

Description

@integry

Register agent type pi and implement PiAgent.executeTask so implementation tasks and PR follow-ups run through Pi in JSON mode, with the complete trace persisted.

Acceptance:

  • pi is added to the shared agent type, createAgentFromConfig, default config paths (~/.pi/agent), agent constants, model definitions/aliases/label resolution, the PR template agent naming and the API types.
  • Invocation: pi -p --mode json --model <provider/id>[:<thinking>] --thinking <level> --session-dir <runtime sessions dir> --no-approve, with the prompt via stdin or an @file mounted read-only. Map ProPR reasoning levels to off|minimal|low|medium|high|xhigh|max.
  • Project trust: always pass --no-approve, so repository-provided .pi/ extensions, settings and prompts are never trusted. AGENTS.md/CLAUDE.md context files still load, which is desired.
  • Model IDs: use a ProPR-side id scheme (e.g. pi-<provider>/<model>, mapped to --model <provider>/<model>), configured per agent in supportedModels, with sensible defaults. Labels in PR titles show the underlying model.
  • Output parser for the JSON event stream (see the fixture in the notes):
    • session id from the session header;
    • summary from the last assistant message_end text;
    • success when agent_settled.aborted is false, the process exited 0 and the last assistant stopReason is not error/aborted;
    • token usage summed over all assistant message_end.message.usage records (input, output, cacheRead → cache_read_input_tokens, cacheWrite → cache_creation_input_tokens), since usage is per response, not cumulative;
    • cost from usage.cost.total when totalFromProvider (else ProPR pricing).
  • conversationLog: Claude-shaped events, persisted as LLM log details so get_task_logs shows them:
    • user message;
    • assistant text and thinking;
    • each toolCall → tool_use (name, arguments);
    • each tool_execution_end or toolResult message → tool_result with is_error from isError.
  • The activity watchdog and output-activity detection recognise Pi events, so long tool runs aren't treated as stalls.
  • Tests: parser and result tests built from the fixture (tool pairs including the failed bash call, token sums, session id, success); Docker args tests (flags, mounts, --no-approve, no root-owned paths).

Implementation

Follow OpenCodeAgent/VibeAgent structure: a docker args builder, an output parser module under packages/core/src/agents/impl/utils/, and the result processing that feeds recordLLMMetrics. Persist the fixture as test/fixtures/pi/pi-1.6.1-json-tool-task.jsonl.

Notes

Fixture: a real Pi 1.6.1 run via OpenRouter (mistralai/devstral-2512), trimmed to one example of each record type (paths sanitized):

{"type":"session","version":3,"id":"01a21d71-9198-74eb-978e-565639986934","timestamp":"2026-11-27T14:38:31.832Z","cwd":"/home/node/workspace"}
{"type":"agent_start"}
{"type":"turn_start"}
{"type":"message_end","message":{"role":"user","content":[{"type":"text","text":"Read math.js, add subtract(a, b) next to add and export it, add a node:test test in math.test.js, then run node --test. Also run 'cat missing.txt' once."}],"timestamp":1795790311889}}
{"type":"message_update","usage":{"input":0,"output":0,"cacheRead":0,"cacheWrite":0,"totalTokens":0,"cost":{"input":0,"output":0,"cacheRead":0,"cacheWrite":0,"total":0}},"assistantMessageEvent":{"type":"toolcall_start","contentIndex":0,"id":"HEFIeQfFW","toolName":"read"}}
{"type":"message_update","usage":{"input":0,"output":0,"cacheRead":0,"cacheWrite":0,"totalTokens":0,"cost":{"input":0,"output":0,"cacheRead":0,"cacheWrite":0,"total":0}},"assistantMessageEvent":{"type":"toolcall_delta","contentIndex":0,"delta":""}}
{"type":"message_end","message":{"role":"assistant","content":[{"type":"toolCall","id":"HEFIeQfFW","name":"read","arguments":{"path":"math.js","offset":1,"limit":50}},{"type":"toolCall","id":"7Rc4Yw8fp","name":"read","arguments":{"path":"math.test.js","offset":1,"limit":50}},{"type":"toolCall","id":"4vK53wBZb","name":"bash","arguments":{"command":"cat missing.txt","timeout":5}}],"api":"openai-completions","provider":"openrouter","model":"mistralai/devstral-2512","usage":{"input":1583,"output":65,"cacheRead":0,"cacheWrite":0,"reasoning":0,"totalTokens":1648,"cost":{"input":0.0006332000000000001,"output":0.00013,"cacheRead":0,"cacheWrite":0,"total":0.000755568,"totalFromProvider":true}},"stopReason":"toolUse","timestamp":1795790311916,"responseId":"gen-1795790312-9VMDdqzYpui5kDqt0P0f","rawStopReason":"tool_calls","durationMs":2080,"thinkingLevel":"off"}}
{"type":"tool_execution_start","toolCallId":"HEFIeQfFW","toolName":"read","args":{"path":"math.js","offset":1,"limit":50}}
{"type":"tool_execution_update","toolCallId":"4vK53wBZb","toolName":"bash","args":{"command":"cat missing.txt","timeout":5},"partialResult":"<trimmed>"}
{"type":"tool_execution_end","toolCallId":"4vK53wBZb","toolName":"bash","result":{"content":[{"type":"text","text":"cat: missing.txt: No such file or directory\n\n\nCommand exited with code 1"}],"structuredContent":{"output":"cat: missing.txt: No such file or directory\n","truncated":false,"exit_code":1,"wall_time_seconds":0},"isError":true},"isError":true,"durationMs":17}
{"type":"tool_execution_end","toolCallId":"6UNoPXH4u","toolName":"edit","result":{"content":[{"type":"text","text":"Successfully replaced 1 block(s) in math.js."}],"details":{"diff":"...","firstChangedLine":5}},"isError":false,"durationMs":13}
{"type":"message_end","message":{"role":"toolResult","toolCallId":"HEFIeQfFW","toolName":"read","content":[{"type":"text","text":"function add(a, b) {\n  return a + b;\n}\n\nmodule.exports = { add };\n"}],"isError":false,"durationMs":19,"timestamp":1795790314021}}
{"type":"turn_end","message":"<trimmed>","toolResults":[{"role":"toolResult","toolCallId":"4vK53wBZb","toolName":"bash","content":[{"type":"text","text":"cat: missing.txt: No such file or directory\n\n\nCommand exited with code 1"}],"isError":true,"durationMs":17,"timestamp":1795790314022}]}
{"type":"message_end","message":{"role":"assistant","content":[{"type":"text","text":"Done. Added subtract(a, b) to math.js, exported it, and added a test; node --test passes."}],"api":"openai-completions","provider":"openrouter","model":"mistralai/devstral-2512","usage":{"input":2202,"output":164,"cacheRead":0,"cacheWrite":0,"reasoning":0,"totalTokens":2366,"cost":{"input":0.0008808,"output":0.000328,"cacheRead":0,"cacheWrite":0,"total":0.001196712,"totalFromProvider":true}},"stopReason":"stop","timestamp":1795790316556,"responseId":"gen-1795790316-uvu8unnsQlnQFhumFWZy","rawStopReason":"stop","durationMs":2016,"thinkingLevel":"off"}}
{"type":"agent_end","messages":["<trimmed>"],"willRetry":false}
{"type":"agent_settled","aborted":false}

The full event reference is in the package's docs/json.md: message_update.assistantMessageEvent types text_*, thinking_* and toolcall_*; tool_execution_*; compaction and retry events. ProPR runs on SQLite only: do not add code or tests for other databases.

Activity

  1. propr-dev commented on Nov 27, 2026

    @propr-dev
    Contributor

    🤖 AI processing has started for this issue using claude agent with claude-opus-5-5 model.

    I'll analyze the problem and work on a solution. This may take a few minutes.

    Processing Details:

    • Agent: claude
    • Model: claude-opus-5-5
    • Branch: 3832/claude-opus-5-5-pi-agent-type-and-piagent-20261127-1622-0nl
    • Base Branch: 3831-epic-pi-coding-jml
    • Worktree: issue-3832-20261127-1622-claude-opus-5-5-0nl

    🔍 Track Task Execution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions