# darwin-lfl/langmanus architecture

> Architecture diagram of the GitHub repository darwin-lfl/langmanus, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/darwin-lfl/langmanus
- Repository: https://github.com/darwin-lfl/langmanus

## Overview

##### Major Components
- Agents/Modules: The core of the system is the multi-agent orchestration. Based on the README and the src/agents folder, include components such as:
- Coordinator: Acts as the entry point and task router.
- Planner: Analyzes tasks and creates execution strategies.
- Supervisor: Oversees the workflow, delegating tasks to other agents.
- Researcher, Coder, Browser, Reporter, File Manager: Each defined in separate prompt markdown files under src/prompts.
- (Also note that the src/agents/llm.py suggests integration with language models for processing tasks.)
- API Server: Represented by the FastAPI implementation in src/api/app.py (or server.py). This component is responsible for exposing endpoints (like /api/chat/stream) to handle chat interactions and generate streaming responses via Server-Sent Events.
- Workflow & Orchestration: Highlight the workflow component (see src/workflow.py and src/service/workflow_service.py) that manages the sequence of tasks and inter-agent communication.
- Tools & Integrations: Include the utilities provided in src/tools (e.g., bash_tool, browser, search, Python REPL, file management) and crawling modules (src/crawler) that support external interactions such as web crawling (Jina and Tavily integration).
- Graph & Visualization: With the presence of src/graph (builder, nodes, types), visually represent the workflow and inter-agent task delegation as a graph structure.
- Configuration: Detected under src/config, which sets up environment variables, agents’ configurations, and tool settings. This indicates the importance of a configurability layer.
- External Services: Mark integrations with external APIs and services (e.g., Tavily API for search, Jina for neural search, and the configurable LLM endpoints).

##### Relationships and Interactions
- Routing/Entry: The Coordinator receives the initial input and directs it to the appropriate agent based on task type.
- Tools and External Integrations: For agents that need to perform specific operations (e.g., web search, crawling, file management), illustrate connectivity with tool components from src/tools and src/crawler.
- API and Service Interaction Flow: Represent the FastAPI server handling incoming HTTP requests, which then pass these requests into the multi-agent orchestration layer. Also, include data flow back to the user via streaming endpoints.
- Configuration Layer: Show how the configuration settings (from src/config) affect various components (such as agent setup and tool initialization).

##### Architectural Patterns and Design Principles
- Separation of Concerns: Clearly separate the core modules—agents, API, tools, workflow, and configuration—to make the overall design easier to understand and maintain.
- Extensibility and Modularity: Note that each specialized agent has its own prompt definition (stored in markdown under src/prompts), which supports easy modification and extension without changing the base code.

## Diagram (Mermaid)

```mermaid
graph TD
    U["User Interaction (CLI/Web UI)"]:::external

    subgraph "API Layer"
        A["API Server (FastAPI)"]:::api
    end

    subgraph "Workflow Engine"
        W["Workflow Engine"]:::workflow
    end

    subgraph "Multi-Agent System"
        Coord["Coordinator"]:::agents
        Plan["Planner"]:::agents
        Super["Supervisor"]:::agents
        Res["Researcher"]:::agents
        Code["Coder"]:::agents
        Brow["Browser"]:::agents
        Rep["Reporter"]:::agents
        FMan["File Manager"]:::agents
        LLM["LLM Integration"]:::agents
    end

    subgraph "Tools & Integrations"
        Tools["Tools (Utilities: Web Search, Python REPL, Bash)"]:::tools
        Craw["Crawler & External Integrations"]:::tools
    end

    Graph["Graph & Visualization"]:::tools
    Config["Configuration"]:::config

    U -->|"initiates"| A
    A -->|"routes_tasks"| W
    W -->|"delegates_tasks"| Coord
    Coord -->|"analyzes_tasks"| Plan
    Coord -->|"delegates_tasks"| Super
    Coord -->|"calls_LLM"| LLM
    Plan -->|"enhances_planning"| LLM
    Super -->|"assigns_tasks"| Res
    Super -->|"assigns_tasks"| Code
    Super -->|"assigns_tasks"| Brow
    Super -->|"assigns_tasks"| Rep
    Super -->|"assigns_tasks"| FMan
    Res -->|"utilizes"| Tools
    Code -->|"utilizes"| Tools
    Brow -->|"utilizes"| Tools
    Rep -->|"utilizes"| Tools
    FMan -->|"utilizes"| Tools
    Tools -->|"supports"| Craw
    W -->|"visualizes"| Graph
    Config -->|"configures"| A
    Config -->|"configures"| W
    Config -->|"configures"| Coord
    Config -->|"configures"| Tools
    Config -->|"configures"| Craw
    Config -->|"configures"| Graph

    click Coord "https://github.com/darwin-lfl/langmanus/blob/main/src/prompts/coordinator.md"
    click Plan "https://github.com/darwin-lfl/langmanus/blob/main/src/prompts/planner.md"
    click Super "https://github.com/darwin-lfl/langmanus/blob/main/src/prompts/supervisor.md"
    click Res "https://github.com/darwin-lfl/langmanus/blob/main/src/prompts/researcher.md"
    click Code "https://github.com/darwin-lfl/langmanus/blob/main/src/prompts/coder.md"
    click Brow "https://github.com/darwin-lfl/langmanus/blob/main/src/prompts/browser.md"
    click Rep "https://github.com/darwin-lfl/langmanus/blob/main/src/prompts/reporter.md"
    click FMan "https://github.com/darwin-lfl/langmanus/blob/main/src/prompts/file_manager.md"
    click LLM "https://github.com/darwin-lfl/langmanus/blob/main/src/agents/llm.py"
    click A "https://github.com/darwin-lfl/langmanus/blob/main/src/api/app.py"
    click W "https://github.com/darwin-lfl/langmanus/blob/main/src/workflow.py"
    click W "https://github.com/darwin-lfl/langmanus/blob/main/src/service/workflow_service.py"
    click Tools "https://github.com/darwin-lfl/langmanus/tree/main/src/tools"
    click Craw "https://github.com/darwin-lfl/langmanus/tree/main/src/crawler"
    click Graph "https://github.com/darwin-lfl/langmanus/tree/main/src/graph"
    click Config "https://github.com/darwin-lfl/langmanus/tree/main/src/config"

    classDef external fill:#f0a2a2,stroke:#333,stroke-width:2px;
    classDef api fill:#a2d8f0,stroke:#333,stroke-width:2px;
    classDef workflow fill:#d8a2f5,stroke:#333,stroke-width:2px;
    classDef agents fill:#a2f5a2,stroke:#333,stroke-width:2px;
    classDef tools fill:#f5caa2,stroke:#333,stroke-width:2px;
    classDef config fill:#f5f5a2,stroke:#333,stroke-width:2px;
```
