# fetchai/uagents architecture

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

- Interactive diagram: https://gitdiagram.com/fetchai/uagents
- Repository: https://github.com/fetchai/uagents

## Overview

##### Main Components

a) Core Framework Layer:
- Agent Runtime Environment
- Cryptographic Services
- Communication Protocol Handler
- Storage System
- Task Scheduler

b) Integration Layer:
- External Services Connectors
- API Endpoints
- Blockchain Integration (Fetch.ai)

c) Agent Components:
- Agent Identity Management
- Message Handling System
- Task Management
- State Management

**┌─────────────────────────────────────────────────────────┐**
- Client Applications                    │
- ┘
- ↕
**┌─────────────────────────────────────────────────────────┐**
- uAgents Framework                    │
- ┬─────────────────┬────────────┬───────────┤
- Agent Core │ Communication   │  Storage   │  Security │
- System       │   Layer    │   Layer   │
- ┴─────────────────┴────────────┴───────────┘
- ↕
**┌─────────────────────────────────────────────────────────┐**
- Integration Layer                       │
- ┬──────────┬───────────┬──────────┬───────────┤
- Blockchain│  APIs   │ AI Models │ External │  Protocol │
- (Almanac) │         │           │ Services │  Handlers │
- ┴──────────┴───────────┴──────────┴───────────┘

##### Key Elements to Highlight

a) Agent Components:
- Use hexagons to represent individual agents
- Internal agent structure (context, tasks, handlers)
- Message flow patterns

b) Communication Patterns:
- Peer-to-peer agent communication
- Broadcast capabilities
- Integration points with external services

c) Security Layer:
- Cryptographic components
- Wallet integration
- Demonstrate message verification flow

##### Implementation Details

- Agent class structure (from /python/src/uagents/agent.py)
- Protocol handlers (from /python/src/uagents/protocol.py)
- Storage system (from /python/src/uagents/storage)
- Communication system (from /python/src/uagents/communication.py)

##### Integration Points

How the various integrations connect:
- AI model integrations (DistilGPT2, T5-base, etc.)
- External APIs (Google Maps, Spotify, etc.)
- Blockchain services
- Database systems

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Client["Client Applications"]
        App1[Web Applications]
        App2[Mobile Apps]
        App3[Desktop Clients]
    end

    subgraph Framework["uAgents Framework"]
        subgraph Core["Agent Core Components"]
            ARE[Agent Runtime Environment]:::core
            TM[Task Management]:::core
            SM[State Management]:::core
            MHS[Message Handling System]:::core
        end

        subgraph CommSys["Communication System"]
            CPH[Communication Protocol Handler]:::comm
            EP[API Endpoints]:::comm
        end

        subgraph SecLayer["Security Layer"]
            CS[Cryptographic Services]:::security
            AIM[Agent Identity Management]:::security
        end

        subgraph Store["Storage Layer"]
            SS[Storage System]:::storage
        end
    end

    subgraph Integration["Integration Layer"]
        subgraph BlockInt["Blockchain Integration"]
            BI[Fetch.ai Blockchain]:::blockchain
            ASC[Almanac Smart Contract]:::blockchain
        end

        subgraph ExtInt["External Integration"]
            ESI[External Services Integration]:::external
            AIM1[AI Models]:::external
            API[External APIs]:::external
        end

        subgraph ExpFeatures["Experimental Features"]
            DLG[Dialogues]:::experimental
            QTA[Quota System]:::experimental
        end
    end

    %% Connections
    Client --> Framework
    Core --> CommSys
    Core --> SecLayer
    Core --> Store
    Framework --> Integration
    
    %% Component Mappings
    click ARE "https://github.com/fetchai/uAgents/blob/main/python/src/uagents/agent.py"
    click CS "https://github.com/fetchai/uAgents/tree/main/python/src/uagents/crypto/"
    click CPH "https://github.com/fetchai/uAgents/blob/main/python/src/uagents/protocol.py"
    click SS "https://github.com/fetchai/uAgents/tree/main/python/src/uagents/storage/"
    click MHS "https://github.com/fetchai/uAgents/blob/main/python/src/uagents/envelope.py"
    click SM "https://github.com/fetchai/uAgents/blob/main/python/src/uagents/context.py"
    click EP "https://github.com/fetchai/uAgents/blob/main/python/src/uagents/asgi.py"
    click BI "https://github.com/fetchai/uAgents/tree/main/integrations/fetchai-blockchain/"
    click TM "https://github.com/fetchai/uAgents/blob/main/python/src/uagents/dispatch.py"
    click ESI "https://github.com/fetchai/uAgents/tree/main/integrations/"
    click AIM "https://github.com/fetchai/uAgents/tree/main/python/src/uagents/crypto/"
    click DLG "https://github.com/fetchai/uAgents/tree/main/python/src/uagents/experimental/dialogues/"
    click QTA "https://github.com/fetchai/uAgents/tree/main/python/src/uagents/experimental/quota/"

    %% Styling
    classDef core fill:#3498db,stroke:#2980b9,color:white
    classDef comm fill:#2ecc71,stroke:#27ae60,color:white
    classDef security fill:#f1c40f,stroke:#f39c12,color:black
    classDef storage fill:#95a5a6,stroke:#7f8c8d,color:white
    classDef blockchain fill:#9b59b6,stroke:#8e44ad,color:white
    classDef external fill:#e67e22,stroke:#d35400,color:white
    classDef experimental fill:#e74c3c,stroke:#c0392b,color:white

    %% Legend
    subgraph Legend
        L1[Core Components]:::core
        L2[Communication]:::comm
        L3[Security]:::security
        L4[Storage]:::storage
        L5[Blockchain]:::blockchain
        L6[External Services]:::external
        L7[Experimental]:::experimental
    end
```
