# holmeswww/agentkit architecture

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

- Interactive diagram: https://gitdiagram.com/holmeswww/agentkit
- Repository: https://github.com/holmeswww/agentkit

## Overview

##### Project Type and Purpose
- AgentKit is an open-source Python framework (a library + CLI) for constructing LLM-based “agents” as directed acyclic graphs (DAGs) of nodes.
- It is not a web service or monolith; it is a packaged library (`src/agentkit`), with example clients under `examples/`, documentation under `docs/`, and LLM-API adapters for OpenAI, Anthropic, Ollama, etc.

##### File-Structure Analysis
- Top-level directories:
- `src/agentkit`: core library
- `examples/`: sample applications (crafter, prompt-without-coding CLI)
- `docs/`: Sphinx documentation
- `setup.py`, `requirements.txt`: packaging/config
- Core modules in `src/agentkit`:
- graph.py → Graph class (DAG orchestrator)
- base_node.py, node.py, node_functions.py → Node definitions
- compose_prompt.py → Pre-processing (Compose)
- after_query.py → Post-processing (After-Query)
- llm_api/ → Adapter layer for multiple LLM providers
- utils.py, exceptions.py → supporting utilities

##### README Insights
- Architecture: each BaseNode runs three phases—Compose → LLM query → AfterQuery—and nodes are linked by `graph.add_edge` to form a DAG.
- Dynamic graph modification: nodes/edges can be added/removed at runtime based on LLM output.
- Usage: Graph.evaluate() triggers ordered evaluation, tracks token usage per node.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Core Library
    subgraph "Core Library"
        direction TB
        Graph["Graph Manager (Graph)"]:::core
        Token["Token Usage Tracker"]:::core
        subgraph "Node Component"
            direction TB
            Compose["ComposePrompt"]:::core
            BaseNode["BaseNode"]:::core
            NodeFns["NodeFunctions"]:::core
            AfterQ["AfterQuery"]:::core
        end
        Utils["Utilities"]:::core
        Excs["Exceptions"]:::core
    end

    %% Adapter Layer
    subgraph "Adapter Layer"
        direction TB
        AdapterDir["llm_api (directory)"]:::adapter
        BaseAdapter["Base Adapter"]:::adapter
        OpenAIAdapter["OpenAIAdapter"]:::adapter
        ClaudeAdapter["ClaudeAdapter"]:::adapter
        OllamaAdapter["OllamaAdapter"]:::adapter
        AdapterUtils["Adapter Utils"]:::adapter
    end

    %% External LLM Services
    subgraph "External LLM Services"
        direction TB
        OpenAICloud["OpenAI"]:::external
        AnthropicCloud["Anthropic"]:::external
        OllamaCloud["Ollama"]:::external
    end

    %% Examples & Clients
    subgraph "Examples & Clients"
        direction TB
        Crafter["Crafter Example"]:::example
        CLI["Prompt-Without-Coding CLI"]:::example
    end

    %% Documentation
    Docs["Documentation (Sphinx)"]:::docs

    %% Connections
    Graph --> Token
    Graph -->|orchestrates| Compose
    Compose -->|"pre-process"| AdapterDir
    AdapterDir --> BaseAdapter
    AdapterDir --> OpenAIAdapter
    AdapterDir --> ClaudeAdapter
    AdapterDir --> OllamaAdapter
    AdapterDir --> AdapterUtils

    OpenAIAdapter --> OpenAICloud
    ClaudeAdapter --> AnthropicCloud
    OllamaAdapter --> OllamaCloud

    OpenAICloud --> OpenAIAdapter
    AnthropicCloud --> ClaudeAdapter
    OllamaCloud --> OllamaAdapter

    OpenAIAdapter --> AfterQ
    ClaudeAdapter --> AfterQ
    OllamaAdapter --> AfterQ

    AfterQ -->|"collect results"| Graph
    AfterQ -.->|"dynamic modification"| Graph

    Graph -->|returns output| Crafter
    Graph -->|returns output| CLI
    Graph -->|links to docs| Docs

    %% Click Events
    click Graph "https://github.com/holmeswww/agentkit/blob/main/src/agentkit/graph.py"
    click Compose "https://github.com/holmeswww/agentkit/blob/main/src/agentkit/compose_prompt.py"
    click AfterQ "https://github.com/holmeswww/agentkit/blob/main/src/agentkit/after_query.py"
    click BaseNode "https://github.com/holmeswww/agentkit/blob/main/src/agentkit/base_node.py"
    click NodeFns "https://github.com/holmeswww/agentkit/blob/main/src/agentkit/node_functions.py"
    click Utils "https://github.com/holmeswww/agentkit/blob/main/src/agentkit/utils.py"
    click Excs "https://github.com/holmeswww/agentkit/blob/main/src/agentkit/exceptions.py"
    click AdapterDir "https://github.com/holmeswww/agentkit/tree/main/src/agentkit/llm_api/"
    click BaseAdapter "https://github.com/holmeswww/agentkit/blob/main/src/agentkit/llm_api/base.py"
    click OpenAIAdapter "https://github.com/holmeswww/agentkit/blob/main/src/agentkit/llm_api/GPT.py"
    click ClaudeAdapter "https://github.com/holmeswww/agentkit/blob/main/src/agentkit/llm_api/claude.py"
    click OllamaAdapter "https://github.com/holmeswww/agentkit/blob/main/src/agentkit/llm_api/ollama.py"
    click AdapterUtils "https://github.com/holmeswww/agentkit/blob/main/src/agentkit/llm_api/utils.py"
    click Crafter "https://github.com/holmeswww/agentkit/tree/main/examples/crafter/"
    click CLI "https://github.com/holmeswww/agentkit/tree/main/examples/prompt_without_coding/"
    click Docs "https://github.com/holmeswww/agentkit/tree/main/docs/"

    %% Styles
    classDef core fill:#e0f7fa,stroke:#0288d1,color:#000
    classDef adapter fill:#ede7f6,stroke:#512da8,color:#000
    classDef external fill:#e8f5e9,stroke:#2e7d32,color:#000
    classDef example fill:#fff3e0,stroke:#ef6c00,color:#000
    classDef docs fill:#eceff1,stroke:#546e7a,color:#000
```
