# phil65/llmling-agent architecture

> Architecture diagram of the GitHub repository phil65/llmling-agent, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/phil65/llmling-agent
- Repository: https://github.com/phil65/llmling-agent

## Overview

##### Main Components

a) Core Components:
- Agent System
- Chat Session Manager
- Command System
- Environment Manager
- Tool Management System
- Storage System
- Event System
- Web UI Interface

b) Integration Components:
- LLM Model Integration
- Resource Management
- Agent Pool System
- Message Forwarding System

**┌─ User Interface Layer ─────────────────────┐**
- Web UI (llmling_agent_web)              │
- CLI Interface (llmling_agent_cli)       │
- Textual UI (llmling_textual)            │
- ┬┘
- ↕
**┌─ Core Service Layer ───────────────────────┐**
- ┌─ Agent Management ─┐ ┌─ Chat System ──┐  │
- Agent Pool      │ │ - Sessions     │  │
- Agent Config    │ │ - History      │  │
- Delegation      │ │ - Conversation │  │
- ┘ └───────────────┬─┘  │
- ┌─ Tool System ──────┐ ┌─ Events ────┴─┐  │
- Tool Manager    │ │ - Event Bus   │  │
- Tool Registry   │ │ - Handlers    │  │
- ┘ └───────────────┘  │
- ┘
- ↕
**┌─ Infrastructure Layer ────────────────────┐**
- ┌─ Storage ────────┐ ┌─ Environment ───┐ │
- Query Engine   │ │ - Resources     │ │
- Models         │ │ - Capabilities  │ │
- ┘ └───────────────┬─┘ │
- ┌─ LLM Integration ─┐ ┌─ Commands ───┴─┐ │
- Model Handlers  │ │ - Processors   │ │
- Prompts        │ │ - Completers   │ │
- ┘ └───────────────┘ │
- ┘

##### Key Relationships to Highlight

a) Agent System:
- How agents interact with the tool system
- Message forwarding between agents
- Connection to LLM models

b) Chat System:
- Interaction with storage for history
- Event system integration
- Session management flow

c) Tool System:
- Tool registration flow
- Capability checking
- Resource access paths

##### Implementation Details

- Use double lines for data flow

##### Additional Elements

- Version information
- External service dependencies
- Configuration flow

Remember to include notes about the dynamic nature of the system, particularly how agents can modify their environment and register new tools at runtime.

This system design should provide a clear understanding of how LLMling-Agent works while maintaining the right balance between detail and abstraction.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles
    classDef ui fill:#3498db,stroke:#2980b9,color:white
    classDef core fill:#2ecc71,stroke:#27ae60,color:white
    classDef infra fill:#f1c40f,stroke:#f39c12,color:black
    classDef external fill:#e74c3c,stroke:#c0392b,color:white
    classDef data fill:#9b59b6,stroke:#8e44ad,color:white

    %% User Interface Layer
    subgraph UI
        WebUI["Web UI Interface"]
        CLI["CLI Interface"]
        TUI["Textual UI"]
    end

    %% Core Service Layer
    subgraph CoreServices
        subgraph AgentManagement
            AgentSystem["Agent System"]:::core
            AgentPool["Agent Pool"]:::core
            AgentConfig["Agent Config"]:::core
        end

        subgraph ChatSystem
            ChatSession["Chat Session Manager"]:::core
            History["History Management"]:::core
            Conversation["Conversation Handler"]:::core
        end

        subgraph ToolSystem
            ToolManager["Tool Manager"]:::core
            ToolRegistry["Tool Registry"]:::core
        end

        subgraph EventSystem
            EventBus["Event Bus"]:::core
            EventHandlers["Event Handlers"]:::core
        end
    end

    %% Infrastructure Layer
    subgraph Infrastructure
        subgraph Storage
            QueryEngine["Query Engine"]:::infra
            StorageModels["Storage Models"]:::infra
        end

        subgraph Environment
            EnvManager["Environment Manager"]:::infra
            Resources["Resources"]:::infra
        end

        subgraph LLMIntegration
            ModelHandlers["Model Handlers"]:::infra
            Prompts["Prompts"]:::infra
        end

        subgraph CommandSystem
            CmdProcessors["Command Processors"]:::infra
            CmdCompleters["Command Completers"]:::infra
        end
    end

    %% Relationships
    WebUI --> ChatSession
    CLI --> ChatSession
    TUI --> ChatSession

    AgentSystem --> ToolManager
    AgentSystem --> EventBus
    AgentSystem --> ModelHandlers
    AgentPool --> AgentSystem
    AgentConfig --> AgentSystem

    ChatSession --> History
    ChatSession --> EventBus
    ChatSession --> Conversation

    ToolManager --> ToolRegistry
    ToolManager --> Resources
    ToolManager --> CmdProcessors

    EventBus --> EventHandlers
    EventHandlers --> StorageModels

    QueryEngine --> StorageModels
    EnvManager --> Resources
    ModelHandlers --> Prompts
    CmdProcessors --> CmdCompleters

    %% Click Events
    click AgentSystem "https://github.com/phil65/llmling-agent/tree/main/src/llmling_agent/agent/"
    click ChatSession "https://github.com/phil65/llmling-agent/tree/main/src/llmling_agent/chat_session/"
    click CmdProcessors "https://github.com/phil65/llmling-agent/tree/main/src/llmling_agent/commands/"
    click EnvManager "https://github.com/phil65/llmling-agent/tree/main/src/llmling_agent/environment/"
    click ToolManager "https://github.com/phil65/llmling-agent/tree/main/src/llmling_agent/tools/"
    click QueryEngine "https://github.com/phil65/llmling-agent/tree/main/src/llmling_agent/storage/"
    click EventBus "https://github.com/phil65/llmling-agent/tree/main/src/llmling_agent/events/"
    click WebUI "https://github.com/phil65/llmling-agent/tree/main/src/llmling_agent_web/"
    click AgentPool "https://github.com/phil65/llmling-agent/tree/main/src/llmling_agent/delegation/"
    click AgentConfig "https://github.com/phil65/llmling-agent/tree/main/src/llmling_agent/config_resources/"
    click Conversation "https://github.com/phil65/llmling-agent/blob/main/src/llmling_agent/models/messages.py"
    click History "https://github.com/phil65/llmling-agent/tree/main/src/llmling_agent/history/"

    %% Legend
    subgraph Legend
        UI_L["User Interface"]:::ui
        Core_L["Core Services"]:::core
        Infra_L["Infrastructure"]:::infra
        External_L["External Services"]:::external
        Data_L["Data Flow"]:::data
    end
```
