# opensage-agent/opensage-adk architecture

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

- Interactive diagram: https://gitdiagram.com/opensage-agent/opensage-adk
- Repository: https://github.com/opensage-agent/opensage-adk

## Overview

#### Purpose and Entry Points
OpenSage-ADK is a Python 3.12+ development kit for self-programming AI agents: agents can create sub-agent topologies, synthesize tools/skills, and maintain structured memory at runtime. Primary user entry points are the CLI and local web UI in `src/opensage/cli/opensage_cli.py` and `src/opensage/cli/opensage_web_app.py`. Custom agents expose an `mk_agent(session_id, model=None)` factory; runnable examples live under `agent_library/`.

#### Agent Runtime and Dynamic Topology
`OpenSageAgent` is the central agent abstraction at `src/opensage/agents/opensage_agent.py`. It is instantiated with model, instructions, tools, subagents, and enabled skills. The orchestration layer manages dynamically created agents, invocation, lifecycle, messaging, and persisted state through `src/opensage/orchestration/manager.py`, `src/opensage/orchestration/instance.py`, and `src/opensage/orchestration/inbox.py`. This is the control-plane boundary between an agent’s model loop and multi-agent execution, supporting sequential decomposition and parallel/ensemble patterns.

#### Sessions, Memory, and Context Management
A session binds runtime resources and services for an agent invocation in `src/opensage/session/opensage_session.py`, with sandbox and Neo4j managers in `src/opensage/session/opensage_sandbox_manager.py` and `src/opensage/session/opensage_neo4j_client_manager.py`. Memory is primarily file-based: cross-task knowledge storage is under `src/opensage/memory/file_based/long_term/knowledge_store.py`; per-task prompt, sandbox I/O, and session artifacts are handled in `src/opensage/memory/file_based/short_term/`. Summarization and in-memory session services in `src/opensage/features/summarization.py` and `src/opensage/features/opensage_in_memory_session_service.py` control context growth.

#### Tools, Skills, and Extensibility
The toolbox adapts executable capabilities into agent-callable tools, notably shell/skill execution in `src/opensage/toolbox/general/bash_tool.py`, staging/loading support in `src/opensage/utils/bash_tools_staging.py`, and tool normalization in `src/opensage/toolbox/tool_normalization.py`. Skills are packaged as `SKILL.md`-described command sets under `src/opensage/bash_tools/`, including code retrieval, static analysis, fuzzing, coverage, and software-engineering workflows. MCP toolset integrations are represented by providers such as `src/opensage/toolbox/debugger/gdb_mcp/get_toolset.py`.

Plugins modify agent-runtime behavior rather than application orchestration. Loaders are in `src/opensage/plugins/adk_plugin_loader.py` and `src/opensage/plugins/claude_code_hook_loader.py`; built-ins include budget enforcement, history summarization, tool-response summarization, and edit safeguards under `src/opensage/plugins/default/adk_plugins/`.

#### Sandbox and Analysis Infrastructure
Tool execution is isolated behind a sandbox interface and factory: `src/opensage/sandbox/base_sandbox.py` and `src/opensage/sandbox/factory.py`. Supported backends include local, Docker, remote Docker, Podman, Kubernetes, Nitrobox, and OpenSandbox (`src/opensage/sandbox/local_sandbox.py`, `src/opensage/sandbox/native_docker_sandbox.py`, `src/opensage/sandbox/k8s_sandbox.py`). Initializers provision optional analysis services such as CodeQL, Joern, fuzzing, coverage, GDB MCP, and Neo4j via `src/opensage/sandbox/initializers/`.

This boundary is material: agents request tools; tools operate within sandboxed workspaces and may depend on Docker, external containers, or remote infrastructure.

#### Models and External Services
Model selection and spending limits are centralized in `src/opensage/llm/registry.py` and `src/opensage/llm/budget.py`. The documented minimal agent uses Google ADK’s `LiteLlm`, so configured LLM providers require API credentials. Optional external integrations include Neo4j for graph-backed code/memory queries, Joern and CodeQL for static analysis, MCP servers for debugger/binary tools, and web search (`src/opensage/toolbox/general/web_search_tool.py`).

#### Evaluation and Distribution Surfaces
Benchmark adapters dispatch agents across native or Ray execution in `src/opensage/evaluation/dispatchers/native.py` and `src/opensage/evaluation/dispatchers/ray.py`. Benchmark implementations under `benchmarks/` cover SWE-bench Pro, CyberGym, CVEGym, DevOpsGym, Harbor, and related environments. RL adapters bridge the runtime to AREAL, Slime, Miles, and NeMo-style environments under `src/opensage/evaluation/rl_adapters/`. Example agents are the practical integration surface: `agent_library/agents_101/`, `agent_library/agents_with_features/`, and task-oriented agents in `agent_library/agents/`.

Main entry points: [`src/opensage/agents/opensage_agent.py`](https://github.com/opensage-agent/opensage-adk/blob/main/src/opensage/agents/opensage_agent.py) (OpenSageAgent), [`src/opensage/toolbox/tool_normalization.py`](https://github.com/opensage-agent/opensage-adk/blob/main/src/opensage/toolbox/tool_normalization.py) (Toolbox), [`src/opensage/orchestration/manager.py`](https://github.com/opensage-agent/opensage-adk/blob/main/src/opensage/orchestration/manager.py) (Orchestration manager), [`src/opensage/session/opensage_session.py`](https://github.com/opensage-agent/opensage-adk/blob/main/src/opensage/session/opensage_session.py) (OpenSage session)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Entry &amp; Examples"]
  node_cli["CLI<br/>entry point<br/>[opensage_cli.py]"]
  node_web_ui["Local web UI<br/>entry point"]
  node_examples["Example agents<br/>agent factories"]
end

subgraph group_runtime["Agent Runtime"]
  node_agent{{"OpenSageAgent<br/>agent abstraction<br/>[opensage_agent.py]"}}
  node_orchestration["Orchestration manager<br/>control plane<br/>[manager.py]"]
  node_agent_instance["Agent instances<br/>runtime state<br/>[instance.py]"]
  node_inbox["Agent inbox<br/>messaging<br/>[inbox.py]"]
  node_session["OpenSage session<br/>resource binding"]
  node_memory[("File-based memory<br/>long/short-term storage<br/>[knowledge_store.py]")]
  node_context_services["Context services<br/>summarization<br/>[summarization.py]"]
  node_llm["LLM registry &amp; budget<br/>model governance<br/>[registry.py]"]
end

subgraph group_capabilities["Execution &amp; Extensions"]
  node_toolbox["Toolbox<br/>tool adaptation"]
  node_skills["Skill packages<br/>SKILL.md commands"]
  node_plugins["Runtime plugins<br/>behavior extensions"]
  node_sandbox["Sandbox factory<br/>execution isolation<br/>[factory.py]"]
  node_analysis_services["Analysis initializers<br/>optional services"]
  node_external_tools["MCP &amp; web integrations<br/>external toolsets<br/>[get_toolset.py]"]
end

subgraph group_evaluation["Evaluation"]
  node_benchmark_dispatch["Benchmark dispatch<br/>evaluation runner<br/>[native.py]"]
  node_benchmarks["Benchmark suites<br/>evaluation environments"]
  node_rl_adapters["RL adapters<br/>training bridge"]
end

node_cli -->|"loads agents"| node_examples
node_web_ui -->|"loads agents"| node_examples
node_examples -->|"constructs"| node_agent
node_agent -->|"delegates topology"| node_orchestration
node_orchestration -->|"creates"| node_agent_instance
node_orchestration -->|"routes messages"| node_inbox
node_agent -->|"invokes with"| node_session
node_session -->|"persists context"| node_memory
node_context_services -->|"summarizes"| node_memory
node_agent -->|"uses model"| node_llm
node_agent -->|"requests tools"| node_toolbox
node_agent -.->|"extends behavior"| node_plugins
node_toolbox -->|"executes skills"| node_skills
node_toolbox -->|"runs in"| node_sandbox
node_session -->|"manages workspace"| node_sandbox
node_sandbox -.->|"provisions"| node_analysis_services
node_toolbox -.->|"integrates"| node_external_tools
node_benchmark_dispatch -->|"evaluates"| node_agent
node_benchmark_dispatch -->|"dispatches across"| node_benchmarks
node_rl_adapters -->|"bridges runtime"| node_agent

click node_cli "https://github.com/opensage-agent/opensage-adk/blob/main/src/opensage/cli/opensage_cli.py"
click node_web_ui "https://github.com/opensage-agent/opensage-adk/blob/main/src/opensage/cli/opensage_web_app.py"
click node_agent "https://github.com/opensage-agent/opensage-adk/blob/main/src/opensage/agents/opensage_agent.py"
click node_orchestration "https://github.com/opensage-agent/opensage-adk/blob/main/src/opensage/orchestration/manager.py"
click node_agent_instance "https://github.com/opensage-agent/opensage-adk/blob/main/src/opensage/orchestration/instance.py"
click node_inbox "https://github.com/opensage-agent/opensage-adk/blob/main/src/opensage/orchestration/inbox.py"
click node_session "https://github.com/opensage-agent/opensage-adk/blob/main/src/opensage/session/opensage_session.py"
click node_memory "https://github.com/opensage-agent/opensage-adk/blob/main/src/opensage/memory/file_based/long_term/knowledge_store.py"
click node_context_services "https://github.com/opensage-agent/opensage-adk/blob/main/src/opensage/features/summarization.py"
click node_llm "https://github.com/opensage-agent/opensage-adk/blob/main/src/opensage/llm/registry.py"
click node_toolbox "https://github.com/opensage-agent/opensage-adk/blob/main/src/opensage/toolbox/tool_normalization.py"
click node_plugins "https://github.com/opensage-agent/opensage-adk/blob/main/src/opensage/plugins/adk_plugin_loader.py"
click node_sandbox "https://github.com/opensage-agent/opensage-adk/blob/main/src/opensage/sandbox/factory.py"
click node_external_tools "https://github.com/opensage-agent/opensage-adk/blob/main/src/opensage/toolbox/debugger/gdb_mcp/get_toolset.py"
click node_benchmark_dispatch "https://github.com/opensage-agent/opensage-adk/blob/main/src/opensage/evaluation/dispatchers/native.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_cli,node_web_ui,node_examples toneBlue
class node_agent,node_orchestration,node_agent_instance,node_inbox,node_session,node_memory,node_context_services,node_llm toneAmber
class node_toolbox,node_skills,node_plugins,node_sandbox,node_analysis_services,node_external_tools toneMint
class node_benchmark_dispatch,node_benchmarks,node_rl_adapters toneRose
```

## Components

### Entry & Examples

- [CLI](https://github.com/opensage-agent/opensage-adk/blob/main/src/opensage/cli/opensage_cli.py): entry point · `src/opensage/cli/opensage_cli.py`
- [Local web UI](https://github.com/opensage-agent/opensage-adk/blob/main/src/opensage/cli/opensage_web_app.py): entry point · `src/opensage/cli/opensage_web_app.py`
- **Example agents**: agent factories · Agents expose an mk_agent(session_id, model=None) factory.

### Agent Runtime

- [OpenSageAgent](https://github.com/opensage-agent/opensage-adk/blob/main/src/opensage/agents/opensage_agent.py): agent abstraction · Combines model, instructions, tools, subagents, and skills. · `src/opensage/agents/opensage_agent.py`
- [Orchestration manager](https://github.com/opensage-agent/opensage-adk/blob/main/src/opensage/orchestration/manager.py): control plane · Manages dynamic agents, invocation, lifecycle, and persisted state. · `src/opensage/orchestration/manager.py`
- [Agent instances](https://github.com/opensage-agent/opensage-adk/blob/main/src/opensage/orchestration/instance.py): runtime state · `src/opensage/orchestration/instance.py`
- [Agent inbox](https://github.com/opensage-agent/opensage-adk/blob/main/src/opensage/orchestration/inbox.py): messaging · `src/opensage/orchestration/inbox.py`
- [OpenSage session](https://github.com/opensage-agent/opensage-adk/blob/main/src/opensage/session/opensage_session.py): resource binding · Binds services and runtime resources per invocation. · `src/opensage/session/opensage_session.py`
- [File-based memory](https://github.com/opensage-agent/opensage-adk/blob/main/src/opensage/memory/file_based/long_term/knowledge_store.py): long/short-term storage · Stores cross-task knowledge plus task prompts, I/O, and artifacts. · `src/opensage/memory/file_based/long_term/knowledge_store.py`
- [Context services](https://github.com/opensage-agent/opensage-adk/blob/main/src/opensage/features/summarization.py): summarization · Controls context growth with summaries and in-memory sessions. · `src/opensage/features/summarization.py`
- [LLM registry & budget](https://github.com/opensage-agent/opensage-adk/blob/main/src/opensage/llm/registry.py): model governance · Selects providers and enforces spending limits. · `src/opensage/llm/registry.py`

### Execution & Extensions

- [Toolbox](https://github.com/opensage-agent/opensage-adk/blob/main/src/opensage/toolbox/tool_normalization.py): tool adaptation · Normalizes executable capabilities into agent-callable tools. · `src/opensage/toolbox/tool_normalization.py`
- **Skill packages**: SKILL.md commands · Code retrieval, analysis, fuzzing, coverage, and engineering workflows.
- [Runtime plugins](https://github.com/opensage-agent/opensage-adk/blob/main/src/opensage/plugins/adk_plugin_loader.py): behavior extensions · Loads budget, history, tool-response, and edit-safety hooks. · `src/opensage/plugins/adk_plugin_loader.py`
- [Sandbox factory](https://github.com/opensage-agent/opensage-adk/blob/main/src/opensage/sandbox/factory.py): execution isolation · Selects local, container, remote, Kubernetes, and other backends. · `src/opensage/sandbox/factory.py`
- **Analysis initializers**: optional services · Provisions CodeQL, Joern, fuzzing, coverage, GDB MCP, and Neo4j.
- [MCP & web integrations](https://github.com/opensage-agent/opensage-adk/blob/main/src/opensage/toolbox/debugger/gdb_mcp/get_toolset.py): external toolsets · Provides debugger/binary MCP tools and web search. · `src/opensage/toolbox/debugger/gdb_mcp/get_toolset.py`

### Evaluation

- [Benchmark dispatch](https://github.com/opensage-agent/opensage-adk/blob/main/src/opensage/evaluation/dispatchers/native.py): evaluation runner · Runs agents through native or Ray execution. · `src/opensage/evaluation/dispatchers/native.py`
- **Benchmark suites**: evaluation environments · Includes SWE-bench Pro, CyberGym, CVEGym, DevOpsGym, and Harbor.
- **RL adapters**: training bridge · Connects the runtime to AREAL, Slime, Miles, and NeMo-style environments.

## Connections

- CLI → Example agents: loads agents
- Local web UI → Example agents: loads agents
- Example agents → OpenSageAgent: constructs
- OpenSageAgent → Orchestration manager: delegates topology
- Orchestration manager → Agent instances: creates
- Orchestration manager → Agent inbox: routes messages
- OpenSageAgent → OpenSage session: invokes with
- OpenSage session → File-based memory: persists context
- Context services → File-based memory: summarizes
- OpenSageAgent → LLM registry & budget: uses model
- OpenSageAgent → Toolbox: requests tools
- OpenSageAgent → Runtime plugins: extends behavior
- Toolbox → Skill packages: executes skills
- Toolbox → Sandbox factory: runs in
- OpenSage session → Sandbox factory: manages workspace
- Sandbox factory → Analysis initializers: provisions
- Toolbox → MCP & web integrations: integrates
- Benchmark dispatch → OpenSageAgent: evaluates
- Benchmark dispatch → Benchmark suites: dispatches across
- RL adapters → OpenSageAgent: bridges runtime
