# togethercomputer/hybridagent architecture

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

- Interactive diagram: https://gitdiagram.com/togethercomputer/hybridagent
- Repository: https://github.com/togethercomputer/hybridagent

## Overview

Hybrid Reasoning Agents combines a runtime agent with supervised and reinforcement-learning post-training, batch inference, and latent-trace inspection. The principal user workflow is to submit a question, generate a mixed latent/text trajectory, call tools from text mode, and return an answer; inference can also emit readouts and tool statistics. The graph preserves the documented training and inspection branches. Several internal links are supported by the SOURCE INDEX or README rather than complete excerpts, so uncertain connections are omitted.

Main entry points: [`hybrid_rl/train.py`](https://github.com/togethercomputer/hybridagent/blob/main/hybrid_rl/train.py) (RL trainer), [`hybrid_agent/engine.py`](https://github.com/togethercomputer/hybridagent/blob/main/hybrid_agent/engine.py) (Hybrid generation), [`interpretable_latent_mode/trace.py`](https://github.com/togethercomputer/hybridagent/blob/main/interpretable_latent_mode/trace.py) (Trace capture), [`hybrid_agent/model.py`](https://github.com/togethercomputer/hybridagent/blob/main/hybrid_agent/model.py) (Model wrapper)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Agent runtime"]
  node_engine["Hybrid generation<br/>[engine.py]"]
  node_model["Model wrapper<br/>[model.py]"]
  node_link["HybridLink<br/>[hybridlink.py]"]
  node_prompts["Agent prompt<br/>[prompts.py]"]
  node_readout["Latent readout<br/>[readout.py]"]
  node_executor["Tool executor<br/>[executor.py]"]
  node_python["Python tool<br/>[python_tool.py]"]
  node_search["Search tool<br/>[search_tool.py]"]
  node_cache[("Search cache<br/>[search_cache.py]")]
end

subgraph group_sft["HybridSFT"]
  node_sftdata["Trajectory data<br/>[data.py]"]
  node_sftmodel["SFT model<br/>[model.py]"]
  node_sfttrain["SFT trainer<br/>[train.py]"]
end

subgraph group_rl["HybridRL"]
  node_rlconfig["RL configuration<br/>[config.py]"]
  node_rldata["Prompt data<br/>[data.py]"]
  node_rollout["Policy rollout<br/>[rollout.py]"]
  node_trajectory["Trajectory records<br/>[trajectory.py]"]
  node_reward["Reward scoring<br/>[reward.py]"]
  node_replay["Exact replay<br/>[replay.py]"]
  node_policy["Policy update<br/>[policy.py]"]
  node_rltrain["RL trainer<br/>[train.py]"]
end

subgraph group_inference["Inference and inspection"]
  node_batch["Batch inference<br/>[run_batch.py]"]
  node_trace["Trace capture<br/>[trace.py]"]
  node_render["Trace renderer<br/>[render.py]"]
end

node_user(("Questioner"))
node_tavily["Tavily search"]
node_answer(("Agent answer"))

node_user -->|"submits questions"| node_batch
node_batch -->|"runs generation"| node_engine
node_engine -->|"uses model"| node_model
node_model -->|"applies adapter"| node_link
node_engine -->|"dispatches tools"| node_executor
node_executor -->|"dispatches"| node_python
node_executor -->|"dispatches"| node_search
node_search -->|"reads and writes"| node_cache
node_search -->|"searches"| node_tavily
node_engine -->|"records readout"| node_readout
node_batch -->|"writes results"| node_answer
node_sfttrain -->|"loads trajectories"| node_sftdata
node_sfttrain -->|"trains model"| node_sftmodel
node_sfttrain -->|"uses shared model"| node_model
node_rltrain -->|"uses settings"| node_rlconfig
node_rltrain -->|"loads prompts"| node_rldata
node_rltrain -->|"samples trajectories"| node_rollout
node_rollout -->|"runs agent"| node_engine
node_rollout -->|"records rollout"| node_trajectory
node_rltrain -->|"scores samples"| node_reward
node_rltrain -->|"replays trajectories"| node_replay
node_rltrain -->|"updates policy"| node_policy
node_policy -->|"uses shared model"| node_model
node_trace -->|"extends generation"| node_engine
node_trace -->|"maps latent steps"| node_readout
node_render -->|"renders traces"| node_trace
node_user -->|"requests inspection"| node_trace

click node_batch "https://github.com/togethercomputer/hybridagent/blob/main/hybrid_inference/run_batch.py"
click node_engine "https://github.com/togethercomputer/hybridagent/blob/main/hybrid_agent/engine.py"
click node_model "https://github.com/togethercomputer/hybridagent/blob/main/hybrid_agent/model.py"
click node_link "https://github.com/togethercomputer/hybridagent/blob/main/hybrid_agent/hybridlink.py"
click node_prompts "https://github.com/togethercomputer/hybridagent/blob/main/hybrid_agent/prompts.py"
click node_readout "https://github.com/togethercomputer/hybridagent/blob/main/hybrid_agent/readout.py"
click node_executor "https://github.com/togethercomputer/hybridagent/blob/main/hybrid_agent/tools/executor.py"
click node_python "https://github.com/togethercomputer/hybridagent/blob/main/hybrid_agent/tools/python_tool.py"
click node_search "https://github.com/togethercomputer/hybridagent/blob/main/hybrid_agent/tools/search_tool.py"
click node_cache "https://github.com/togethercomputer/hybridagent/blob/main/hybrid_agent/tools/search_cache.py"
click node_sftdata "https://github.com/togethercomputer/hybridagent/blob/main/hybrid_sft/data.py"
click node_sftmodel "https://github.com/togethercomputer/hybridagent/blob/main/hybrid_sft/model.py"
click node_sfttrain "https://github.com/togethercomputer/hybridagent/blob/main/hybrid_sft/train.py"
click node_rlconfig "https://github.com/togethercomputer/hybridagent/blob/main/hybrid_rl/config.py"
click node_rldata "https://github.com/togethercomputer/hybridagent/blob/main/hybrid_rl/data.py"
click node_rollout "https://github.com/togethercomputer/hybridagent/blob/main/hybrid_rl/rollout.py"
click node_trajectory "https://github.com/togethercomputer/hybridagent/blob/main/hybrid_rl/trajectory.py"
click node_reward "https://github.com/togethercomputer/hybridagent/blob/main/hybrid_rl/reward.py"
click node_replay "https://github.com/togethercomputer/hybridagent/blob/main/hybrid_rl/replay.py"
click node_policy "https://github.com/togethercomputer/hybridagent/blob/main/hybrid_rl/policy.py"
click node_rltrain "https://github.com/togethercomputer/hybridagent/blob/main/hybrid_rl/train.py"
click node_trace "https://github.com/togethercomputer/hybridagent/blob/main/interpretable_latent_mode/trace.py"
click node_render "https://github.com/togethercomputer/hybridagent/blob/main/interpretable_latent_mode/render.py"

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_engine,node_model,node_link,node_prompts,node_readout,node_executor,node_python,node_search,node_cache toneBlue
class node_sftdata,node_sftmodel,node_sfttrain toneAmber
class node_rlconfig,node_rldata,node_rollout,node_trajectory,node_reward,node_replay,node_policy,node_rltrain toneMint
class node_batch,node_trace,node_render toneRose
class node_user,node_tavily,node_answer toneIndigo
```

## Components

### Agent runtime

- [Hybrid generation](https://github.com/togethercomputer/hybridagent/blob/main/hybrid_agent/engine.py): `hybrid_agent/engine.py`
- [Model wrapper](https://github.com/togethercomputer/hybridagent/blob/main/hybrid_agent/model.py): `hybrid_agent/model.py`
- [HybridLink](https://github.com/togethercomputer/hybridagent/blob/main/hybrid_agent/hybridlink.py): `hybrid_agent/hybridlink.py`
- [Agent prompt](https://github.com/togethercomputer/hybridagent/blob/main/hybrid_agent/prompts.py): `hybrid_agent/prompts.py`
- [Latent readout](https://github.com/togethercomputer/hybridagent/blob/main/hybrid_agent/readout.py): `hybrid_agent/readout.py`
- [Tool executor](https://github.com/togethercomputer/hybridagent/blob/main/hybrid_agent/tools/executor.py): `hybrid_agent/tools/executor.py`
- [Python tool](https://github.com/togethercomputer/hybridagent/blob/main/hybrid_agent/tools/python_tool.py): `hybrid_agent/tools/python_tool.py`
- [Search tool](https://github.com/togethercomputer/hybridagent/blob/main/hybrid_agent/tools/search_tool.py): `hybrid_agent/tools/search_tool.py`
- [Search cache](https://github.com/togethercomputer/hybridagent/blob/main/hybrid_agent/tools/search_cache.py): `hybrid_agent/tools/search_cache.py`

### HybridSFT

- [Trajectory data](https://github.com/togethercomputer/hybridagent/blob/main/hybrid_sft/data.py): `hybrid_sft/data.py`
- [SFT model](https://github.com/togethercomputer/hybridagent/blob/main/hybrid_sft/model.py): `hybrid_sft/model.py`
- [SFT trainer](https://github.com/togethercomputer/hybridagent/blob/main/hybrid_sft/train.py): `hybrid_sft/train.py`

### HybridRL

- [RL configuration](https://github.com/togethercomputer/hybridagent/blob/main/hybrid_rl/config.py): `hybrid_rl/config.py`
- [Prompt data](https://github.com/togethercomputer/hybridagent/blob/main/hybrid_rl/data.py): `hybrid_rl/data.py`
- [Policy rollout](https://github.com/togethercomputer/hybridagent/blob/main/hybrid_rl/rollout.py): `hybrid_rl/rollout.py`
- [Trajectory records](https://github.com/togethercomputer/hybridagent/blob/main/hybrid_rl/trajectory.py): `hybrid_rl/trajectory.py`
- [Reward scoring](https://github.com/togethercomputer/hybridagent/blob/main/hybrid_rl/reward.py): `hybrid_rl/reward.py`
- [Exact replay](https://github.com/togethercomputer/hybridagent/blob/main/hybrid_rl/replay.py): `hybrid_rl/replay.py`
- [Policy update](https://github.com/togethercomputer/hybridagent/blob/main/hybrid_rl/policy.py): `hybrid_rl/policy.py`
- [RL trainer](https://github.com/togethercomputer/hybridagent/blob/main/hybrid_rl/train.py): `hybrid_rl/train.py`

### Inference and inspection

- [Batch inference](https://github.com/togethercomputer/hybridagent/blob/main/hybrid_inference/run_batch.py): `hybrid_inference/run_batch.py`
- [Trace capture](https://github.com/togethercomputer/hybridagent/blob/main/interpretable_latent_mode/trace.py): `interpretable_latent_mode/trace.py`
- [Trace renderer](https://github.com/togethercomputer/hybridagent/blob/main/interpretable_latent_mode/render.py): `interpretable_latent_mode/render.py`

### Other components

- **Questioner**
- **Tavily search**
- **Agent answer**

## Connections

- Questioner → Batch inference: submits questions (evidence: `README.md`)
- Batch inference → Hybrid generation: runs generation (evidence: `hybrid_inference/run_batch.py`)
- Hybrid generation → Model wrapper: uses model (evidence: `hybrid_agent/engine.py`)
- Model wrapper → HybridLink: applies adapter (evidence: `hybrid_agent/model.py`)
- Hybrid generation → Tool executor: dispatches tools (evidence: `hybrid_agent/engine.py`)
- Tool executor → Python tool: dispatches (evidence: `hybrid_agent/tools/executor.py`)
- Tool executor → Search tool: dispatches (evidence: `hybrid_agent/tools/executor.py`)
- Search tool → Search cache: reads and writes (evidence: `hybrid_agent/tools/search_tool.py`)
- Search tool → Tavily search: searches (evidence: `hybrid_agent/tools/search_tool.py`)
- Hybrid generation → Latent readout: records readout (evidence: `hybrid_agent/engine.py`)
- Batch inference → Agent answer: writes results (evidence: `README.md`)
- SFT trainer → Trajectory data: loads trajectories (evidence: `hybrid_sft/train.py`)
- SFT trainer → SFT model: trains model (evidence: `hybrid_sft/train.py`)
- SFT trainer → Model wrapper: uses shared model (evidence: `hybrid_sft/train.py`)
- RL trainer → RL configuration: uses settings (evidence: `hybrid_rl/train.py`)
- RL trainer → Prompt data: loads prompts (evidence: `hybrid_rl/train.py`)
- RL trainer → Policy rollout: samples trajectories (evidence: `hybrid_rl/train.py`)
- Policy rollout → Hybrid generation: runs agent (evidence: `hybrid_rl/rollout.py`)
- Policy rollout → Trajectory records: records rollout (evidence: `hybrid_rl/rollout.py`)
- RL trainer → Reward scoring: scores samples (evidence: `hybrid_rl/train.py`)
- RL trainer → Exact replay: replays trajectories (evidence: `hybrid_rl/train.py`)
- RL trainer → Policy update: updates policy (evidence: `hybrid_rl/train.py`)
- Policy update → Model wrapper: uses shared model (evidence: `hybrid_rl/policy.py`)
- Trace capture → Hybrid generation: extends generation (evidence: `interpretable_latent_mode/trace.py`)
- Trace capture → Latent readout: maps latent steps (evidence: `interpretable_latent_mode/trace.py`)
- Trace renderer → Trace capture: renders traces (evidence: `interpretable_latent_mode/render.py`)
- Questioner → Trace capture: requests inspection (evidence: `README.md`)
