# git-devisha/crewai architecture

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

- Interactive diagram: https://gitdiagram.com/git-devisha/crewai
- Repository: https://github.com/git-devisha/crewai

## Overview

##### Main Components
- • CLI & Project Bootstrap: Represented by the src/crewai/cli and the templates folders. This part manages the creation of new projects, configuration files (agents.yaml, tasks.yaml, etc.), and provides command-line commands for interacting with the system.
- • Core Framework Modules:
◦ Agents & Agent Builders: Found in src/crewai/agents and its submodules, including agent_builder and cache. These modules encapsulate the building, configuration, and execution of individual agents.
◦ Crews: The abstraction that groups agents together (see src/crewai/crews and the crew.py files). This module orchestrates task delegation, parallel/sequential execution, and overall crew coordination.
◦ Flows: Located in src/crewai/flow, handling the event-driven orchestration. This module defines how multiple tasks and agent executions interact in an event-based, sequential, or hierarchical process.
- • Memory Management: Multiple modules under src/crewai/memory (short‑term, long‑term, entity etc.) show how state and context are captured, stored, and recalled across tasks.
- • Knowledge & Knowledge Sources: Under src/crewai/knowledge, representing how external and internal data are processed (via different file formats like JSON, CSV, PDF) and embedded.
- • Tools & LLM Integrations: In src/crewai/tools and src/crewai/llms, these components encapsulate tool handling and connection to external language models (e.g., OpenAI API, or local alternatives) to let agents query and process language data.
- • Utilities, Logging, and Exception Handling: Diverse helper modules in src/crewai/utilities, events, and security provide support for error handling, logging, configuration management, and event bus communication (which is pivotal for flows and triggering tasks).
- • Telemetry & Security: Modules in src/crewai/telemetry and src/crewai/security manage data collection (with privacy in mind) as described in the README and ensure secure operation.
- • Tests: The tests directory shows unit, integration, and cassette-based tests, validating the correct behavior of both core and extended functionalities.

##### Relationships and Interactions
◦ The CLI layer (and project templates) initiate and bootstrap Crews/Flows.
◦ The Crew component orchestrates multiple agents by linking their task definitions (from agents.yaml and tasks.yaml) to the specific agent implementations.
◦ Agents interact with Memory, Knowledge, Tools, and External LLM APIs to process input and produce outputs.
◦ The Flow module uses event-listeners and decorators to chain task executions and introduce conditional branching (for example, based on telemetry or output evaluation).
◦ Telemetry/Security modules “listen” for events and capture logs, while utilities facilitate error handling and event propagation.
- That configuration (pyproject.toml, YAML config files, and environment variables from .env) is a core dependency across modules.

##### Architectural Patterns
- The design follows modular, layered architecture where independent components (agents, crews, flows) communicate via well-defined interfaces.
- Uses decorators (@agent, @task, @crew, @start, @listen, @router) to clearly separate concerns and control execution logic.
- There’s heavy reliance on event-driven and process-oriented design, making it easier to extend and swap workflow strategies (sequential, hierarchical, etc.).

##### Relevant Technologies and Frameworks
- Python (≥3.10 <3.13) as the base language.
- UV for dependency management.
- Optional integration with external LLM APIs (OpenAI, Serper.dev) and integration with tooling for CLI commands.
- Testing frameworks (pytest) and static analysis (mypy, ruff) are configured to maintain quality.

## Diagram (Mermaid)

```mermaid
flowchart TD
    User("User"):::bootstrap

    subgraph "Bootstrapping Layer"
        CLI("CLI & Templates"):::bootstrap
        Config("Configuration Management"):::bootstrap
    end

    subgraph "Orchestration Layer"
        Crew("Crew Orchestrator"):::orchestration
        Flow("Flow Manager"):::orchestration
    end

    subgraph "Execution Layer"
        Agents("Agents & Agent Builders"):::execution
    end

    subgraph "Data & External Services"
        Memory("Memory Management"):::data
        Knowledge("Knowledge Sources"):::data
        Tools("Tools & LLM Integrations"):::data
        API("External LLM/API Services"):::data
    end

    subgraph "Support & Monitoring"
        Util("Utilities, Logging & Exceptions"):::support
        Telemetry("Telemetry"):::support
        Sec("Security"):::support
    end

    subgraph "Testing"
        Tests("Tests"):::test
    end

    %% Data flow connections
    User -->|"initiates"| CLI
    CLI -->|"loads"| Config
    CLI -->|"bootstraps"| Crew
    CLI -->|"bootstraps"| Flow
    Config -->|"provides config"| Crew
    Config -->|"provides config"| Flow

    Crew -->|"orchestrates"| Agents
    Flow -->|"triggers tasks"| Agents

    Agents -->|"updates"| Memory
    Agents -->|"queries"| Knowledge
    Agents -->|"invokes"| Tools
    Tools -->|"calls"| API

    Flow -->|"logs"| Telemetry
    Flow -->|"enforces"| Sec

    Agents -->|"reports"| Util
    Memory -->|"logs"| Util
    Knowledge -->|"logs"| Util

    %% Styling classes
    classDef bootstrap fill:#d6bbff,stroke:#333,stroke-width:2px
    classDef orchestration fill:#9ad3de,stroke:#333,stroke-width:2px
    classDef execution fill:#bbf7d0,stroke:#333,stroke-width:2px
    classDef data fill:#ffddb3,stroke:#333,stroke-width:2px
    classDef support fill:#f3c6c1,stroke:#333,stroke-width:2px
    classDef test fill:#e2e2e2,stroke:#333,stroke-width:2px

    %% Click Events
    click CLI "https://github.com/git-devisha/crewai/tree/main/src/crewai/cli"
    click CLI "https://github.com/git-devisha/crewai/tree/main/src/crewai/cli/templates"
    click Agents "https://github.com/git-devisha/crewai/tree/main/src/crewai/agents"
    click Crew "https://github.com/git-devisha/crewai/tree/main/src/crewai/crews"
    click Flow "https://github.com/git-devisha/crewai/tree/main/src/crewai/flow"
    click Memory "https://github.com/git-devisha/crewai/tree/main/src/crewai/memory"
    click Knowledge "https://github.com/git-devisha/crewai/tree/main/src/crewai/knowledge"
    click Tools "https://github.com/git-devisha/crewai/tree/main/src/crewai/tools"
    click Util "https://github.com/git-devisha/crewai/tree/main/src/crewai/utilities"
    click Telemetry "https://github.com/git-devisha/crewai/tree/main/src/crewai/telemetry"
    click Sec "https://github.com/git-devisha/crewai/tree/main/src/crewai/security"
    click Tests "https://github.com/git-devisha/crewai/tree/main/tests"
```
