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 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.
  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.

Package Map

PathResponsibility
agent_engine.pyPyO3-facing JSON functions called by Rust.
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 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 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, 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 per-agent memory.

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_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