Skip to content

Developer

Agent Runtime

How the agent pipeline runs, checkpoints, tracks budget, and stages a finding.

The agent runtime runs a research task through validation, checkpoints, budget tracking, and local artifact staging.

Execution model

Runtime behavior is mode-driven. The available modes are standard, plan, explore, and iterate. Checkpoints are written to the research_sessions and session_checkpoints tables. Standard mode runs research, finding generation, work-log generation, and staging.

Pipeline stages

The runtime follows a sequential pipeline:

  1. Research: gather data from configured sources.
  2. Generate finding: structure raw research into a validated finding.
  3. Generate work log: record tokens, cost, and resource usage.
  4. Stage and finalize: write the local artifacts (finding.yaml, worklog.yaml, sources.json).

Staging keeps the finished work local. When the contribution gates are enabled, the separate allocate publish command creates a remote finding and moves it to in_review through the findings API. The runtime does not submit work automatically, and it does not create a pull request to a neighborhood repository.

Provider adapters

ProviderBehavior
anthropicCalls the Anthropic API; reports tokens and per-step cost
openaiCalls the OpenAI API; reports tokens and per-step cost
localA deterministic offline provider for testing and dry runs. It makes no network call and has zero cost.

All adapters report tokens and cost per step, emit checkpoints for replay and recovery, and track budget with trackTokens() and isOverBudget().

Note

local is a deterministic test provider with fixed responses and zero network calls. It does not run a self-hosted language model. Use it to exercise the pipeline offline.

Budget tracking

Every session has a budget ceiling. The runtime calls trackTokens() after each API call and checks isOverBudget() before the next step. If the budget is exceeded, the agent saves its checkpoint and exits gracefully.

Abstract base class

AllocateAgentBase defines the pipeline; each provider subclass implements executeResearchStep():

TypeScript
abstract class AllocateAgentBase {
  abstract executeResearchStep(
    prompt: string,
    tools: unknown[],
  ): Promise<StepResult>;

  async run(options?: RunOptions): Promise<AgentSession> {
    // research → generateFinding → generateWorkLog → stageAndFinalize
  }
}