# stepfun-ai/stepdeepresearch architecture

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

- Interactive diagram: https://gitdiagram.com/stepfun-ai/stepdeepresearch
- Repository: https://github.com/stepfun-ai/stepdeepresearch

## Overview

#### Purpose and Entry Points
Step-DeepResearch is a Python deep-research-agent framework with a React/Vite demo UI. A single ReAct-style agent iteratively reasons, calls tools, and emits a cited research report. Primary launch paths are `demo/server.py` for the WebSocket service/UI and `scripts/runner.py` for offline batch or ad-hoc execution. The demo agent is defined in `demo/dr_agent/dr_agent.py`.

#### Agent Execution Core
The agent abstraction separates generic lifecycle/step handling from concrete ReAct behavior. `cortex/agents/base_agent.py` and `cortex/agents/base_step_agent.py` define agent contracts and iterative execution; `cortex/agents/react_agent.py` implements the reasoning/action loop. `cortex/agents/agent_factory.py` selects/builds configured agents. The research-specific assembly in `demo/dr_agent/dr_agent.py` supplies the model, prompt, toolset, and runtime limits.

#### Model and Configuration Boundary
Model calls are provider-mediated rather than embedded in agent logic. `cortex/model/provider.py` and `cortex/model/stepfun_provider.py` resolve the configured StepFun provider; `cortex/model/stepfun_chat.py` implements chat interaction. Environment and runtime defaults are centralized in `cortex/env.py` and `cortex/runtime_config.py`. External dependencies are StepFun’s model API and its search API, configured through root `.env` values such as `MODEL_BASE`, `STEP_MODEL_API_KEY`, and search equivalents.

#### Tool Execution Layer
Agents invoke a common tool protocol through `cortex/tools/base.py` and aggregate capabilities via `cortex/tools/toolset.py`. The demo supplies research-facing tools in `demo/tools/`: web search/browsing (`batch_search.py`, `batch_web_surfer.py`), file operations (`file.py`), task tracking (`todo.py`), and shell execution (`shell.py`). Tool adapters also support function, client, agent, session, channel, and MCP-based integrations under `cortex/tools/`.

#### Context, State, and Checkpointing
Conversation/task state is abstracted behind `cortex/context/base_context.py`, with simple and file-backed implementations in `cortex/context/simple_context.py` and `cortex/context/file_context.py`. Long-running or resumable flows use the checkpoint-agent subsystem: `cortex/agents/checkpoint_agent/checkpoint_agent.py`, `cortex/agents/checkpoint_agent/checkpointer.py`, and its ReAct variant. This is a boundary between in-process execution state and persisted/recoverable agent state.

#### Runtime Transport and Orchestration
The server exposes agent execution over HTTP/WebSocket using `cortex/server/http_server.py` and channel implementations including `cortex/server/channel/ws_channel.py` and `cortex/server/channel/memory_channel.py`. Orchestration abstracts where execution occurs: `cortex/orchestrator/orchestrator.py` coordinates runners, while `local_runner.py` and `remote_runner.py` represent local versus remote execution paths. Streaming events cross this channel boundary to clients and runners.

#### Observability and UI
Tracing is a standalone subsystem: `agentkit/trace/tracer.py`, `agentkit/trace/local_tracer.py`, and `agentkit/trace/remote_tracer.py` capture spans locally or remotely; server logging integrates trace handling in `cortex/server/log/trace.py`. The frontend starts at `cortex-ui/src/main.tsx` and `cortex-ui/src/App.tsx`; `cortex-ui/src/pages/ChatPage.tsx` consumes backend communication through `cortex-ui/src/services/api.ts`. Panels render streamed tool-specific state, including search, shell, files, todos, webpages, and final answers.

Main entry points: [`cortex/agents/react_agent.py`](https://github.com/stepfun-ai/stepdeepresearch/blob/main/cortex/agents/react_agent.py) (ReAct loop), [`cortex/server/http_server.py`](https://github.com/stepfun-ai/stepdeepresearch/blob/main/cortex/server/http_server.py) (HTTP/WebSocket server), [`cortex/agents/agent_factory.py`](https://github.com/stepfun-ai/stepdeepresearch/blob/main/cortex/agents/agent_factory.py) (Agent factory), [`demo/dr_agent/dr_agent.py`](https://github.com/stepfun-ai/stepdeepresearch/blob/main/demo/dr_agent/dr_agent.py) (Research agent assembly)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Entry Points"]
  node_demo_server["Demo server<br/>Python entry point<br/>[server.py]"]
  node_batch_runner["Batch runner<br/>Python entry point<br/>[runner.py]"]
end

subgraph group_agent["Agent Core"]
  node_research_agent["Research agent assembly<br/>agent configuration<br/>[dr_agent.py]"]
  node_agent_factory["Agent factory<br/>agent builder<br/>[agent_factory.py]"]
  node_agent_lifecycle["Agent lifecycle<br/>agent base classes<br/>[base_step_agent.py]"]
  node_react_loop{{"ReAct loop<br/>agent runtime<br/>[react_agent.py]"}}
end

subgraph group_execution["Execution Services"]
  node_context[("Context state<br/>context storage<br/>[base_context.py]")]
  node_checkpointing[("Checkpoint agents<br/>recovery subsystem")]
  node_http_server["HTTP/WebSocket server<br/>transport server<br/>[http_server.py]"]
  node_ws_channel["WebSocket channel<br/>streaming channel<br/>[ws_channel.py]"]
  node_orchestrator["Orchestrator<br/>execution coordinator<br/>[orchestrator.py]"]
  node_runners["Local / remote runners<br/>execution backends<br/>[local_runner.py]"]
end

subgraph group_integrations["Model &amp; Tools"]
  node_provider["Model provider<br/>provider resolution<br/>[provider.py]"]
  node_stepfun_chat["StepFun chat<br/>model client<br/>[stepfun_chat.py]"]
  node_toolset["Toolset<br/>tool registry<br/>[toolset.py]"]
  node_research_tools["Research tools<br/>demo tool adapters<br/>[batch_search.py]"]
  node_external_apis(("StepFun APIs<br/>external services"))
end

subgraph group_client["UI &amp; Observability"]
  node_frontend["React UI<br/>Vite frontend<br/>[App.tsx]"]
  node_ui_api["UI API client<br/>frontend transport<br/>[api.ts]"]
  node_tracing["Tracing<br/>observability subsystem<br/>[tracer.py]"]
end

node_demo_server -->|"starts"| node_http_server
node_batch_runner -->|"builds agent"| node_agent_factory
node_http_server -->|"streams through"| node_ws_channel
node_ws_channel -->|"events"| node_ui_api
node_ui_api -->|"updates"| node_frontend
node_http_server -->|"submits execution"| node_orchestrator
node_orchestrator -->|"selects backend"| node_runners
node_runners -->|"runs"| node_agent_factory
node_agent_factory -->|"configures"| node_research_agent
node_research_agent -->|"instantiates"| node_react_loop
node_agent_lifecycle -->|"base execution"| node_react_loop
node_react_loop -->|"reads and writes state"| node_context
node_react_loop -.->|"checkpoints"| node_checkpointing
node_react_loop -->|"requests inference"| node_provider
node_provider -->|"resolves client"| node_stepfun_chat
node_stepfun_chat -->|"model calls"| node_external_apis
node_react_loop -->|"invokes tools"| node_toolset
node_toolset -->|"provides"| node_research_tools
node_research_tools -->|"search requests"| node_external_apis
node_http_server -.->|"records traces"| node_tracing
node_react_loop -.->|"emits spans"| node_tracing

click node_demo_server "https://github.com/stepfun-ai/stepdeepresearch/blob/main/demo/server.py"
click node_batch_runner "https://github.com/stepfun-ai/stepdeepresearch/blob/main/scripts/runner.py"
click node_research_agent "https://github.com/stepfun-ai/stepdeepresearch/blob/main/demo/dr_agent/dr_agent.py"
click node_agent_factory "https://github.com/stepfun-ai/stepdeepresearch/blob/main/cortex/agents/agent_factory.py"
click node_agent_lifecycle "https://github.com/stepfun-ai/stepdeepresearch/blob/main/cortex/agents/base_step_agent.py"
click node_react_loop "https://github.com/stepfun-ai/stepdeepresearch/blob/main/cortex/agents/react_agent.py"
click node_context "https://github.com/stepfun-ai/stepdeepresearch/blob/main/cortex/context/base_context.py"
click node_checkpointing "https://github.com/stepfun-ai/stepdeepresearch/blob/main/cortex/agents/checkpoint_agent/checkpoint_agent.py"
click node_http_server "https://github.com/stepfun-ai/stepdeepresearch/blob/main/cortex/server/http_server.py"
click node_ws_channel "https://github.com/stepfun-ai/stepdeepresearch/blob/main/cortex/server/channel/ws_channel.py"
click node_orchestrator "https://github.com/stepfun-ai/stepdeepresearch/blob/main/cortex/orchestrator/orchestrator.py"
click node_runners "https://github.com/stepfun-ai/stepdeepresearch/blob/main/cortex/orchestrator/local_runner.py"
click node_provider "https://github.com/stepfun-ai/stepdeepresearch/blob/main/cortex/model/provider.py"
click node_stepfun_chat "https://github.com/stepfun-ai/stepdeepresearch/blob/main/cortex/model/stepfun_chat.py"
click node_toolset "https://github.com/stepfun-ai/stepdeepresearch/blob/main/cortex/tools/toolset.py"
click node_research_tools "https://github.com/stepfun-ai/stepdeepresearch/blob/main/demo/tools/batch_search.py"
click node_frontend "https://github.com/stepfun-ai/stepdeepresearch/blob/main/cortex-ui/src/App.tsx"
click node_ui_api "https://github.com/stepfun-ai/stepdeepresearch/blob/main/cortex-ui/src/services/api.ts"
click node_tracing "https://github.com/stepfun-ai/stepdeepresearch/blob/main/agentkit/trace/tracer.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_demo_server,node_batch_runner toneBlue
class node_research_agent,node_agent_factory,node_agent_lifecycle,node_react_loop toneAmber
class node_context,node_checkpointing,node_http_server,node_ws_channel,node_orchestrator,node_runners toneMint
class node_provider,node_stepfun_chat,node_toolset,node_research_tools,node_external_apis toneRose
class node_frontend,node_ui_api,node_tracing toneIndigo
```

## Components

### Entry Points

- [Demo server](https://github.com/stepfun-ai/stepdeepresearch/blob/main/demo/server.py): Python entry point · Launches the interactive WebSocket demo. · `demo/server.py`
- [Batch runner](https://github.com/stepfun-ai/stepdeepresearch/blob/main/scripts/runner.py): Python entry point · Runs offline or ad-hoc research jobs. · `scripts/runner.py`

### Agent Core

- [Research agent assembly](https://github.com/stepfun-ai/stepdeepresearch/blob/main/demo/dr_agent/dr_agent.py): agent configuration · Composes model, prompt, tools, and limits. · `demo/dr_agent/dr_agent.py`
- [Agent factory](https://github.com/stepfun-ai/stepdeepresearch/blob/main/cortex/agents/agent_factory.py): agent builder · Selects and constructs configured agents. · `cortex/agents/agent_factory.py`
- [Agent lifecycle](https://github.com/stepfun-ai/stepdeepresearch/blob/main/cortex/agents/base_step_agent.py): agent base classes · Defines contracts and iterative step execution. · `cortex/agents/base_step_agent.py`
- [ReAct loop](https://github.com/stepfun-ai/stepdeepresearch/blob/main/cortex/agents/react_agent.py): agent runtime · Iterates reasoning, actions, and report generation. · `cortex/agents/react_agent.py`

### Execution Services

- [Context state](https://github.com/stepfun-ai/stepdeepresearch/blob/main/cortex/context/base_context.py): context storage · Provides simple and file-backed conversation state. · `cortex/context/base_context.py`
- [Checkpoint agents](https://github.com/stepfun-ai/stepdeepresearch/blob/main/cortex/agents/checkpoint_agent/checkpoint_agent.py): recovery subsystem · Persists recoverable long-running agent state. · `cortex/agents/checkpoint_agent/checkpoint_agent.py`
- [HTTP/WebSocket server](https://github.com/stepfun-ai/stepdeepresearch/blob/main/cortex/server/http_server.py): transport server · Exposes agent execution and streaming events. · `cortex/server/http_server.py`
- [WebSocket channel](https://github.com/stepfun-ai/stepdeepresearch/blob/main/cortex/server/channel/ws_channel.py): streaming channel · Carries live events to connected clients. · `cortex/server/channel/ws_channel.py`
- [Orchestrator](https://github.com/stepfun-ai/stepdeepresearch/blob/main/cortex/orchestrator/orchestrator.py): execution coordinator · Coordinates local or remote runners. · `cortex/orchestrator/orchestrator.py`
- [Local / remote runners](https://github.com/stepfun-ai/stepdeepresearch/blob/main/cortex/orchestrator/local_runner.py): execution backends · Provide local and remote execution paths. · `cortex/orchestrator/local_runner.py`

### Model & Tools

- [Model provider](https://github.com/stepfun-ai/stepdeepresearch/blob/main/cortex/model/provider.py): provider resolution · Resolves the configured StepFun model provider. · `cortex/model/provider.py`
- [StepFun chat](https://github.com/stepfun-ai/stepdeepresearch/blob/main/cortex/model/stepfun_chat.py): model client · Implements chat interaction with StepFun. · `cortex/model/stepfun_chat.py`
- [Toolset](https://github.com/stepfun-ai/stepdeepresearch/blob/main/cortex/tools/toolset.py): tool registry · Aggregates tools behind a common protocol. · `cortex/tools/toolset.py`
- [Research tools](https://github.com/stepfun-ai/stepdeepresearch/blob/main/demo/tools/batch_search.py): demo tool adapters · Search, browsing, files, todos, and shell capabilities. · `demo/tools/batch_search.py`
- **StepFun APIs**: external services · Model and search APIs configured from environment.

### UI & Observability

- [React UI](https://github.com/stepfun-ai/stepdeepresearch/blob/main/cortex-ui/src/App.tsx): Vite frontend · Renders chat and streamed research state. · `cortex-ui/src/App.tsx`
- [UI API client](https://github.com/stepfun-ai/stepdeepresearch/blob/main/cortex-ui/src/services/api.ts): frontend transport · Consumes backend communication. · `cortex-ui/src/services/api.ts`
- [Tracing](https://github.com/stepfun-ai/stepdeepresearch/blob/main/agentkit/trace/tracer.py): observability subsystem · Captures spans locally or remotely. · `agentkit/trace/tracer.py`

## Connections

- Demo server → HTTP/WebSocket server: starts
- Batch runner → Agent factory: builds agent
- HTTP/WebSocket server → WebSocket channel: streams through
- WebSocket channel → UI API client: events
- UI API client → React UI: updates
- HTTP/WebSocket server → Orchestrator: submits execution
- Orchestrator → Local / remote runners: selects backend
- Local / remote runners → Agent factory: runs
- Agent factory → Research agent assembly: configures
- Research agent assembly → ReAct loop: instantiates
- Agent lifecycle → ReAct loop: base execution
- ReAct loop → Context state: reads and writes state
- ReAct loop → Checkpoint agents: checkpoints
- ReAct loop → Model provider: requests inference
- Model provider → StepFun chat: resolves client
- StepFun chat → StepFun APIs: model calls
- ReAct loop → Toolset: invokes tools
- Toolset → Research tools: provides
- Research tools → StepFun APIs: search requests
- HTTP/WebSocket server → Tracing: records traces
- ReAct loop → Tracing: emits spans
