Skip to content

Azad Architecture

This page provides an overview of the Azad architecture, explaining how the different components work together to create an autonomous AI development agent.

High-Level Architecture

Azad follows a modular architecture with several key components:

graph TD
    Client["Client<br/>(VS Code, CLI)"] --> AzadServer

    subgraph AzadServer["Azad Server"]
        Agent["Agent"] <--> Task["Task"]
        Task <--> Environment["Environment"]
        Agent --> AINetwork["AI Network"]
        AINetwork <--> Dialect["Dialect"]
        Environment --> Tools["Tools"]
        Dialect <--> Tools
        AINetwork --> Compression["Compression"]
    end

    AzadServer --> LLMProvider["LLM Provider<br/>(OpenAI, etc.)"]

Core Components

Agent

The AzadAgent class is the central component that manages the execution of tasks. It:

  • Handles incoming requests from clients
  • Manages task state and execution
  • Coordinates tool calls and responses
  • Communicates with the AI network

Task and Mind Map

The Task class represents a specific task being executed by the agent. It contains:

  • A list of messages (system, user, assistant, tool)
  • The current state of the task
  • Methods for adding and retrieving messages

The Mind Map is the data structure that represents the conversation and tool interactions within a task.

Environment

The Environment class provides an interface for the agent to interact with the outside world. It:

  • Executes tools
  • Requests approval for tool usage
  • Manages resources

AI Network

The AINetwork class handles communication with language model providers. It:

  • Sends requests to language models
  • Processes streaming responses
  • Manages context window exceeded errors with compression
  • Emits standardized network events

Prompt Dialects

The Dialect system supports multiple prompt formats for different model requirements. Each dialect:

  • Formats messages for the language model
  • Parses responses from the language model
  • Handles tool calls and results

Compression

The Compression system helps manage context windows for large conversations. It:

  • Implements different compression strategies
  • Tracks compression checkpoints
  • Transforms message history to fit within context limits

Tools

Azad includes Predefined Tools for common operations, as well as support for server-executed tools requiring specific environments.

Execution Flow

  1. A client (VS Code extension, CLI) sends a task to the Azad server
  2. The AzadAgent loads the task and initializes the environment
  3. The loop_stepper.step function is called to execute a step of the task
  4. The AINetwork sends the current task state to the language model
  5. The language model responds with text and/or tool calls
  6. Tool calls are approved and executed through the Environment
  7. Results are added to the task and the process repeats
  8. The task completes when the language model indicates it's done or an error occurs

Key Design Patterns

Request/Response Pattern

Azad uses a request/response pattern for communication between components, with methods decorated with @request_response or @request_stream to indicate their behavior.

Event-Driven Architecture

The AI network and tool execution use an event-driven architecture, emitting events that are processed by the agent and forwarded to the client.

Strategy Pattern

The compression system uses the strategy pattern to allow different compression strategies to be used interchangeably.

Factory Pattern

The dialect system uses a factory pattern to create the appropriate dialect parser based on configuration.

Configuration

Azad can be configured via:

  • Configuration files
  • Environment variables
  • Command-line arguments

See the README for more details on configuration options.