# himanshu00singhal/agent architecture

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

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

## Overview

##### Project Type and Purpose
- This is a lightweight AI‐agent orchestration service with both an HTTP API (FastAPI) and an optional Streamlit UI.
- Purpose: accept POST requests at /process/, route tasks (“internet”, “query”, “summarize”) through a manager to specialized agent modules, and return AI‐driven results.

##### File‐Structure Analysis
- Top‐level:
- .env – environment variables (e.g., API keys)
- Dockerfile – containerizes the FastAPI app
- requirements.txt – Python dependencies (FastAPI, Uvicorn, python‐dotenv, Streamlit, etc.)
- app.py – FastAPI entrypoint defining /process/ endpoint and connecting to manager
- ui.py – Streamlit app for an interactive UI layer
- agents/ – core business logic modules:
– agent_1.py, agent_2.py, agent_3.py: implement “internet”, “query”, “summarize” behaviors
– manager.py: orchestrates which agent to invoke based on task_type

##### README Insights
- The service runs on port 8000, exposes Swagger UI at /docs.
- Can be consumed directly via Swagger or via the Streamlit front‐end.
- Uses Docker for deployment and .env for configuration.

a. Main Components
- Clients:
- Swagger UI (FastAPI auto‐docs)
- Streamlit UI (ui.py)
- API Backend: FastAPI server (app.py)
- Orchestration Layer: AgentManager (agents/manager.py)
- Agent Modules: agents/agent_1.py, agent_2.py, agent_3.py
- External Services:
- LLM API (OpenAI or similar)
- (For “internet” tasks) Web search API or crawling service
- Infrastructure: Docker container, .env config

b. Relationships & Data Flow
1. Client → HTTP POST /process/ (input_text, task_type, document_text)
2. FastAPI Controller (app.py) → AgentManager
3. AgentManager → selects agent_X.py based on task_type
4. Agent Module → calls external LLM or web‐search API
5. AgentModule returns response → AgentManager → FastAPI → Client

c. Architectural Patterns & Principles
- Single responsibility: each agent file handles one task type.
- Orchestration vs. execution: manager decouples routing logic from agent logic.
- 12-factor app: config via .env, containerized.

d. Key Technologies & Frameworks
- FastAPI + Uvicorn
- Python‐dotenv for config
- Streamlit for UI
- Docker for packaging
- External AI APIs (e.g., OpenAI)

##### Detailed Capture of Architecture
- Docker as an outer container boundary.
- .env feeding into FastAPI and Manager (config injection).
- Agent with its task_type (“internet”, “query”, “summarize”).
- Two UIs separately, indicating they both consume the same API endpoint.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Clients / Presentation Layer
    subgraph "Clients / Presentation Layer"
        Swagger["Swagger UI"]:::ui
        Streamlit["Streamlit UI"]:::ui
    end

    %% Backend Layer
    subgraph "Backend Layer"
        API["FastAPI HTTP API"]:::backend
    end

    %% Orchestration Layer
    subgraph "Orchestration Layer"
        Manager["AgentManager"]:::backend
    end

    %% Agent Modules
    subgraph "Agent Modules"
        Internet["Internet Agent"]:::agent
        Query["Query Agent"]:::agent
        Summarize["Summarize Agent"]:::agent
    end

    %% External Services
    subgraph "External Services"
        WebSearch["Web Search API"]:::external
        LLM["LLM API"]:::external
    end

    %% Infrastructure
    Env[".env"]:::infra
    Dockerfile["Dockerfile"]:::infra
    Requirements["requirements.txt"]:::infra
    Readme["README.md"]:::infra

    %% Data Flows
    Swagger -->|HTTP GET| API
    Streamlit -->|HTTP POST /process/| API
    API -->|"route request"| Manager
    Manager -->|"task_type=internet"| Internet
    Manager -->|"task_type=query"| Query
    Manager -->|"task_type=summarize"| Summarize
    Internet -->|REST API| WebSearch
    Internet -->|REST API| LLM
    Query -->|REST API| LLM
    Summarize -->|REST API| LLM
    Internet -->|response| Manager
    Query -->|response| Manager
    Summarize -->|response| Manager
    Manager -->|result| API
    API -->|response| Streamlit
    API -->|response| Swagger

    %% Config Injection
    Env --> API
    Env --> Manager

    %% Click Events
    click API "https://github.com/himanshu00singhal/agent/blob/main/app.py"
    click Streamlit "https://github.com/himanshu00singhal/agent/blob/main/ui.py"
    click Manager "https://github.com/himanshu00singhal/agent/blob/main/agents/manager.py"
    click Internet "https://github.com/himanshu00singhal/agent/blob/main/agents/agent_1.py"
    click Query "https://github.com/himanshu00singhal/agent/blob/main/agents/agent_2.py"
    click Summarize "https://github.com/himanshu00singhal/agent/blob/main/agents/agent_3.py"
    click Env "https://github.com/himanshu00singhal/agent/blob/main/.env"
    click Dockerfile "https://github.com/himanshu00singhal/agent/tree/main/Dockerfile"
    click Requirements "https://github.com/himanshu00singhal/agent/blob/main/requirements.txt"
    click Readme "https://github.com/himanshu00singhal/agent/blob/main/README.md"

    %% Styles
    classDef ui fill:#ADD8E6,stroke:#000,stroke-width:1px
    classDef backend fill:#90EE90,stroke:#000,stroke-width:1px
    classDef agent fill:#FFA500,stroke:#000,stroke-width:1px
    classDef external fill:#D8BFD8,stroke:#000,stroke-width:1px
    classDef infra fill:#D3D3D3,stroke:#000,stroke-width:1px
```
