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:
Dialectinterface for implementing different prompt dialectsDialectParserinterface for parsing responses from language modelsPromptDataclass 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¶
- The
AINetworkcreates a dialect based on the task configuration - The dialect formats the prompt data into a format that the language model understands
- The dialect creates a parser for processing the language model's response
- The parser converts the response into standardized events that the agent can process
Dialect Components¶
Each dialect consists of two main components:
-
Dialect Class: Responsible for formatting prompts and creating parsers
-
Formats system prompts with rules and tool documentation
- Formats message history for the language model
- Formats tool calls and results
-
Creates parsers for processing responses
-
Parser Class: Responsible for parsing responses from the language model
- Processes streaming responses
- Extracts tool calls and parameters
- Emits standardized events
Creating Custom Dialects¶
To create a custom dialect:
- Implement the
DialectandDialectParserinterfaces - Define a configuration class for your dialect
- Register your dialect with the
PromptDialectRegistry
See the Extending Azad guide for more details.