# simbianai/taskgen architecture

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

- Interactive diagram: https://gitdiagram.com/simbianai/taskgen
- Repository: https://github.com/simbianai/taskgen

## Overview

##### Project type and purpose
- Type: A Python library/open-source framework for creating “task-based” agents that orchestrate LLM calls, external functions, memory, shared variables, and global context.
- Purpose: To let users split complex tasks into subtasks, run them synchronously or in parallel, plug-in external or LLM-based functions, and maintain state across subtasks and sessions.

##### File structure
- Core package:
– taskgen/agent.py, base.py, base_async.py → Agent and AsyncAgent classes (entry points)
– taskgen/function.py → Function wrappers (sync & async)
– taskgen/memory.py → Memory module
– taskgen/utils.py, wrapper.py, ranker.py → Helpers, RAG over function space
- Configuration & packaging: setup.py, pyproject.toml, requirements.txt, build.sh
- Tutorials & docs: Jupyter notebooks, Paper/, resources/ → background, research, sample code
- contrib/community → Plug-in agents & functions (“HelpfulAssistant”, “MathExpert”)

##### Key insights from README
- Agents orchestrate subtasks using StrictJSON prompts → JSON format + type checking
- Support for:
– Sync/async task execution
– LLM-based functions vs. external Python functions
– Shared variables (multi-modality)
– Global context (persistent state)
– Retrieval-augmented generation over function space
– Community plugin upload/download

##### Main components
a. User application (scripts/Notebook)
b. TaskGen Library
- Agent Core (Agent / AsyncAgent)
- Task Splitter & Scheduler
- Function Manager
– LLM Functions (StrictJSON calls)
– External Functions (Python sync/async)
- Memory Store (subtasks_completed buffer)
- Shared Variables store
- Global Context layer
- RAG Retriever/Ranker
c. External services
- LLM Provider (OpenAI / other LLMs)
- Optional storage or community registry

##### Relationships & data flows
– The User App instantiates Agent, configures LLM & functions → calls run()
– Agent Core splits the main task → passes subtasks to Scheduler
– Scheduler dispatches each subtask either:
- to LLM Functions → via StrictJSON → to LLM Service → parse JSON → back to Agent
- or to External Functions → local Python calls
– Outputs feed into Memory Store & Shared Variables
– Global Context is prepended to prompts on each LLM call
– RAG Retriever can look up past functions/subtasks to augment prompts
– Final reply_user() assembles combined output back to User App

##### Architectural patterns & principles
- Modular layering: clear separation of Agent core, Function layer, and external services
- Plugin-friendly: external functions and community modules dynamically registered
- Async pattern: Agent and Function Manager support parallel tasks
- State management: explicit Memory and Shared Variables vs ephemeral local variables
- Prompt design: strict JSON enforcement for predictable parsing

##### Relevant technologies/frameworks
- Python 3.x, AsyncIO
- StrictJSON parser (core dependency)
- OpenAI/python-based LLM clients (synchronous & asynchronous)
- CI via GitHub Actions (.github/workflows/build.yaml)
- Packaging: setuptools (setup.py), Poetry/pyproject.toml

##### Detail level
– Include every “taskgen/” submodule at a high level (don’t drown in file-by-file detail; group related modules)
– Explicitly show the in-memory stores: subtasks_completed, shared_variables, global_context
– Call out the RAG module as a specialized retriever within the Function Manager

## Diagram (Mermaid)

```mermaid
flowchart TD
  %% User Layer
  subgraph "User Application" 
    direction TB
    TA0["Tutorial 0 - StrictJSON"]:::user
    TA1["Tutorial 1 - Agent"]:::user
    TA2["Tutorial 2 - Shared Variables & Global Context"]:::user
    TA3["Tutorial 3 - Memory"]:::user
    TA4["Tutorial 4 - Hierarchical Agents"]:::user
    TA5["Tutorial 5 - CodeGen & External Function"]:::user
    TA6["Tutorial 6 - Conversation Class"]:::user
    TA7["Maze Navigator (Paper)"]:::user
  end

  %% Core Framework
  subgraph "TaskGen Library" 
    direction TB
    subgraph "Agent Core" 
      direction TB
      AC1["Agent"]:::core
      AC2["Base"]:::core
      AC3["AsyncAgent"]:::core
    end

    AC1 --> AC2
    AC1 --> AC3

    TS["Task Splitter & Scheduler"]:::core
    AC3 -->|splits tasks| TS

    subgraph "Function Manager" 
      direction TB
      FM1["Function Wrappers"]:::core
      FM2["Wrapper"]:::core
      FM3["Utils"]:::core
      subgraph "RAG Retriever/Ranker"
        direction TB
        RR["Ranker"]:::core
      end
    end

    TS --> FM1
    TS --> FM2
    TS --> FM3
    FM3 --> RR
  end

  %% External Functions
  subgraph "Function Execution Paths"
    direction TB
    LLMF["LLM Functions (StrictJSON)"]:::core
    EF["External Functions"]:::user
  end

  FM1 -->|invoke| LLMF
  FM2 -->|invoke| EF

  LLMF -->|JSON calls| LLM["LLM Provider"]:::external
  EF -->|Python calls| EF

  %% State Stores
  subgraph "State Management"
    direction TB
    MS["Memory Store"]:::core
    SV["Shared Variables"]:::core
    GC["Global Context"]:::core
  end

  LLM --> MS
  EF --> MS
  LLM --> SV
  EF --> SV
  SV --> GC
  RR -->|augments prompts| GC

  %% Results back to Agent and User
  GC --> AC1
  MS --> AC1
  SV --> AC1
  AC1 -->|"reply_user()"| TA0

  %% Plugin Registry
  subgraph "Community Plugins"
    direction TB
    P1["HelpfulAssistant"]:::external
    P2["MathExpert"]:::external
  end
  P1 --> FM1
  P2 --> FM2

  %% Configuration & Packaging
  subgraph "Config & Packaging"
    direction TB
    CFG1["setup.py"]:::core
    CFG2["pyproject.toml"]:::core
    CFG3["requirements.txt"]:::core
    CFG4["build.sh"]:::core
    CFG5[".github Actions"]:::core
  end

  %% Connections from User App
  TA0 --> AC1
  TA1 --> AC1
  TA2 --> AC1
  TA3 --> AC1
  TA4 --> AC1
  TA5 --> AC1
  TA6 --> AC1
  TA7 --> AC1

  %% Click Events
  click TA0 "https://github.com/simbianai/taskgen/blob/main/Paper/maze_navigator/Maze Navigator.ipynb"
  click TA1 "https://github.com/simbianai/taskgen/blob/main/Tutorial 1 - Agent.ipynb"
  click TA2 "https://github.com/simbianai/taskgen/blob/main/Tutorial 2 - Shared Variables and Global Context.ipynb"
  click TA3 "https://github.com/simbianai/taskgen/blob/main/Tutorial 3 - Memory.ipynb"
  click TA4 "https://github.com/simbianai/taskgen/blob/main/Tutorial 4 - Hierarchical Agents.ipynb"
  click TA5 "https://github.com/simbianai/taskgen/blob/main/Tutorial 5 - CodeGen and External Function Interfacing.ipynb"
  click TA6 "https://github.com/simbianai/taskgen/blob/main/Tutorial 6 - Conversation Class.ipynb"
  click AC1 "https://github.com/simbianai/taskgen/blob/main/taskgen/agent.py"
  click AC2 "https://github.com/simbianai/taskgen/blob/main/taskgen/base.py"
  click AC3 "https://github.com/simbianai/taskgen/blob/main/taskgen/base_async.py"
  click FM1 "https://github.com/simbianai/taskgen/blob/main/taskgen/function.py"
  click FM2 "https://github.com/simbianai/taskgen/blob/main/taskgen/wrapper.py"
  click FM3 "https://github.com/simbianai/taskgen/blob/main/taskgen/utils.py"
  click MS "https://github.com/simbianai/taskgen/blob/main/taskgen/memory.py"
  click SV "https://github.com/simbianai/taskgen/blob/main/taskgen/utils.py"
  click RR "https://github.com/simbianai/taskgen/blob/main/taskgen/ranker.py"
  click P1 "https://github.com/simbianai/taskgen/blob/main/contrib/community/HelpfulAssistant/main.py"
  click P2 "https://github.com/simbianai/taskgen/blob/main/contrib/community/MathExpert/main.py"
  click CFG1 "https://github.com/simbianai/taskgen/blob/main/setup.py"
  click CFG2 "https://github.com/simbianai/taskgen/blob/main/pyproject.toml"
  click CFG3 "https://github.com/simbianai/taskgen/blob/main/requirements.txt"
  click CFG4 "https://github.com/simbianai/taskgen/blob/main/build.sh"
  click CFG5 "https://github.com/simbianai/taskgen/blob/main/.github/workflows/build.yaml"

  %% Styles
  classDef core fill:#D0E3FF,stroke:#4A6FA5,color:#000;
  classDef user fill:#E2F7E1,stroke:#3C923A,color:#000;
  classDef external fill:#FFE4B5,stroke:#D38B00,color:#000;
```
