Skip to content

[Tracking]: Pi-style Local Agent adaptation for LangBot runner #6

Description

@huanghuoguoguo

Goal

Implement the useful parts of Pi Agent in langbot-local-agent while preserving LangBot's architecture:

  • LangBot Host owns authorization, resources, transcript/history, artifacts, state/storage, and platform delivery.
  • Local Agent Runner owns model-facing behavior: message/context assembly, tool loop policy, context budgeting, and recovery strategy.
  • The runner must use AgentRunAPIProxy and ctx.resources; it must not reach into host-private managers or assume Pi's local filesystem/security model.
  • Pipeline remains a compatibility adapter, not the design center.

Source References

Non-goals

  • Do not copy Pi CLI/TUI product behavior wholesale.
  • Do not add per-conversation mutable state to the plugin instance.
  • Do not bypass Host authorization to access local files, tools, models, knowledge bases, or storage.
  • Do not commit dependency files (pyproject.toml, uv.lock) unless a dependency change is explicitly intended.

Implementation Checklist

Phase 0: Guardrails and Baseline

  • Preserve current prompt_get / effective prompt direction if present in the active branch.
  • Preserve skill_authoring / skill_injection capabilities if present in the active branch.
  • Keep all runner resource access behind AgentRunAPIProxy.
  • Add or update tests before claiming any checklist item complete.

Phase 1: Pi-style Tool Loop

  • Add same-batch parallel tool execution for independent tool calls, borrowing Pi's semantics:
    • preflight/prepare tool calls in assistant source order;
    • execute allowed tool calls concurrently;
    • emit tool.call.completed as each tool finishes;
    • append model-facing tool result messages in original assistant source order.
  • Keep a sequential fallback mode/config for tools or deployments that must avoid concurrency.
  • Preserve existing max-tool-iterations loop guard.
  • Add tests proving parallel execution and source-order tool result messages.

Phase 2: Tool Result Bounding

  • Add max-tool-result-chars / equivalent runner config.
  • Truncate or summarize oversized tool results before injecting them into the next model request.
  • Prefer Host artifact/storage references for large results when the Host API is available.
  • Provide a safe fallback marker when artifact/storage APIs are unavailable.
  • Add tests for string, JSON, error, and oversized structured tool results.

Phase 3: Per-turn Context Budgeting

  • Move context budgeting from one-time run assembly to before every LLM turn in the tool loop.
  • Re-budget after assistant tool calls and tool result messages are appended.
  • Keep prompt/current input/recent context priority clear and documented.
  • Add tests where a large tool result would exceed budget unless compacted/bounded.

Phase 4: Context Overflow Recovery

  • Detect provider context overflow errors in both streaming and non-streaming paths.
  • Compact more aggressively and retry once, similar to Pi's overflow compact-and-retry path.
  • Avoid infinite retry loops; expose a clear runner.context_overflow failure code after the one retry.
  • Add tests for retry-on-overflow and fail-after-second-overflow.

Phase 5: LLM Summary / Checkpoint Path

  • Replace deterministic summary-only compaction with an optional Host-authorized summarization path.
  • Persist compaction checkpoints through Host state/storage when available.
  • Keep deterministic fallback for environments without summary model/storage access.
  • Add tests for checkpoint reload through Host history/state API.

Phase 6: LangBot QA Gates

  • Unit tests in langbot-local-agent pass.
  • Browser E2E local-agent-basic-debug-chat passes.
  • Browser E2E local-agent-plugin-tool-call-debug-chat passes.
  • Add a dedicated multi-tool-call E2E case in langbot-skills when the fixture supports it.

Current Sprint Slice

  • Implement Phase 1 parallel tool execution first.
  • Implement Phase 2 tool result bounding next.
  • Reassess Phase 3 design after Phase 1/2 tests are passing, because per-turn budgeting touches both the loop and context pipeline.

Acceptance Notes

A feature is not done merely because the issue body says it is covered. Mark items complete only when source code, focused tests, and at least the relevant LangBot browser smoke path agree.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions