# salesforceairesearch/agentlite architecture

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

- Interactive diagram: https://gitdiagram.com/salesforceairesearch/agentlite
- Repository: https://github.com/salesforceairesearch/agentlite

## Overview

##### Project type and purpose
- AgentLite is a Python research-oriented library for building LLM-based task-oriented agents and multi-agent systems.  It provides core abstractions (Actions, Prompts, Agents, Memory, Logging) and an orchestrator (ManagerAgent) plus optional UI, example scripts, benchmarks and tutorials.

##### File structure
- Top-level directories:
- agentlite/        ← core library
– actions/        ← BaseAction, custom tool wrappers
– agent_prompts/  ← BasePrompt, prompt utilities
– agents/         ← BaseAgent, ManagerAgent, agent utilities
– commons/        ← TaskPackage, AgentAct, shared data types
– llm/            ← LLMConfig, agent_llms (factory for LLM backends)
– memory/         ← AgentSTMemory, memory utilities
– logging/        ← base logger, terminal and streamlit loggers
– utils.py        ← core helper functions
- app/              ← Streamlit UI demo (Homepage.py + pages)
- benchmark/        ← evaluation scripts (hotpotqa, tool-operation, tool, webshop)
- example/          ← standalone agent scripts and notebooks
- docs/, tutorials/ ← Sphinx docs, Jupyter tutorials
- tests/            ← unit tests
- setup.py, requirements.txt

##### Architecture overview from README
- Core library exposes a clear plugin API: define Actions → wrap in BaseAgent → orchestrate with ManagerAgent.
- LLM backends are pluggable via LLMConfig and get_llm_backend.
- State can be persisted via AgentSTMemory.
- Logging sinks to console or Streamlit.
- UI and benchmarks sit on top of the core.

##### Main components
a. Core Library (agentlite)
- Actions module
- Agent Prompts module
- Agents module (BaseAgent, ManagerAgent)
- Commons (TaskPackage, AgentAct)
- LLM layer (LLMConfig, get_llm_backend)
- Memory layer (AgentSTMemory)
- Logging layer (base, terminal, streamlit)
- Utils
b. External Services
- LLM APIs (OpenAI, custom backends)
- Third-party tools invoked by Actions (e.g., Wikipedia API)
c. Orchestrator
- ManagerAgent coordinates TeamAgents
d. UI Layer (Streamlit app)
e. Benchmarks & Examples
- Benchmark runners call ManagerAgent or Agents
- Example scripts demonstrate usage

##### Relationships and data flow
- TaskPackage (instruction + metadata) flows from UI / CLI / benchmark → ManagerAgent or BaseAgent.
- Agent uses:
1. LLM layer to generate next action or response using AgentPrompts.
2. Actions to call external tools.
3. Memory to read/write context.
4. Commons to package AgentAct results into TaskPackage.
5. Logging module to emit logs (to console or UI).
- ManagerAgent routes TaskPackage to multiple BaseAgents, merges their outputs.
- UI layer invokes ManagerAgent / BaseAgent, displays results, and logs via streamlit_logger.

##### Architectural patterns & design principles
- Plugin/Strategy pattern: Actions and Prompts are interchangeable plugins.
- Orchestrator pattern: ManagerAgent coordinates multiple agents in sequence or parallel.
- Separation of concerns: distinct layers for LLM, Actions, Memory, Logging.
- Lightweight core: minimal coupling, easy extension.
- Data flow is explicit via TaskPackage and AgentAct structures.

##### Technologies & frameworks
- Python 3.9+
- LangChain (for tool wrappers in examples)
- OpenAI (or any LLM via pluggable backends)
- Streamlit (UI demo)
- Sphinx (docs)
- pytest (tests)

##### Elements
- Clear, human-readable labels for each module.
– Rectangles for modules/packages
– Clouds for external services (LLM API, Wikipedia).

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "UI Layer"
        UI["Streamlit App"]:::ui
    end

    subgraph "Benchmark & Examples"
        BM["Benchmark Runners"]:::driver
        EX["Example Scripts"]:::driver
    end

    subgraph "Core Library (agentlite)"
        subgraph "Actions"
            A1["BaseAction"]:::core
            A2["InnerActions"]:::core
        end
        subgraph "Agent Prompts"
            P1["BasePrompt"]:::core
            P2["prompt_utils"]:::core
        end
        subgraph "Agents"
            AG1["BaseAgent"]:::core
            AG2["ManagerAgent"]:::core
            AG3["ABCAgent"]:::core
            AG4["agent_utils"]:::core
        end
        subgraph "Commons"
            C1["TaskPackage"]:::core
            C2["AgentAct"]:::core
        end
        subgraph "LLM Layer"
            L1["LLMConfig"]:::core
            L2["agent_llms"]:::core
        end
        subgraph "Memory"
            M1["AgentSTMemory"]:::core
            M2["memory_utils"]:::core
        end
        subgraph "Logging"
            Lg1["base"]:::core
            Lg2["terminal_logger"]:::core
            Lg3["streamlit_logger"]:::core
            Lg4["utils"]:::core
        end
        U["utils.py"]:::core
    end

    subgraph "External Services"
        ES1["LLM APIs (OpenAI, custom)"]:::external
        ES2["Third-party Tools (Wikipedia API)"]:::external
    end

    UI -->|"TaskPackage"| AG2
    BM -->|"TaskPackage"| AG2
    BM -->|"TaskPackage"| AG1
    EX -->|"TaskPackage"| AG1

    AG2 -->|"orchestrate"| AG1
    AG1 -->|"uses prompts"| P1
    AG1 -->|"uses prompts"| P2
    AG1 -->|"generate with"| L1
    AG1 -->|"generate with"| L2
    AG1 -->|"calls actions"| A1
    A1 -->|"invokes"| ES2
    AG1 -->|"read/write"| M1
    AG1 -->|"logs"| Lg1
    Lg1 -->|"to console"| Lg2
    Lg1 -->|"to UI"| Lg3
    AG1 -->|"outputs"| C2
    C2 -->|"wraps"| C1
    AG2 -->|"collects outputs"| C2
    C2 -->|"returns results"| UI

    ES1 -->|"LLM backend"| L1

    classDef core fill:#ADD8E6,stroke:#000;
    classDef external fill:#98FB98,stroke:#000;
    classDef ui fill:#FFA500,stroke:#000;
    classDef driver fill:#D3D3D3,stroke:#000;

    click A1 "https://github.com/salesforceairesearch/agentlite/blob/main/agentlite/actions/BaseAction.py"
    click A2 "https://github.com/salesforceairesearch/agentlite/blob/main/agentlite/actions/InnerActions.py"
    click P1 "https://github.com/salesforceairesearch/agentlite/blob/main/agentlite/agent_prompts/BasePrompt.py"
    click P2 "https://github.com/salesforceairesearch/agentlite/blob/main/agentlite/agent_prompts/prompt_utils.py"
    click AG1 "https://github.com/salesforceairesearch/agentlite/blob/main/agentlite/agents/BaseAgent.py"
    click AG2 "https://github.com/salesforceairesearch/agentlite/blob/main/agentlite/agents/ManagerAgent.py"
    click AG3 "https://github.com/salesforceairesearch/agentlite/blob/main/agentlite/agents/ABCAgent.py"
    click AG4 "https://github.com/salesforceairesearch/agentlite/blob/main/agentlite/agents/agent_utils.py"
    click C1 "https://github.com/salesforceairesearch/agentlite/blob/main/agentlite/commons/TaskPackage.py"
    click C2 "https://github.com/salesforceairesearch/agentlite/blob/main/agentlite/commons/AgentAct.py"
    click L1 "https://github.com/salesforceairesearch/agentlite/blob/main/agentlite/llm/LLMConfig.py"
    click L2 "https://github.com/salesforceairesearch/agentlite/blob/main/agentlite/llm/agent_llms.py"
    click M1 "https://github.com/salesforceairesearch/agentlite/blob/main/agentlite/memory/AgentSTMemory.py"
    click M2 "https://github.com/salesforceairesearch/agentlite/blob/main/agentlite/memory/memory_utils.py"
    click Lg1 "https://github.com/salesforceairesearch/agentlite/blob/main/agentlite/logging/base.py"
    click Lg2 "https://github.com/salesforceairesearch/agentlite/blob/main/agentlite/logging/terminal_logger.py"
    click Lg3 "https://github.com/salesforceairesearch/agentlite/blob/main/agentlite/logging/streamlit_logger.py"
    click Lg4 "https://github.com/salesforceairesearch/agentlite/blob/main/agentlite/logging/utils.py"
    click U "https://github.com/salesforceairesearch/agentlite/blob/main/agentlite/utils.py"
    click UI "https://github.com/salesforceairesearch/agentlite/blob/main/app/Homepage.py"
    click BM "https://github.com/salesforceairesearch/agentlite/tree/main/benchmark/"
    click EX "https://github.com/salesforceairesearch/agentlite/tree/main/example/"
```
