# meta-llama/llama-stack-client-python architecture

> Architecture diagram of the GitHub repository meta-llama/llama-stack-client-python, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-05). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/meta-llama/llama-stack-client-python
- Repository: https://github.com/meta-llama/llama-stack-client-python

## Overview

##### Main Components

a. Core Client Layer
- Base Client Component (src/llama_stack_client/_base_client.py)
- Synchronous Client (src/llama_stack_client/_client.py)
- Async Client (shown in README examples)
- HTTP Client Wrapper (DefaultHttpxClient)

b. Resource Layer
- Agents
- Inference
- Memory
- Models
- Post Training
- Evaluation
- Safety
- Telemetry
- Datasets

c. Types Layer
- Request Types
- Response Types
- Shared Types
- Model Definitions

d. Utility Components
- Error Handling
- Logging
- Response Processing
- File Handling
- Streaming Support

##### Relationships

a. Client Flow:
**User Application → Client Layer → Resource Layer → HTTP Client → Llama Stack Server**

b. Data Flow:
**Request Types → Resource Layer → Response Types → User Application**

**┌─────────────────────────────────────────────────────────┐**
- User Application                        │
- ┬─────────────────────────────────┘
- ↓
**┌─────────────────────────────────────────────────────────┐**
- Client Layer                         │
- ┌───────────────┐  ┌───────────────┐  ┌────────────┐  │
- Sync Client   │  │ Async Client  │  │HTTP Client  │  │
- ┬───────┘  └───────┬───────┘  └─────┬──────┘  │
- ┼────────────────┬─┼───────────────┬┼─────────┘
- ↓                ↓ ↓               ↓↓
**┌─────────────────────────────────────────────────────────┐**
- Resource Layer                        │
- ┌─────────┐ ┌─────────┐ ┌──────────┐ ┌────────────┐  │
- Agents  │ │Inference│ │ Memory   │ │   Models   │  │
- ┬────┘ └────┬────┘ └────┬─────┘ └─────┬──────┘  │
- ┼──────────┬┼─────────┬─┼────────────┬┼─────────┘
- ↓          ↓↓         ↓ ↓            ↓↓
**┌─────────────────────────────────────────────────────────┐**
- Types Layer                         │
- ┌────────────┐ ┌───────────┐ ┌────────────────────┐  │
- Request Types│ │Shared Types│ │Response Types     │  │
- ┘ └───────────┘ └────────────────────┘  │
- ┘

##### Additional Elements

- Version compatibility information
- Configuration options (timeout, retries, etc.)

##### Implementation Details

- The separation between sync and async clients
- The resource-based API structure
- Type safety and validation
- Error handling and retry mechanisms
- Streaming response capabilities
- HTTP client configuration options

- Clear boundaries between layers
- Type system as it's a key feature
- Error handling paths
- Both synchronous and asynchronous flows
- Configuration points
- Integration points with external systems

This design captures the essential architecture while maintaining clarity and showing the relationships between components. It reflects both the file structure and the functionality described in the README.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph User["User Application"]
        UA[Client Usage]
    end

    subgraph ClientLayer["Client Layer"]
        BaseClient["Base Client"]:::client
        SyncClient["Synchronous Client"]:::client
        AsyncClient["Asynchronous Client"]:::client
        HTTPClient["HTTP Client Wrapper"]:::client
    end

    subgraph ResourceLayer["Resource Layer"]
        ResourceBase["Resource Base"]:::resource
        Agents["Agents"]:::resource
        Inference["Inference"]:::resource
        Memory["Memory"]:::resource
        Models["Models"]:::resource
        PostTraining["Post Training"]:::resource
        Evaluation["Evaluation"]:::resource
        Safety["Safety"]:::resource
        Telemetry["Telemetry"]:::resource
    end

    subgraph TypesLayer["Types Layer"]
        RequestTypes["Request Types"]:::type
        ResponseTypes["Response Types"]:::type
        SharedTypes["Shared Types"]:::type
        ModelDefs["Model Definitions"]:::type
    end

    subgraph UtilityLayer["Utility Components"]
        ErrorHandling["Error Handling"]:::utility
        Logging["Logging"]:::utility
        FileHandling["File Handling"]:::utility
        TypeUtils["Type Utilities"]:::utility
        Constants["Constants"]:::utility
    end

    UA --> BaseClient
    UA --> SyncClient
    UA --> AsyncClient

    BaseClient --> HTTPClient
    SyncClient --> HTTPClient
    AsyncClient --> HTTPClient

    HTTPClient --> ResourceBase
    ResourceBase --> Agents
    ResourceBase --> Inference
    ResourceBase --> Memory
    ResourceBase --> Models
    ResourceBase --> PostTraining
    ResourceBase --> Evaluation
    ResourceBase --> Safety
    ResourceBase --> Telemetry

    RequestTypes --> ResourceBase
    ResourceBase --> ResponseTypes
    SharedTypes --> ResourceBase
    ModelDefs --> ResourceBase

    ErrorHandling -.-> ClientLayer
    Logging -.-> ClientLayer
    FileHandling -.-> ResourceLayer
    TypeUtils -.-> TypesLayer
    Constants -.-> ClientLayer

    %% Click events for component mapping
    click BaseClient "https://github.com/meta-llama/llama-stack-client-python/blob/main/src/llama_stack_client/_base_client.py"
    click SyncClient "https://github.com/meta-llama/llama-stack-client-python/blob/main/src/llama_stack_client/_client.py"
    click HTTPClient "https://github.com/meta-llama/llama-stack-client-python/blob/main/src/llama_stack_client/_utils/_proxy.py"
    click ResourceBase "https://github.com/meta-llama/llama-stack-client-python/blob/main/src/llama_stack_client/_resource.py"
    click Agents "https://github.com/meta-llama/llama-stack-client-python/tree/main/src/llama_stack_client/resources/agents"
    click Inference "https://github.com/meta-llama/llama-stack-client-python/blob/main/src/llama_stack_client/resources/inference.py"
    click Memory "https://github.com/meta-llama/llama-stack-client-python/blob/main/src/llama_stack_client/resources/memory.py"
    click Models "https://github.com/meta-llama/llama-stack-client-python/blob/main/src/llama_stack_client/resources/models.py"
    click PostTraining "https://github.com/meta-llama/llama-stack-client-python/tree/main/src/llama_stack_client/resources/post_training"
    click Evaluation "https://github.com/meta-llama/llama-stack-client-python/tree/main/src/llama_stack_client/resources/eval"
    click Safety "https://github.com/meta-llama/llama-stack-client-python/blob/main/src/llama_stack_client/resources/safety.py"
    click Telemetry "https://github.com/meta-llama/llama-stack-client-python/blob/main/src/llama_stack_client/resources/telemetry.py"
    click RequestTypes "https://github.com/meta-llama/llama-stack-client-python/tree/main/src/llama_stack_client/types"
    click SharedTypes "https://github.com/meta-llama/llama-stack-client-python/tree/main/src/llama_stack_client/types/shared"
    click ModelDefs "https://github.com/meta-llama/llama-stack-client-python/blob/main/src/llama_stack_client/_models.py"
    click ErrorHandling "https://github.com/meta-llama/llama-stack-client-python/blob/main/src/llama_stack_client/_exceptions.py"
    click Logging "https://github.com/meta-llama/llama-stack-client-python/blob/main/src/llama_stack_client/_utils/_logs.py"
    click FileHandling "https://github.com/meta-llama/llama-stack-client-python/blob/main/src/llama_stack_client/_files.py"
    click TypeUtils "https://github.com/meta-llama/llama-stack-client-python/blob/main/src/llama_stack_client/_utils/_typing.py"
    click Constants "https://github.com/meta-llama/llama-stack-client-python/blob/main/src/llama_stack_client/_constants.py"

    classDef client fill:#2374ab
    classDef resource fill:#2a9d8f
    classDef type fill:#e9c46a
    classDef utility fill:#grey
    
    %% Legend
    subgraph Legend
        Client[Client Components]:::client
        Resource[Resource Components]:::resource
        Type[Type Components]:::type
        Utility[Utility Components]:::utility
        Flow["--> Normal Flow"]
        ErrorFlow["-.- Error/Utility Flow"]
    end
```
