Skip to content

Prompts Package

The azad.prompts package provides utilities for formatting prompts and parsing responses for different language models. It implements a dialect system that allows Azad to work with various prompt formats.

Core Components

Base Dialect

The Base Dialect module defines the core interfaces and classes for the dialect system. It includes:

  • Dialect interface for implementing different prompt dialects
  • DialectParser interface for parsing responses from language models
  • PromptData class for representing prompt data

Registry

The Registry module provides a registry for prompt dialects. It:

  • Registers dialects by name
  • Retrieves dialects by name
  • Manages dialect instantiation

Dialects

The Dialects subpackage contains implementations of different prompt dialects:

  • JSON: A dialect that formats prompts and parses responses in JSON format
  • Native: A dialect that uses the native tool calling format of the language model
  • XML: A dialect that formats prompts and parses responses in XML format

How Dialects Work

  1. The AINetwork creates a dialect based on the task configuration
  2. The dialect formats the prompt data into a format that the language model understands
  3. The dialect creates a parser for processing the language model's response
  4. The parser converts the response into standardized events that the agent can process

Dialect Components

Each dialect consists of two main components:

  1. Dialect Class: Responsible for formatting prompts and creating parsers

  2. Formats system prompts with rules and tool documentation

  3. Formats message history for the language model
  4. Formats tool calls and results
  5. Creates parsers for processing responses

  6. Parser Class: Responsible for parsing responses from the language model

  7. Processes streaming responses
  8. Extracts tool calls and parameters
  9. Emits standardized events

Creating Custom Dialects

To create a custom dialect:

  1. Implement the Dialect and DialectParser interfaces
  2. Define a configuration class for your dialect
  3. Register your dialect with the PromptDialectRegistry

See the Extending Azad guide for more details.