How stepfun-ai/stepdeepresearch works
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: react_agent.py ReAct loop · http_server.py HTTP/WebSocket server · agent_factory.py Agent factory · dr_agent.py Research agent assembly
Components 20
Entry Points
- Demo server · Launches the interactive WebSocket demo.
demo/server.py - Batch runner · Runs offline or ad-hoc research jobs.
scripts/runner.py
Agent Core
- Research agent assembly · Composes model, prompt, tools, and limits.
demo/dr_agent/dr_agent.py - Agent factory · Selects and constructs configured agents.
cortex/agents/agent_factory.py - Agent lifecycle · Defines contracts and iterative step execution.
cortex/agents/base_step_agent.py - ReAct loop · Iterates reasoning, actions, and report generation.
cortex/agents/react_agent.py
Execution Services
- Context state · Provides simple and file-backed conversation state.
cortex/context/base_context.py - Checkpoint agents · Persists recoverable long-running agent state.
cortex/agents/checkpoint_agent/checkpoint_agent.py - HTTP/WebSocket server · Exposes agent execution and streaming events.
cortex/server/http_server.py - WebSocket channel · Carries live events to connected clients.
cortex/server/channel/ws_channel.py - Orchestrator · Coordinates local or remote runners.
cortex/orchestrator/orchestrator.py - Local / remote runners · Provide local and remote execution paths.
cortex/orchestrator/local_runner.py
Model & Tools
- Model provider · Resolves the configured StepFun model provider.
cortex/model/provider.py - StepFun chat · Implements chat interaction with StepFun.
cortex/model/stepfun_chat.py - Toolset · Aggregates tools behind a common protocol.
cortex/tools/toolset.py - Research tools · Search, browsing, files, todos, and shell capabilities.
demo/tools/batch_search.py - StepFun APIs · Model and search APIs configured from environment.
UI & Observability
- React UI · Renders chat and streamed research state.
cortex-ui/src/App.tsx - UI API client · Consumes backend communication.
cortex-ui/src/services/api.ts - Tracing · Captures spans locally or remotely.
agentkit/trace/tracer.py
Connections 21
- 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