# ruc-nlpir/deepagent architecture

> Architecture diagram of the GitHub repository ruc-nlpir/deepagent, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-11-04). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ruc-nlpir/deepagent
- Repository: https://github.com/ruc-nlpir/deepagent

## Overview

##### Project type and purpose
- DeepAgent is a full-stack Python application implementing a modular, microservice-style reasoning agent.
- It orchestrates LLM-based reasoning, dynamic tool discovery, and execution across multiple benchmarks (ToolBench, API-Bank, ALFWorld, GAIA, WebShop, HLE).

##### File structure
- Top-level:
- config/ – YAML configurations for models, APIs, and data paths
- data/ – Pre-processed datasets and initial databases for each benchmark
- figures/ – Static images used in README
- src/ – Core Python code, subdivided into:
– envs/ – Environment wrappers (ALFWorld, WebShop)
– evaluate/ – Post-run evaluation scripts per benchmark
– prompts/ – Task-specific LLM prompt templates
– tools/ – Tool modules (API-Bank client, RapidAPI proxy, Python executor, file processor, search, etc.)
– utils/ – Shared utilities (OAS parsing, math equivalence, general helpers)
– run_deep_agent.py & run_tool_search_server.py – Entry points for agent and tool-retriever services
- requirements.txt, LICENSE, README.md

##### Key insights from README
- Core components:
- DeepAgent orchestrator (main & auxiliary LLMs)
- Tool Retriever micro-service (semantic tool search)
- vLLM model-serving endpoints for reasoning and VQA
- Autonomous memory folding (episodic, working, tool memory)
- Workflows: closed-set vs. open-set (tool search enabled)
- Evaluation pipelines per benchmark

a. Main components:
- CLI / Orchestrator: run_deep_agent.py parses config, dataset, and flags
- Config Loader: reads base_config.yaml, supplies API keys and service URLs
- Data Store (data/): JSON, JSONL, OAS specs, initial DBs
- DeepAgent Core:
- Reasoning Loop & Memory Manager
- Prompt Manager (prompts/)
- Tool Manager (selects and invokes tool modules)
- Microservices:
- Main LLM Service (vLLM endpoint)
- Auxiliary LLM Service (memory folding, tool retrieval hints)
- VQA Service (for GAIA / HLE image tasks)
- Tool Retriever Service (run_tool_search_server.py)
- Tool Modules (src/tools/):
- API-Bank client
- RapidAPI / ToolBench proxy
- RestBench client (TMDB, Spotify)
- Python Executor
- File Processor & Multimodal Tools
- Google Search / Serper API
- ToolHop executor
- Environment Wrappers (src/envs/): ALFWorld, WebShop
- Evaluation Engine (src/evaluate/): per-benchmark metrics

b. Relationships & data flows:
1. User invokes CLI → Config Loader → Data Store
2. Orchestrator → DeepAgent Core
3. Core sends prompt → Main LLM Service → Core receives reasoning token stream
4. Core decides: memory fold? → Auxiliary LLM Service → updates Memory Manager
5. Core chooses tool → Tool Retriever Service (optional) → ranked tool list → Core
6. Core → Tool Manager calls appropriate Tool Module → external API / environment simulator → returns observation
7. Observation → Core → Next prompt → loop until task done
8. Outputs & logs → Evaluation Engine → metrics

c. Architectural patterns & design principles:
- Plugin-based tool architecture: each tool encapsulated in src/tools/ with a unified interface
- Microservices for heavy-weight tasks (LLM inference, tool retrieval)
- Decoupled config and code; all keys, URLs in YAML
- Memory abstraction: segregated episodic, working, and tool memories
- Batch evaluation decoupled via src/evaluate/

d. Technologies & frameworks:
- Python 3.10+
- vLLM for model serving (main, auxiliary, VQA)
- YAML for configuration
- JSON/JSONL for dataset storage
- FastAPI or Flask (implied) for tool-search server
- Conda / pip for environment

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Data and Config
    subgraph "Data & Config"
        direction TB
        ConfigLoader["Config Loader"]:::data
        DataStore(["Data Store"]):::data
    end

    %% CLI Orchestrator
    Orchestrator["DeepAgent Orchestrator (CLI)"]:::core

    %% Core Agent
    subgraph "DeepAgent Core"
        direction TB
        PromptManager["Prompt Manager"]:::core
        MemoryManager["Memory Manager"]:::core
        ToolManager["Tool Manager"]:::core
    end

    %% Services
    subgraph "External Services"
        direction TB
        MainLLM["Main LLM Service (vLLM)"]:::service
        AuxLLM["Auxiliary LLM Service"]:::service
        VQAService["VQA Service"]:::service
        ToolRetriever["Tool Retriever Service"]:::service
    end

    %% Tools and Environments
    subgraph "Tools & Env Wrappers" 
        direction TB
        subgraph "Tool Modules" 
            direction TB
            APIBank["API-Bank Client"]:::toolenv
            RapidAPI["RapidAPI Proxy"]:::toolenv
            RestBench["RestBench Client"]:::toolenv
            PyExec["Python Executor"]:::toolenv
            FileProc["File Processor"]:::toolenv
            GoogleSearch["Google Search / Serper API"]:::toolenv
            MultiModal["Multimodal Tools"]:::toolenv
            ToolHop["ToolHop Executor"]:::toolenv
        end
        subgraph "Env Wrappers"
            direction TB
            ALFWorld["ALFWorld Env"]:::toolenv
            WebShop["WebShop Env"]:::toolenv
        end
    end

    %% Evaluation
    Evaluation["Evaluation Engine"]:::data

    %% Connections
    Orchestrator -->|reads| ConfigLoader
    Orchestrator -->|loads| DataStore
    Orchestrator -->|initializes| PromptManager
    Orchestrator -->|initializes| MemoryManager
    Orchestrator -->|initializes| ToolManager

    PromptManager -->|sends prompt| MainLLM
    MainLLM -->|response tokens| PromptManager

    PromptManager -->|memory check| AuxLLM
    AuxLLM -->|memory hints| MemoryManager

    ToolManager -->|tool search| ToolRetriever
    ToolRetriever -->|ranked tools| ToolManager

    ToolManager -->|invoke| APIBank
    ToolManager -->|invoke| RapidAPI
    ToolManager -->|invoke| RestBench
    ToolManager -->|invoke| PyExec
    ToolManager -->|invoke| FileProc
    ToolManager -->|invoke| GoogleSearch
    ToolManager -->|invoke| MultiModal
    ToolManager -->|invoke| ToolHop

    APIBank -->|calls API| ExternalAPI["External API"]:::service
    RapidAPI -->|calls API| ExternalAPI
    RestBench -->|calls API| ExternalAPI
    GoogleSearch -->|calls API| ExternalAPI
    MultiModal -->|calls| VQAService
    PyExec -->|executes code| Local
    FileProc -->|file ops| Local

    ALFWorld -->|simulate| ToolManager
    WebShop -->|simulate| ToolManager

    PromptManager -->|observations| MemoryManager
    MemoryManager -->|state| PromptManager

    PromptManager -->|final output| Evaluation
    ToolManager -->|logs| Evaluation

    %% Click Events
    click Orchestrator "https://github.com/ruc-nlpir/deepagent/blob/main/src/run_deep_agent.py"
    click ConfigLoader "https://github.com/ruc-nlpir/deepagent/blob/main/config/base_config.yaml"
    click DataStore "https://github.com/ruc-nlpir/deepagent/tree/main/data/"
    click PromptManager "https://github.com/ruc-nlpir/deepagent/tree/main/src/prompts/"
    click ToolManager "https://github.com/ruc-nlpir/deepagent/blob/main/src/tools/tool_manager.py"
    click ToolRetriever "https://github.com/ruc-nlpir/deepagent/blob/main/src/run_tool_search_server.py"
    click APIBank "https://github.com/ruc-nlpir/deepagent/blob/main/src/tools/api_bank.py"
    click RapidAPI "https://github.com/ruc-nlpir/deepagent/blob/main/src/tools/rapid_api.py"
    click RestBench "https://github.com/ruc-nlpir/deepagent/blob/main/src/tools/restbench_api.py"
    click PyExec "https://github.com/ruc-nlpir/deepagent/blob/main/src/tools/python_executor.py"
    click FileProc "https://github.com/ruc-nlpir/deepagent/blob/main/src/tools/file_process.py"
    click GoogleSearch "https://github.com/ruc-nlpir/deepagent/blob/main/src/tools/google_search.py"
    click MultiModal "https://github.com/ruc-nlpir/deepagent/blob/main/src/tools/multimodal_tools.py"
    click ToolHop "https://github.com/ruc-nlpir/deepagent/blob/main/src/tools/toolhop.py"
    click ALFWorld "https://github.com/ruc-nlpir/deepagent/blob/main/src/envs/alfworld.py"
    click WebShop "https://github.com/ruc-nlpir/deepagent/blob/main/src/envs/webshop.py"
    click Evaluation "https://github.com/ruc-nlpir/deepagent/tree/main/src/evaluate/"

    %% Styles
    classDef core fill:#D0E6FF,stroke:#0066CC,color:#003366;
    classDef service fill:#DFF2D8,stroke:#339933,color:#225522;
    classDef data fill:#FFE7C6,stroke:#CC9900,color:#663300;
    classDef toolenv fill:#E8D8F8,stroke:#9933CC,color:#663399;
```
