# homayounsrp/function-calling-with-agent architecture

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

- Interactive diagram: https://gitdiagram.com/homayounsrp/function-calling-with-agent
- Repository: https://github.com/homayounsrp/function-calling-with-agent

## Overview

- Main Notebook (main.ipynb): Acts as the orchestrator or entry point, invoking the various parts of the system.
- Components Module:
- Query Planner (Components/query_planner.py): Responsible for analyzing user input/queries and planning the query execution.
- Routing (Components/routing.py): Likely manages the flow of actions depending on the output of the query planner.
- Tools (Components/tools.py): Contains auxiliary functions or utilities that the system uses (possibly for data manipulation, logging, etc.).
- LLM Module:
- LLM Loading (LLM/load_llm.py): Handles the initialization and configuration of the language model (presumably interfacing with OpenAI’s API).

##### Relationships and Data Flow
- The main notebook triggers the overall process.
- The system begins by sending user input or a query to the Query Planner.
- The Query Planner, in turn, formulates a plan and passes its output to the Routing component.
- The Routing part then directs the query to the appropriate Tools if needed or to the Language Model.
- The LLM module (via load_llm.py) is responsible for executing the inference using an OpenAI model.
- The response from the LLM is then sent back through the routing and planning layers (if further processing is required) before being returned to the user.

##### Architectural Patterns and Design Principles
- Modular Design: The separation into Components and LLM modules encourages loose coupling and ease of maintenance.
- Clear Separation of Concerns: Each module has a well-defined area—query planning, routing, utility functions, and LLM handling.
- Pipeline/Orchestration: The flow from query planning to routing to LLM suggests a pipeline-based architecture for processing requests efficiently.

##### Relevant Technologies and Frameworks
- LangChain: Mentioned in the README, indicating that parts of the system might leverage this framework for chaining LLM calls or managing prompt flows.
- OpenAI: The LLM module clearly integrates with an external OpenAI model.
- Python: Given the structure and file naming (notebooks and .py files), all components are implemented in Python.

##### Specific Elements
- Clear Labeling: Each module (main.ipynb, query_planner, routing, tools, load_llm) should be clearly labeled.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Orchestration Layer
    Notebook["main.ipynb"]:::orchestration

    %% Components Module
    subgraph "Components Module"
        QueryPlanner["Query Planner"]:::component
        Router["Routing"]:::component
        Tools["Tools"]:::utility
    end

    %% LLM Module
    subgraph "LLM Module"
        LLMLoad["LLM Loading"]:::llm
    end

    %% Data Flow
    Notebook -->|"triggers"| QueryPlanner
    QueryPlanner -->|"plans"| Router
    Router -->|"routes to"| Tools
    Router -->|"routes to"| LLMLoad
    LLMLoad -->|"returns response"| Router
    Router -->|"sends final response"| Notebook

    %% Click Events
    click Notebook "https://github.com/homayounsrp/function-calling-with-agent/blob/main/main.ipynb"
    click QueryPlanner "https://github.com/homayounsrp/function-calling-with-agent/blob/main/Components/query_planner.py"
    click Router "https://github.com/homayounsrp/function-calling-with-agent/blob/main/Components/routing.py"
    click Tools "https://github.com/homayounsrp/function-calling-with-agent/blob/main/Components/tools.py"
    click LLMLoad "https://github.com/homayounsrp/function-calling-with-agent/blob/main/LLM/load_llm.py"

    %% Styles
    classDef orchestration fill:#ADD8E6,stroke:#333,stroke-width:2px;
    classDef component fill:#90EE90,stroke:#333,stroke-width:2px;
    classDef utility fill:#FFD700,stroke:#333,stroke-width:2px;
    classDef llm fill:#FFB6C1,stroke:#333,stroke-width:2px;
```
