The Big Picture
When you callkapso.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
Whenevolve() is called, Kapso creates the execution stack:
| Component | Module | Role |
|---|---|---|
| ProblemHandler | src.environment.handlers | Wraps goal and problem context |
| 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 and runs evaluation |
| FeedbackGenerator | (within search strategy) | Validates results and decides stop |
| KnowledgeSearch | src.knowledge_base.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: GenericSearch — Claude Code + MCP gates:Step 5: Write Code and Run Evaluation
ExperimentSession coordinates code generation:- Implementing the solution code
- Building evaluation in
kapso_evaluation/ - Running the evaluation
- Returning structured JSON with results
ExperimentWorkspace:
Step 6: Agent Returns Structured JSON
The developer agent returns a structured JSON with evaluation results:Step 7: Feedback Generation
The FeedbackGenerator validates the evaluation and decides whether to continue:- Validates evaluation: Checks if the agent-built evaluation is fair and correct
- Extracts score: Parses the evaluation output to get numeric scores
- Checks goal: Determines if the goal has been achieved
- Generates feedback: Provides actionable suggestions for the next iteration
Step 8: Check Feedback Result
The search strategy checks the feedback result: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 |