# vrsen/agency-swarm architecture

> Architecture diagram of the GitHub repository vrsen/agency-swarm, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/vrsen/agency-swarm
- Repository: https://github.com/vrsen/agency-swarm

## Overview

##### Main Components

a) Core Framework Components:
- Agency Manager (agency_swarm/agency/agency.py)
- Agent System (agency_swarm/agents)
- Threading System (agency_swarm/threads)
- Tools Framework (agency_swarm/tools)
- Message Handler (agency_swarm/messages)
- User Interface (agency_swarm/user)

b) Genesis System:
- Genesis Agency
- Agent Creator
- Tool Creator
- OpenAPI Creator

c) Built-in Agents:
- Browsing Agent
- Developer Agent (Devid)

##### Component Relationships

**[User Interface Layer]**
- ↕
**[Agency Manager]**
- ↙     ↓     ↘
**[Agents] ↔ [Tools] ↔ [Messages]**
- ↓         ↓
**[Threads] [OpenAI API]**

**[Genesis Agency]**
- ↙     ↓     ↘
**[Agent Creator] [Tool Creator] [OpenAPI Creator]**

##### Implementation Details

- Integration with OpenAI's Assistant API
- Tool factory pattern for OpenAPI schema conversion
- Message routing system
- State management system (settings.json)

##### Specific Elements to Highlight

- Tool Creation System using Instructor
- Agent Communication Patterns
- File/Resource Management
- State Management
- Async Communication Capabilities

##### Additional Notes

- Tool creation process
- Agent initialization flow
- Genesis agency operations
- Communication patterns

- Customizable agent roles
- Tool creation and management
- Communication flows
- State management
- Deployment capabilities

Remember to maintain a balance between showing the complexity of the system while keeping it understandable. Use clear labels and group related components together. Consider creating separate views for different aspects of the system (e.g., runtime view, deployment view, component view) if needed for clarity.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles
    classDef core fill:#a8d1f0,stroke:#333
    classDef agent fill:#90EE90,stroke:#333
    classDef tool fill:#FFE5B4,stroke:#333
    classDef external fill:#DDA0DD,stroke:#333
    classDef genesis fill:#FFA07A,stroke:#333
    classDef interface fill:#E6E6FA,stroke:#333

    %% User Interface Layer
    UI["User Interface"]:::interface
    click UI "https://github.com/VRSEN/agency-swarm/tree/main/agency_swarm/user/"

    %% Core Components
    AM["Agency Manager"]:::core
    click AM "https://github.com/VRSEN/agency-swarm/blob/main/agency_swarm/agency/agency.py"
    AS["Agent System"]:::core
    click AS "https://github.com/VRSEN/agency-swarm/tree/main/agency_swarm/agents/"
    TS["Threading System"]:::core
    click TS "https://github.com/VRSEN/agency-swarm/tree/main/agency_swarm/threads/"
    TF["Tools Framework"]:::core
    click TF "https://github.com/VRSEN/agency-swarm/tree/main/agency_swarm/tools/"
    MH["Message Handler"]:::core
    click MH "https://github.com/VRSEN/agency-swarm/tree/main/agency_swarm/messages/"

    %% External Services
    OpenAI{"OpenAI API"}:::external

    %% Genesis System
    subgraph Genesis
        GA["Genesis Agency"]:::genesis
        click GA "https://github.com/VRSEN/agency-swarm/blob/main/agency_swarm/agency/genesis/GenesisAgency.py"
        AC["Agent Creator"]:::genesis
        click AC "https://github.com/VRSEN/agency-swarm/tree/main/agency_swarm/agency/genesis/AgentCreator/"
        TC["Tool Creator"]:::genesis
        click TC "https://github.com/VRSEN/agency-swarm/tree/main/agency_swarm/agency/genesis/ToolCreator/"
        OC["OpenAPI Creator"]:::genesis
        click OC "https://github.com/VRSEN/agency-swarm/tree/main/agency_swarm/agency/genesis/OpenAPICreator/"
    end

    %% Built-in Agents
    subgraph Agents
        BA["Browsing Agent"]:::agent
        click BA "https://github.com/VRSEN/agency-swarm/tree/main/agency_swarm/agents/BrowsingAgent/"
        DA["Developer Agent (Devid)"]:::agent
        click DA "https://github.com/VRSEN/agency-swarm/tree/main/agency_swarm/agents/Devid/"
    end

    %% Relationships
    UI --> AM
    AM --> AS
    AM --> TF
    AM --> MH
    AS --> TS
    AS --> OpenAI
    TF --> OpenAI
    MH --> AS
    MH --> TF

    %% Genesis Relationships
    GA --> AC
    GA --> TC
    GA --> OC
    AC --> AS
    TC --> TF
    OC --> TF

    %% Agent Relationships
    AS --> BA
    AS --> DA
    BA <--> DA

    %% Legend
    subgraph Legend
        L1["Core Component"]:::core
        L2["Agent Component"]:::agent
        L3["Tool Component"]:::tool
        L4{"External Service"}:::external
        L5["Genesis Component"]:::genesis
        L6["Interface Component"]:::interface
    end
```
