# binome-dev/graphite architecture

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

- Interactive diagram: https://gitdiagram.com/binome-dev/graphite
- Repository: https://github.com/binome-dev/graphite

## Overview

Based on our analysis of the provided file tree and README documentation, Graphite is an event-driven framework specifically designed to build AI agent workflows with a modular, composable architecture. The system combines separate layers – Assistants, Nodes, and Tools – with a workflow orchestration mechanism built on a Pub/Sub eventing pattern and event sourcing principles (to provide observability, idempotency, auditability, and restorability).

##### Main Components
- Assistants: These are the high-level orchestrators of AI workflows. They handle user interactions, coordinate multiple nodes, and produce final outputs.
- Nodes: Represent the discrete steps or reasoning components in a workflow. They include LLM nodes executing model calls, LLMFunctionCall nodes that integrate tool invocation, and other helper nodes.
- Tools: These are the execution units (functions) that process or transform data – for example, function tools like TavilyTool or registration API calls.
- Workflow Orchestration: The Pub/Sub messaging system is central (topics such as agent_input_topic, agent_output_topic, human_request_topic, etc.) along with the persistent event store that logs every event to ensure auditability and tracing.

##### Relationships and Data Flow
- Assistants listen to these topics, then dispatch and coordinate across nodes that run LLM functions and function calls.
- Nodes may publish events to topics or trigger tool execution. Tools process the event data and return results to specific output topics (e.g., function_result_topic, agent_output_topic).
- How the event-driven architecture facilitates interactions among components through event sourcing and pub/sub channels.

##### Architectural Patterns and Principles
- Command Pattern: The use of commands (e.g., function calling commands, LLM response commands) clearly separates the issuers of requests (nodes or assistants) from the executors (tools).
- Modular and Composable Layers: Illustrate the clear separation between Assistants, Nodes, and Tools.
- Observability & Idempotency: Incorporate elements indicating logging, tracing, and the event store which captures every state change.

##### Relevant Technologies/Frameworks
- Python (evidenced by the directory structure and pyproject.toml).
- OpenTelemetry (for tracing) and Arize’s OpenInference (observability).
- Pub/Sub infrastructure and the internal event store for managing events.
- The modular “grafi” code base that houses definitions for assistants, nodes, common models, decorators, and workflows.

- Clear labels:
- Data (or event) flow between user input, publishing to topics, processing by nodes, tool execution, and final assistant output.
- Annotations for Architectural Patterns:
- Integration Points:
- External dependencies (e.g., external LLM APIs like OpenAI, or third-party tools like Tavily) and observability tools (Phoenix, OpenTelemetry).

## Diagram (Mermaid)

```mermaid
graph TD
    %% User Input
    UI("User Input"):::user

    %% Message Broker Subgraph
    subgraph "Message Broker"
        AIT("agent_input_topic"):::pubsub
        HRT("human_request_topic"):::pubsub
        AOT("agent_output_topic"):::pubsub
    end

    %% Assistants Layer
    subgraph "Assistants Layer"
        AS("Assistant"):::assistant
    end

    %% Workflow Orchestration
    WO("Workflow Orchestration"):::orchestration

    %% Nodes Layer
    subgraph "Nodes Layer"
        LN("LLM Node"):::node
        LFC("LLM Function Call Node"):::node
    end

    %% Tools Layer
    subgraph "Tools Layer"
        FT("Function Tool"):::tool
        ACT("Agent Calling Tool"):::tool
        LT_OpenAI("LLM Tool - OpenAI"):::tool
        LT_Ollama("LLM Tool - Ollama"):::tool
    end

    %% Infrastructure Components
    ES("Event Store"):::infrastructure
    INST("Tracing/Observability"):::infrastructure

    %% Connections - Vertical Flow
    UI -->|"publishes"| AIT
    UI -->|"publishes"| HRT

    AIT -->|"triggers"| AS
    HRT -->|"triggers"| AS

    AS -->|"delegates"| WO
    WO -->|"orchestrates"| LN
    WO -->|"orchestrates"| LFC

    LN -->|"invokes"| FT
    LFC -->|"invokes"| ACT

    FT -->|"returns_result_to"| AOT
    ACT -->|"returns_result_to"| AOT

    %% Logging & Tracing Connections (Event Sourcing)
    AS ---|"logs"| ES
    LN ---|"logs"| ES
    LFC ---|"logs"| ES
    FT ---|"logs"| ES
    ACT ---|"logs"| ES
    WO ---|"logs"| ES

    AS ---|"traces"| INST
    LN ---|"traces"| INST
    LFC ---|"traces"| INST
    FT ---|"traces"| INST
    ACT ---|"traces"| INST
    WO ---|"traces"| INST

    %% Click Events for Component Mapping
    click AS "https://github.com/binome-dev/graphite/blob/main/grafi/assistants/assistant.py"
    click AS "https://github.com/binome-dev/graphite/blob/main/grafi/assistants/assistant_base.py"
    click AS "https://github.com/binome-dev/graphite/blob/main/grafi/assistants/stream_assistant.py"

    click LN "https://github.com/binome-dev/graphite/blob/main/grafi/nodes/node.py"
    click LN "https://github.com/binome-dev/graphite/blob/main/grafi/nodes/impl/llm_node.py"

    click LFC "https://github.com/binome-dev/graphite/blob/main/grafi/nodes/impl/llm_function_call_node.py"

    click FT "https://github.com/binome-dev/graphite/blob/main/grafi/tools/tool.py"
    click FT "https://github.com/binome-dev/graphite/blob/main/grafi/tools/functions/function_tool.py"

    click ACT "https://github.com/binome-dev/graphite/blob/main/grafi/tools/functions/impl/agent_calling_tool.py"

    click LT_OpenAI "https://github.com/binome-dev/graphite/blob/main/grafi/tools/llms/llm.py"
    click LT_OpenAI "https://github.com/binome-dev/graphite/blob/main/grafi/tools/llms/impl/openai_tool.py"

    click LT_Ollama "https://github.com/binome-dev/graphite/blob/main/grafi/tools/llms/impl/ollama_tool.py"

    click WO "https://github.com/binome-dev/graphite/blob/main/grafi/workflows/workflow.py"
    click WO "https://github.com/binome-dev/graphite/blob/main/grafi/workflows/impl/event_driven_workflow.py"

    click AIT "https://github.com/binome-dev/graphite/blob/main/grafi/common/topics/topic.py"
    click AIT "https://github.com/binome-dev/graphite/blob/main/grafi/common/topics/topic_base.py"

    click HRT "https://github.com/binome-dev/graphite/blob/main/grafi/common/topics/human_request_topic.py"

    click AOT "https://github.com/binome-dev/graphite/blob/main/grafi/common/topics/output_topic.py"

    click ES "https://github.com/binome-dev/graphite/blob/main/grafi/common/event_stores/event_store.py"
    click ES "https://github.com/binome-dev/graphite/blob/main/grafi/common/event_stores/event_store_in_memory.py"

    click INST "https://github.com/binome-dev/graphite/blob/main/grafi/common/instrumentations/tracing.py"

    %% Style Definitions
    classDef user fill:#ffcc00,stroke:#333,stroke-width:2px;
    classDef pubsub fill:#d9ead3,stroke:#333,stroke-width:2px;
    classDef assistant fill:#c9daf8,stroke:#333,stroke-width:2px;
    classDef orchestration fill:#f9cb9c,stroke:#333,stroke-width:2px;
    classDef node fill:#d0e0e3,stroke:#333,stroke-width:2px;
    classDef tool fill:#ffe599,stroke:#333,stroke-width:2px;
    classDef infrastructure fill:#ead1dc,stroke:#333,stroke-width:2px;
```
