feat(orchestrator): support pi as a coding agent backend - #32
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 -pand reuses the operator's local~/.piprovider settings; MetaInfer stores no API keys.Why
next-app only supports a hard-coded
claudeagent. 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.pyAgentBackendLiteral gains"pi";_normalize_agent_backendacceptspi/pi-coding-agent/earendil.pi_binconstructor param;_build_pi_commandmaps the orchestratoreffortknob onto pi--thinking(low/medium/high/max) and reuses the operator's configured provider/model.state_diris provided,--session-diris scoped to<state_dir>/pi-sessionsso orchestrator sessions are invisible to a user runningpi --continuefrom 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> --continueturns rely on). The session id is captured from pi's leading events for resume.orchestrator/_bootstrap.pymake_subagent_managergainspi_binandstate_dir; both resolve from args or env (METAINFER_PI_BIN,METAINFER_AGENT_BACKEND), claude remains the default.state_diris forwarded only to the pi backend.orchestrator/token_budget.pyusage_from_result_eventtolerates pi's camelCase usage names (input/output/cacheRead/cacheWrite/cost.total) so a raw pi event is accounted correctly.Tasks
SubAgentManagernow passesstate_dir=state_dirso 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_kernelandport_modelalready wired it. Other backends ignore the kwarg.Docs
effort→--thinkingmapping.Commits
feat(orchestrator): support configurable coding agent backends— cherry-picked from the existing scaffolding (author preserved), brings the claude/codex abstraction next-app currently lacks.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.ok-detail.jsmissing instatic/), unrelated to this PR — confirmed by stashing these changes and re-running on clean next-app.StateStore.init_or_resume(task_type=)API mismatch ingen_infer_framework_cpp), also unrelated — confirmed pre-existing.No new regressions.
Usage