# hexo-ai/sia architecture

> Architecture diagram of the GitHub repository hexo-ai/sia, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-31). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/hexo-ai/sia
- Repository: https://github.com/hexo-ai/sia

## Overview

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: [`sia/orchestrator.py`](https://github.com/hexo-ai/sia/blob/main/sia/orchestrator.py) (Orchestrator), [`tests`](https://github.com/hexo-ai/sia/tree/main/tests) (Tests), [`sia/context_manager.py`](https://github.com/hexo-ai/sia/blob/main/sia/context_manager.py) (Context manager), [`sia/tasks/_shared/reference_target_agent.py`](https://github.com/hexo-ai/sia/blob/main/sia/tasks/_shared/reference_target_agent.py) (Target template)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_core["Core runtime"]
  node_sia_init["Package API<br/>python package<br/>[__init__.py]"]
  node_orchestrator["Orchestrator<br/>control loop<br/>[orchestrator.py]"]
  node_context_manager["Context manager<br/>state boundary<br/>[context_manager.py]"]
  node_util["Shared utils<br/>helpers<br/>[util.py]"]
end

subgraph group_tasks["Task benchmarks"]
  node_target_template["Target template<br/>agent scaffold"]
  node_sample_exec["Sample log<br/>execution sample"]
  node_gpqa[("GPQA<br/>benchmark task")]
  node_lawbench[("LawBench<br/>benchmark task")]
  node_chess[("LongCoT Chess<br/>benchmark task")]
  node_titanic[("Spaceship Titanic<br/>benchmark task")]
  node_task_eval["Task eval<br/>local scoring"]
  node_task_ref["Task refs<br/>task scaffolding"]
end

subgraph group_artifacts["Run artifacts"]
  node_run_artifacts[("Run outputs<br/>generation store")]
  node_target_agent["Target agent<br/>generation code"]
  node_exec_log["Exec log<br/>trace file"]
  node_improvement["Improvement note<br/>rationale"]
end

subgraph group_prep["Dataset prep"]
  node_dataset_prep["Dataset prep<br/>ingestion script"]
end

subgraph group_ops["Packaging and ops"]
  node_config["Config<br/>packaging<br/>[pyproject.toml]"]
  node_env["Env spec<br/>runtime env<br/>[environment.yml]"]
  node_docs["Docs<br/>documentation"]
  node_tests["Tests<br/>quality checks"]
  node_ci["CI/CD<br/>automation<br/>[workflows]"]
end

node_orchestrator -->|"manages state"| node_context_manager
node_orchestrator -->|"initializes"| node_target_template
node_orchestrator -->|"delegates scoring"| node_task_eval
node_orchestrator -->|"uses prompts"| node_task_ref
node_orchestrator -->|"writes lineage"| node_run_artifacts
node_context_manager -->|"tracks paths"| node_run_artifacts
node_context_manager -->|"binds task"| node_task_eval
node_target_template -->|"becomes"| node_target_agent
node_target_agent -->|"produces"| node_exec_log
node_exec_log -->|"drives feedback"| node_improvement
node_exec_log -->|"feeds loop"| node_orchestrator
node_improvement -->|"edits next gen"| node_target_agent
node_task_ref -->|"guides setup"| node_orchestrator
node_gpqa -->|"contains"| node_task_eval
node_lawbench -->|"contains"| node_task_eval
node_chess -->|"contains"| node_task_eval
node_titanic -->|"contains"| node_task_eval
node_task_ref -->|"specializes"| node_gpqa
node_task_ref -->|"specializes"| node_lawbench
node_task_ref -->|"specializes"| node_chess
node_task_ref -->|"specializes"| node_titanic
node_dataset_prep -->|"bootstraps"| node_task_eval
node_config -->|"configures"| node_orchestrator
node_env -->|"configures"| node_orchestrator
node_docs -.->|"documents"| node_orchestrator
node_tests -.->|"verifies"| node_context_manager
node_tests -.->|"verifies"| node_orchestrator
node_tests -.->|"verifies"| node_task_eval
node_ci -->|"runs"| node_tests

click node_sia_init "https://github.com/hexo-ai/sia/blob/main/sia/__init__.py"
click node_orchestrator "https://github.com/hexo-ai/sia/blob/main/sia/orchestrator.py"
click node_context_manager "https://github.com/hexo-ai/sia/blob/main/sia/context_manager.py"
click node_util "https://github.com/hexo-ai/sia/blob/main/sia/util.py"
click node_target_template "https://github.com/hexo-ai/sia/blob/main/sia/tasks/_shared/reference_target_agent.py"
click node_sample_exec "https://github.com/hexo-ai/sia/blob/main/sia/tasks/_shared/sample_agent_execution.json"
click node_gpqa "https://github.com/hexo-ai/sia/tree/main/sia/tasks/gpqa"
click node_lawbench "https://github.com/hexo-ai/sia/tree/main/sia/tasks/lawbench"
click node_chess "https://github.com/hexo-ai/sia/tree/main/sia/tasks/longcot-chess"
click node_titanic "https://github.com/hexo-ai/sia/tree/main/sia/tasks/spaceship-titanic"
click node_dataset_prep "https://github.com/hexo-ai/sia/blob/main/sia/prepare_mlebench_dataset.py"
click node_config "https://github.com/hexo-ai/sia/blob/main/pyproject.toml"
click node_env "https://github.com/hexo-ai/sia/blob/main/environment.yml"
click node_docs "https://github.com/hexo-ai/sia/tree/main/docs"
click node_tests "https://github.com/hexo-ai/sia/tree/main/tests"
click node_ci "https://github.com/hexo-ai/sia/blob/main/.github/workflows"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_sia_init,node_orchestrator,node_context_manager,node_util toneBlue
class node_target_template,node_sample_exec,node_gpqa,node_lawbench,node_chess,node_titanic,node_task_eval,node_task_ref toneAmber
class node_run_artifacts,node_target_agent,node_exec_log,node_improvement toneMint
class node_dataset_prep toneRose
class node_config,node_env,node_docs,node_tests,node_ci toneIndigo
```

## Components

### Core runtime

Main control-plane package that runs the self-improvement loop.

- [Package API](https://github.com/hexo-ai/sia/blob/main/sia/__init__.py): python package · Exposes the package entry surface and CLI-facing imports. · `sia/__init__.py`
- [Orchestrator](https://github.com/hexo-ai/sia/blob/main/sia/orchestrator.py): control loop · Main generation loop coordinating meta-agent, target execution, and feedback edits. · `sia/orchestrator.py`
- [Context manager](https://github.com/hexo-ai/sia/blob/main/sia/context_manager.py): state boundary · Tracks generation state, run directory, task context, and passed artifacts. · `sia/context_manager.py`
- [Shared utils](https://github.com/hexo-ai/sia/blob/main/sia/util.py): helpers · 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](https://github.com/hexo-ai/sia/blob/main/sia/tasks/_shared/reference_target_agent.py): agent scaffold · Shared starting template for task-specific target agents. · `sia/tasks/_shared/reference_target_agent.py`
- [Sample log](https://github.com/hexo-ai/sia/blob/main/sia/tasks/_shared/sample_agent_execution.json): execution sample · Example agent execution trace used as a reference artifact. · `sia/tasks/_shared/sample_agent_execution.json`
- [GPQA](https://github.com/hexo-ai/sia/tree/main/sia/tasks/gpqa): benchmark task · Question-answering benchmark with public/private split and local evaluation. · `sia/tasks/gpqa`
- [LawBench](https://github.com/hexo-ai/sia/tree/main/sia/tasks/lawbench): benchmark task · Classification or legal reasoning benchmark with task-local scoring assets. · `sia/tasks/lawbench`
- [LongCoT Chess](https://github.com/hexo-ai/sia/tree/main/sia/tasks/longcot-chess): benchmark task · Long-context reasoning task with hidden answers and local evaluation. · `sia/tasks/longcot-chess`
- [Spaceship Titanic](https://github.com/hexo-ai/sia/tree/main/sia/tasks/spaceship-titanic): benchmark task · Competition-style ML task with train/test splits and submission format. · `sia/tasks/spaceship-titanic`
- **Task eval**: local scoring · Per-task evaluation scripts and assets that judge candidate agents or submissions.
- **Task refs**: task scaffolding · 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**: generation store · Materialized generation directories containing target agent code, logs, and rationales.
- **Target agent**: generation code · The evolving agent implementation for a generation.
- **Exec log**: trace file · Execution trace and outcome log produced by running the target agent.
- **Improvement note**: rationale · Human-readable explanation of edits produced from generation 2 onward.

### Dataset prep

Import and conversion layer for external benchmark datasets.

- [Dataset prep](https://github.com/hexo-ai/sia/blob/main/sia/prepare_mlebench_dataset.py): ingestion script · 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](https://github.com/hexo-ai/sia/blob/main/pyproject.toml): packaging · Python packaging and environment definition for runtime dependencies. · `pyproject.toml`
- [Env spec](https://github.com/hexo-ai/sia/blob/main/environment.yml): runtime env · Environment lock/specification for local execution and dependency setup. · `environment.yml`
- [Docs](https://github.com/hexo-ai/sia/tree/main/docs): documentation · Architecture, walkthrough, configuration, and troubleshooting guides. · `docs`
- [Tests](https://github.com/hexo-ai/sia/tree/main/tests): quality checks · Coverage for context management, orchestrator helpers, and task structure invariants. · `tests`
- [CI/CD](https://github.com/hexo-ai/sia/blob/main/.github/workflows): automation · GitHub Actions workflows for continuous integration and publishing. · `.github/workflows`

## Connections

- 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.
