Skip to content

feat(orchestrator): support pi as a coding agent backend - #32

Merged
myrfy001 merged 2 commits into
HuangPuStar:next-appfrom
Bsgg1:feat/pi-agent-backend
Sep 11, 2026
Merged

myrfy001 merged 2 commits into
HuangPuStar:next-appfrom
Bsgg1:feat/pi-agent-backend

Conversation

@Bsgg1

@Bsgg1 Bsgg1 commented Sep 9, 2026

Copy link
Copy Markdown

What

Adds pi (https://pi.dev) as a coding-agent backend for the orchestrator, alongside the existing claude/codex backends. The orchestrator invokes pi --mode json -p and reuses the operator's local ~/.pi provider settings; MetaInfer stores no API keys.

Why

next-app only supports a hard-coded claude agent. This brings the configurable agent-backend abstraction (claude/codex/pi) and the pi implementation so operators can run MetaInfer with pi as the sub-agent driver.

Changes

orchestrator/subagent_manager.py

  • AgentBackend Literal gains "pi"; _normalize_agent_backend accepts pi / pi-coding-agent / earendil.
  • pi_bin constructor param; _build_pi_command maps the orchestrator effort knob onto pi --thinking (low/medium/high/max) and reuses the operator's configured provider/model.
  • pi session isolation: when state_dir is provided, --session-dir is scoped to <state_dir>/pi-sessions so orchestrator sessions are invisible to a user running pi --continue from their shell (pi indexes sessions by cwd; without this a user could attach to a production orchestrator session mid-flight and corrupt the context that later --session <id> --continue turns rely on). The session id is captured from pi's leading events for resume.

orchestrator/_bootstrap.py

  • make_subagent_manager gains pi_bin and state_dir; both resolve from args or env (METAINFER_PI_BIN, METAINFER_AGENT_BACKEND), claude remains the default. state_dir is forwarded only to the pi backend.

orchestrator/token_budget.py

  • usage_from_result_event tolerates pi's camelCase usage names (input / output / cacheRead / cacheWrite / cost.total) so a raw pi event is accounted correctly.

Tasks

  • Every task orchestrator that builds a SubAgentManager now passes state_dir=state_dir so the pi backend can scope its session store per task: calc_value, find_low_hanging_kernel, gen_cpp_infer_framework, gen_infer_framework, gen_infer_framework_cpp, opt_kernel, dcu_kernel_auto_opt, evolve_kernel. opt_GEMM_kernel and port_model already wired it. Other backends ignore the kwarg.

Docs

  • README (en/zh): pi backend install, env vars, and the effort--thinking mapping.

Commits

  1. feat(orchestrator): support configurable coding agent backends — cherry-picked from the existing scaffolding (author preserved), brings the claude/codex abstraction next-app currently lacks.
  2. feat(orchestrator): support pi as a coding agent backend — the pi implementation on top.

Tests

  • test_subagent_manager (pi command building, thinking-level mapping, session-dir scoping, resume-id capture) — 31 passed.
  • test_token_budget (pi camelCase usage parsing) — pass.
  • Full orchestrator + server suite: 135 passed. 2 failures are pre-existing on next-app (opt-kernel ok-detail.js missing in static/), unrelated to this PR — confirmed by stashing these changes and re-running on clean next-app.
  • Task suites for touched tasks: 414 passed; 2 pre-existing failures (StateStore.init_or_resume(task_type=) API mismatch in gen_infer_framework_cpp), also unrelated — confirmed pre-existing.

No new regressions.

Usage

npm i -g @earendil-works/pi-coding-agent
pi auth status   # verify a provider is configured
METAINFER_AGENT_BACKEND=pi ./serve.py
# or if pi is not on PATH:
METAINFER_AGENT_BACKEND=pi METAINFER_PI_BIN=/path/to/pi ./serve.py

Bsgg1 and others added 2 commits September 9, 2026 16:38
Adds `pi` (https://pi.dev) as a third agent backend alongside claude and
codex. The orchestrator invokes `pi --mode json -p` and reuses the
operator's local ~/.pi provider settings; MetaInfer stores no API keys.

orchestrator/subagent_manager.py
  - AgentBackend Literal gains "pi"; _normalize_agent_backend accepts
    pi / pi-coding-agent / earendil.
  - pi_bin constructor param; _build_pi_command maps the orchestrator
    effort knob onto pi --thinking (low/medium/high/max) and reuses the
    operator's configured provider/model.
  - pi session isolation: when state_dir is provided, --session-dir is
    scoped to <state_dir>/pi-sessions so orchestrator sessions are
    invisible to a user running `pi --continue` from their shell (pi
    indexes sessions by cwd; without this a user could attach to a
    production orchestrator session mid-flight and corrupt the context
    that later --session <id> --continue turns rely on). The session id
    is captured from pi's leading events for resume.

orchestrator/_bootstrap.py
  - make_subagent_manager gains pi_bin and state_dir; both resolve from
    args or env (METAINFER_PI_BIN, METAINFER_AGENT_BACKEND) with claude
    remaining the default. state_dir is forwarded only to the pi
    backend.

orchestrator/token_budget.py
  - usage_from_result_event tolerates pi's camelCase usage names
    (input / output / cacheRead / cacheWrite / cost.total) so a raw pi
    event is accounted correctly.

tasks
  - Every task orchestrator that builds a SubAgentManager now passes
    state_dir=state_dir so the pi backend can scope its session store
    per task (calc_value, find_low_hanging_kernel, gen_cpp_infer_framework,
    gen_infer_framework, gen_infer_framework_cpp, opt_kernel,
    dcu_kernel_auto_opt, evolve_kernel). opt_GEMM_kernel and port_model
    already wired it. Other backends ignore the kwarg.

docs
  - README (en/zh): document the pi backend, install, env vars and the
    effort->thinking mapping.

tests
  - test_subagent_manager covers pi command building, thinking-level
    mapping, session-dir scoping and resume-id capture.
  - test_token_budget covers pi camelCase usage parsing.
@myrfy001
myrfy001 merged commit 329e1d0 into HuangPuStar:next-app Sep 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants