How hexo-ai/sia works
1. High-level shape
- This repo is a self-improving agent framework, not a single task app.
- The core loop repeatedly improves a task-specific target agent using two higher-level roles: a meta-agent that creates/initializes the target agent, and a feedback agent that reviews execution logs and edits the agent for the next generation.
2. Core runtime package: sia/
- sia/orchestrator.py is the main control-plane entrypoint for the generation loop.
- sia/context_manager.py is the state-and-artifact boundary: it tracks the current generation, run directory, task context, and the files passed between agents.
- sia/util.py likely contains shared helper logic used across orchestration and task handling.
- sia/__init__.py exposes the package API and CLI-facing surface.
3. The self-improvement data flow
- Input starts with a task definition and its public artifacts.
- The orchestrator feeds that task context to the meta-agent to produce an initial target_agent.py.
- The target agent is executed against the task, producing an agent_execution.json log and task outcomes.
- The feedback agent consumes those logs plus the current agent implementation, then produces an improved agent and an accompanying rationale (improvement.md from generation 2 onward).
- This repeats for max_gen generations, creating a lineage of progressively modified target agents.
4. Task boundary and repository layout
- Tasks live under sia/tasks/ and are treated as isolated benchmark packages.
- Each task has a strict split between:
- data/public/ — visible to the agent
- data/private/ — held-out evaluation material
- reference/ — task-specific reference agent template and sample descriptions
- This split is the main security/performance boundary in the repo: the agent should only see public data while evaluation uses private data.
5. Built-in task families
- The repo ships four benchmark tasks: gpqa, lawbench, longcot-chess, and spaceship-titanic.
- They are not all the same kind of problem, which matters architecturally: some are QA/classification tasks, some are long-context reasoning, and some are ML competition style tasks.
- Each task directory carries its own public task.md, evaluation script, and in some cases training/test CSVs or JSON question sets.
6. Task evaluation mechanism
- Evaluation is task-local, not centralized in the orchestrator.
- Public task directories include evaluate.py or task-specific scoring assets that define how a candidate agent or submission is judged.
- This keeps benchmark logic close to the data and makes external tasks portable as long as they follow the same directory contract.
7. Reference agent templates
- sia/tasks/_shared/reference_target_agent.py is the shared template used as a starting point for target agents.
- Each built-in task also has its own reference_target_agent.py, allowing task-specific scaffolding while preserving a common structure.
- SAMPLE_TASK_DESCRIPTIONS.md files support the meta-agent by giving example task wording and expected style.
8. External task onboarding and dataset bootstrap
- sia/prepare_mlebench_dataset.py converts an MLE-Bench competition into the repo’s task directory format.
- That script is the bridge to external benchmark data, including Kaggle-backed competition assets, and it creates the required public/private split plus reference scaffolding.
- In architecture terms, it is a data ingestion/preparation layer that sits outside the main self-improvement loop.
9. LLM backend boundary
- The system supports multiple agent backends: Claude Agent SDK and OpenHands.
- The backend choice affects which model providers are available, but the orchestrator treats them as interchangeable execution engines for meta/feedback/target roles.
- API keys and provider configuration are part of the runtime environment, not the repo state, which keeps the codebase backend-agnostic at the control-flow level.
10. Artifacts and run outputs
- Runs are materialized under runs/run_{run_id}/gen_{n}/.
- The key artifacts are:
- target_agent.py — the agent code for that generation
- agent_execution.json — execution trace/logs
- improvement.md — explanation of changes
- This directory structure is important for diagramming because it is the persistence layer connecting generations.
11. Configuration and packaging
- pyproject.toml and environment.yml define the Python packaging and environment dependencies.
- The repo targets Python 3.11+ and exposes a CLI (sia --task ... / sia --task_dir ...).
- The configuration docs indicate that models, backends, and API keys are all runtime-configurable, which is central to how the framework is deployed.
12. Quality and release automation
- .github/workflows/ci.yml and publish.yml indicate standard CI and release automation.
- tests/ covers the context manager, orchestrator helpers, and task structure, which suggests the repo’s most important invariants are generation-state management and benchmark directory correctness.
- docs/ contains architecture, walkthrough, configuration, and troubleshooting material, reinforcing that the project is intended to be used as a framework with a strict task contract rather than a single fixed application.
Main entry points: orchestrator.py Orchestrator · tests Tests · context_manager.py Context manager · reference_target_agent.py Target template
Components 22
Core runtime
Main control-plane package that runs the self-improvement loop.
- Package API · Exposes the package entry surface and CLI-facing imports.
sia/__init__.py - Orchestrator · Main generation loop coordinating meta-agent, target execution, and feedback edits.
sia/orchestrator.py - Context manager · Tracks generation state, run directory, task context, and passed artifacts.
sia/context_manager.py - Shared utils · Common helper functions used across orchestration and task handling.
sia/util.py
Task benchmarks
Built-in benchmark tasks with isolated public/private data and local evaluation.
- Target template · Shared starting template for task-specific target agents.
sia/tasks/_shared/reference_target_agent.py - Sample log · Example agent execution trace used as a reference artifact.
sia/tasks/_shared/sample_agent_execution.json - GPQA · Question-answering benchmark with public/private split and local evaluation.
sia/tasks/gpqa - LawBench · Classification or legal reasoning benchmark with task-local scoring assets.
sia/tasks/lawbench - LongCoT Chess · Long-context reasoning task with hidden answers and local evaluation.
sia/tasks/longcot-chess - Spaceship Titanic · Competition-style ML task with train/test splits and submission format.
sia/tasks/spaceship-titanic - Task eval · Per-task evaluation scripts and assets that judge candidate agents or submissions.
- Task refs · Task-specific reference agents and sample descriptions used to initialize new generations.
Run artifacts
Per-generation files written during runs to persist lineage and feedback.
- Run outputs · Materialized generation directories containing target agent code, logs, and rationales.
- Target agent · The evolving agent implementation for a generation.
- Exec log · Execution trace and outcome log produced by running the target agent.
- Improvement note · Human-readable explanation of edits produced from generation 2 onward.
Dataset prep
Import and conversion layer for external benchmark datasets.
- Dataset prep · Converts external MLE-Bench competitions into the repo’s task directory format.
sia/prepare_mlebench_dataset.py
Packaging and ops
Project configuration, docs, tests, and CI/release automation.
- Config · Python packaging and environment definition for runtime dependencies.
pyproject.toml - Env spec · Environment lock/specification for local execution and dependency setup.
environment.yml - Docs · Architecture, walkthrough, configuration, and troubleshooting guides.
docs - Tests · Coverage for context management, orchestrator helpers, and task structure invariants.
tests - CI/CD · GitHub Actions workflows for continuous integration and publishing.
.github/workflows
Connections 29
- Orchestrator → Context manager: manages state · Uses the context manager to track run directory, generation, and artifacts.
- Orchestrator → Target template: initializes · Starts the target agent from the shared reference scaffold.
- Orchestrator → Task eval: delegates scoring · Hands off to task-local evaluation logic via the task contract.
- Orchestrator → Task refs: uses prompts · Consumes task-specific reference material to shape the meta-agent output.
- Orchestrator → Run outputs: writes lineage · Persists each generation’s code, logs, and improvement notes.
- Context manager → Run outputs: tracks paths · Resolves the filesystem boundary for generation artifacts.
- Context manager → Task eval: binds task · Holds task context and the public/private artifact split.
- Target template → Target agent: becomes · Shared scaffold is specialized into a per-generation target agent.
- Target agent → Exec log: produces · The target agent is executed and emits structured logs.
- Exec log → Improvement note: drives feedback · Feedback agent reviews execution traces to produce the next revision.
- Exec log → Orchestrator: feeds loop · Execution outcomes are returned to the control loop for the next generation.
- Improvement note → Target agent: edits next gen · The rationale accompanies the improved agent for the following generation.
- Task refs → Orchestrator: guides setup · Reference descriptions inform how tasks and prompts are prepared.
- GPQA → Task eval: contains · Provides task-local public data and scoring assets.
- LawBench → Task eval: contains · Provides task-local public data and scoring assets.
- LongCoT Chess → Task eval: contains · Provides task-local public data and scoring assets.
- Spaceship Titanic → Task eval: contains · Provides task-local public data and scoring assets.
- Task refs → GPQA: specializes · Each built-in task has its own reference agent and sample descriptions.
- Task refs → LawBench: specializes · Each built-in task has its own reference agent and sample descriptions.
- Task refs → LongCoT Chess: specializes · Each built-in task has its own reference agent and sample descriptions.
- Task refs → Spaceship Titanic: specializes · Each built-in task has its own reference agent and sample descriptions.
- Dataset prep → Task eval: bootstraps · Converts external benchmark data into the repo’s task contract.
- Config → Orchestrator: configures · Defines packaging, entry points, and dependency setup for the runtime.
- Env spec → Orchestrator: configures · Supplies the Python environment needed to execute the framework.
- Docs → Orchestrator: documents · Explains architecture, configuration, and operational usage.
- Tests → Context manager: verifies · Covers generation-state and artifact-boundary behavior.
- Tests → Orchestrator: verifies · Covers orchestration helpers and control-loop invariants.
- Tests → Task eval: verifies · Checks task directory structure and benchmark contract assumptions.
- CI/CD → Tests: runs · CI workflows execute the repository’s test suite and release automation.