The Big Picture
When you callkapso.evolve(), the OrchestratorAgent runs an experiment loop that generates, tests, and refines solutions until one meets your criteria.
Step by Step
Step 1: Initialize Components
Whenevolve() is called, Kapso creates the execution stack:
| Component | Module | Role |
|---|---|---|
| ProblemHandler | src.environment.handlers | Wraps goal + evaluator + stop condition |
| OrchestratorAgent | src.execution.orchestrator | Runs the solve loop |
| SearchStrategy | src.execution.search_strategies | Generates and selects solutions |
| ExperimentWorkspace | src.execution.experiment_workspace | Manages Git branches |
| CodingAgent | src.execution.coding_agents | Writes code (Aider, Claude, etc.) |
| KnowledgeSearch | src.knowledge.search | Retrieves KG context |
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: LinearSearch — One idea per iteration:Step 5: Write Code
ExperimentSession coordinates code generation:ExperimentWorkspace:
Step 6: Run and Evaluate
ProblemHandler.run() executes code and scores it:Step 7: Debug Loop
If code fails, _implement_n_debug() retries:Step 8: Check Stop Condition
StopCondition.check() determines if we’re done:| Condition | Module | Triggers When |
|---|---|---|
threshold | builtin.ThresholdStopCondition | Score >= target |
plateau | builtin.PlateauStopCondition | No improvement for N iterations |
cost_limit | builtin.CostLimitStopCondition | API cost exceeds budget |
composite | builtin.CompositeStopCondition | Any/all conditions met |
Step 9: Return Result
When the loop ends, Kapso returns the best solution:Budget Tracking
OrchestratorAgent tracks three budgets:| Budget | Tracked By | Stops When |
|---|---|---|
| Time | time.time() | Wall-clock limit reached |
| Iterations | Loop counter | Max experiments reached |
| Cost | get_cumulative_cost() | API costs exceed limit |