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.3.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. Configure native lifecycle, streaming, budgets, run reports, and tracing.
  7. Typed approval and cancellation bridge.
  8. ProtoLink conversation state inspection, compaction, reset, and persistence.
  9. Workspace read/search helpers and native recoverable file tool registration.
  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.
runtime_policy.pyTrusted authorization scope, workspace policy, edit/check phases.
runtime_storage.pyCredential selection and terminal sanitization for native redaction.
streaming.pyNative model/process events projected into provisional UI output.
workflow.pyNative Graph with bounded coding and repair attempts.
verification.pyApplication acceptance through native completion checks.
checkpoints.pyPrivate native checkpoint storage, project lease and inventory.
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.
worker_interface.pyTyped small-profile worker calls backed by native ProtoLink child supervision.
mcp.pyLazy MCP configuration, bounded discovery/calls, native policy and model-free setup/probes.
help_agent.pyIsolated Guide agent for /help QUESTION.
context/Context Loom indexer, SQLite store, packer, schemas.
agents/Required Architect/Explorer/Coder/Verifier, optional Tester/Scout/MCP, 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:

terminal
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, Verifier, optional Tester/Scout/MCP, Guide, and state-control facades.
AgentGroupOwned agents, readiness, cleanup and explicitly external resources.
RegistryAgent discovery for Architect delegation.
AgentClientNative delegation between agents over the configured transport.
RunHandle / RunResultTyped events, live cancellation and normalized final results.
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.
RunActionExact prepared commands and file changes with native preview artifacts.
CapabilityPolicyDeny-by-default tool and action permissions.
ApprovalBroker / ApprovalScopeScoped pending requests, correlated decisions and cancellation.
ApprovalRequestPolicy pause before command execution, file writes or restoration.
ApprovalDecisionHuman decision from the Rust app.
StorageCheckpointStoreDedicated SQLite-backed native file recovery records.
CompletionCheck / CompletionValidatorExecuted outcomes and revision-dependent acceptance.
GraphOne initial attempt and at most two bounded repair attempts.
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_native_runtime.pyReal native tools, broker correlation, runtime/SSE meshes, uncertainty and bounded repairs without paid models.
core/tests/test_verification.pyNative process outcomes, resource revisions and completion evidence.
core/tests/test_checkpoints.pyPrivate storage, native restoration, conflicts and legacy inspection.
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 expected evidence.
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:

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