Skip to main content

The Big Picture

When you call kapso.evolve(), the OrchestratorAgent runs an experiment loop that generates, tests, and refines solutions until the feedback generator decides the goal is achieved.

Step by Step

Step 1: Initialize Components

When evolve() is called, Kapso creates the execution stack:

Step 2: Gather Context

The ContextManager assembles information for the coding agent:

Step 3: The Solve Loop

OrchestratorAgent.solve() runs the main loop:

Step 4: Generate Solution Ideas

SearchStrategy generates solution candidates: GenericSearch — Claude Code + MCP gates:
BenchmarkTreeSearch — Tree-based exploration:

Step 5: Write Code and Run Evaluation

ExperimentSession coordinates code generation:
The developer agent is responsible for:
  1. Implementing the solution code
  2. Building evaluation in kapso_evaluation/
  3. Running the evaluation
  4. Returning structured JSON with results
When the caller supplies eval_dir, step 2 changes: the agent must run the provided evaluation without changing its source. Kapso fingerprints the suite and verifies the finalized candidate ref before accepting its score. See Evaluation Integrity. Each experiment gets its own Git branch via ExperimentWorkspace:

Step 6: Agent Returns Structured JSON

The developer agent returns a structured JSON with evaluation results:
This JSON is extracted from the agent’s output and used by the feedback generator.

Step 7: Feedback Generation

The FeedbackGenerator validates the evaluation and decides whether to continue:
The feedback generator:
  1. Validates evaluation: Checks if the agent-built evaluation is fair and correct
  2. Extracts score: Parses the evaluation output to get numeric scores
  3. Checks goal: Determines if the goal has been achieved
  4. Generates feedback: Provides actionable suggestions for the next iteration

Step 8: Check Feedback Result

The search strategy checks the feedback result:

Step 9: Optional External Evaluation

When iteration_evaluator is configured, Kapso evaluates every candidate finalized by the strategy before writing experiment history or a run checkpoint. Each candidate ref is materialized in a temporary detached worktree. Returned metrics are stored on node.metrics and remain observational: node.score still controls search and best-branch selection. See External Iteration Evaluation for the callback contract, isolation model, and failure policies.

Step 10: Return Result

When the loop ends, Kapso returns the best solution:

Budget Tracking

OrchestratorAgent tracks three budgets:
The loop stops when any budget hits 100% OR the stop condition is met.

Error Handling

Errors are captured in SearchNode:
The debug prompt includes error context:

Next Steps

Search Strategies

Linear vs Tree search in detail

Orchestrator

Deep dive into OrchestratorAgent

Feedback Generator

How evaluation is validated

Coding Agents

Pluggable code generators