Skip to main content

Core Overview

The Python core lives under core/protoagent_core/. It is the shared runtime brain behind the Rust CLI and the planned ACP server.

The active core package version is 0.2.0. It is declared in core/pyproject.toml and exported as protoagent_core.__version__.

The core is responsible for:

  1. Provider config and redacted display state.
  2. Model discovery and API key validation.
  3. LLM construction through ProtoLink.
  4. Context Loom indexing and prompt injection.
  5. Agent deck assembly, including opt-in Scout registration.
  6. ProtoLink runtime startup, streaming, budgets, run reports, and tracing.
  7. Typed approval and cancellation bridge.
  8. ProtoLink conversation state inspection, compaction, reset, and persistence.
  9. Workspace-safe read/search/diff/write helpers.
  10. Optional ProtoLink web-search/fetch wiring with an explicit network boundary.

Package Map

PathResponsibility
agent_engine.pyPyO3-facing JSON functions called by Rust.
_version.pyCore version, ACP development marker lookup, and component inventory helpers.
runtime.pyEmbedded ProtoLink mesh runner.
runtime_bridge.pyFile-based progress, approval, and cancellation bridge.
history.pyProtoLink-owned conversation state controls.
llm.pyProvider to ProtoLink LLM wiring and readiness checks.
models.pyLocal/API model discovery and API key validation.
config.pyProvider config, API keys, context window, prompt profile, and optional-agent settings.
tools.pyWorkspace-safe deterministic tools.
help_agent.pyIsolated Guide agent for /help QUESTION.
context/Context Loom indexer, SQLite store, packer, schemas.
agents/Architect, Explorer, Coder, optional Scout factories, and deck assembly.

Core Contract With Rust

Rust imports protoagent_core.agent_engine and calls functions that return JSON strings. The CLI parses those strings into Rust structs such as CoreResponse, ModelInventory, VisibleConfig, and DoctorReport.

This keeps the boundary stable and debuggable:

Rust command or TUI action
-> PyO3 call
-> Python core function
-> JSON string
-> Rust display state

ProtoAgent intentionally uses ProtoLink as the runtime engine. Important ProtoLink objects used by the core include:

ProtoLink objectHow ProtoAgent uses it
AgentArchitect, Explorer, Coder, optional Scout, Guide, and state-control facades.
RegistryAgent discovery for Architect delegation.
AgentClientSend tasks, stream task events, cancel tasks.
TaskUser requests and final responses.
RunContextSession id, workspace URI, permissions, budget, metadata, trace id.
RunBudgetRuntime limits from environment and provider config.
RunRecorderNormalized runtime event collection.
RunEventStable UI trace/timeline input.
RunReportRedacted durable run report returned to Rust.
RunActionWorkspace write proposal with preview artifacts.
CapabilityPolicyDeny-by-default tool and action permissions.
ApprovalRequestPolicy pause before write execution.
ApprovalDecisionHuman decision from the Rust app.
TaskCancellationRequestLive cancellation from the TUI.
ConversationStateDurable Architect memory and state-control facades.
ToolFirst-party agent tools, including Scout's bounded web_search and fetch_url.

RunContract is a ProtoAgent application contract defined in run_contracts.py; it is serialized into RunContext.metadata. It is not a ProtoLink public object. This separation is deliberate: ProtoLink enforces generic runtime behavior while ProtoAgent decides what counts as a completed coding task.

Primary Flow

Tests

The core tests focus on runtime contracts rather than only prompt text:

Test fileCoverage
core/tests/test_runtime_integration.pyPolicies, approvals, cancellation, streaming, run budgets, event/report behavior.
core/tests/test_history_integration.pyProtoLink conversation state describe, compact, reset, and top-level turn persistence.
core/tests/test_run_contracts.pyTask contract inference and completion validation.
core/tests/test_context_indexer.pyIncremental index refresh and unchanged-file accounting.
core/tests/test_agent_manifest.pyRuntime architecture manifest exposed to CLI diagnostics.
core/tests/test_llm_context.pyOllama context window, metrics profile, runtime prompt budget, context continuity ownership.
core/tests/test_help_agent.pyGuide isolation, no tools/storage, current settings snapshot.

Run them with:

PYTHONPATH=core .venv/bin/python -m unittest discover core/tests