azad.prompts.dialects.native Package¶
azad.prompts.dialects.native ¶
Anthropic Native dialect for Azad prompts.
This package contains the Anthropic Native dialect implementation for Azad prompts, which allows using Anthropic's native tool calling format in LLM interactions.
Classes¶
NativeDialectConfig ¶
Bases: DialectConfig
Configuration for Native dialect parser.
Attributes¶
parameter_buffer_threshold
class-attribute
instance-attribute
¶
parameter_buffer_threshold: int = Field(default=15, description='Minimum characters for parameter chunks')
NativeDialectParser ¶
NativeDialectParser(schema: Dict, prompt_data: PromptData, config: NativeDialectConfig)
Bases: DialectParser
Native dialect parser for processing streaming tool call deltas.
This parser processes tool call deltas directly from the model and efficiently emits events with proper buffering to reduce event frequency while maintaining responsiveness. It implements both size-based and time-based buffering mechanisms to optimize the trade-off between low latency and reducing excessive event emissions.
Initialize the parser with the given schema and configuration.
Source code in azad/prompts/dialects/native/parser.py
Attributes¶
Functions¶
reset_state ¶
Reset the parser state for a new tool call.
Source code in azad/prompts/dialects/native/parser.py
feed ¶
feed(data: bytes) -> List[AINetworkEventUnion]
Process plain text content (outside of a tool call).
This method is called when the model outputs regular text instead of a tool call.
Source code in azad/prompts/dialects/native/parser.py
feed_tool_call_delta ¶
feed_tool_call_delta(tool_call: Union[ChatCompletionDeltaToolCall, ChatCompletionMessageToolCall]) -> List[AINetworkEventUnion]
Process tool call deltas from the model with efficient buffering.
This method handles the incremental parts of a tool call that come from the model, buffering small chunks for improved efficiency.
Source code in azad/prompts/dialects/native/parser.py
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 | |
NativeDialect ¶
NativeDialect(config: NativeDialectConfig)
Bases: Dialect
Native dialect for AI agent communication using native tool calling format.
Source code in azad/prompts/dialects/native/dialect.py
Attributes¶
Functions¶
format_tool_schema ¶
format_tool_schema(tool: ToolMetadata) -> dict
Format a tool's metadata into a JSON schema format.
Parameters:
-
tool(ToolMetadata) –The tool metadata to format
Returns:
-
dict–A dictionary representing the formatted tool schema
Source code in azad/prompts/base_dialect.py
format_tools_schema ¶
format_tools_schema(tools: List[ToolMetadata]) -> List[dict]
Format multiple tools' metadata into JSON schema format.
Parameters:
-
tools(List[ToolMetadata]) –A list of tool metadata objects to format
Returns:
-
List[dict]–A list of dictionaries representing the formatted tool schemas
Source code in azad/prompts/base_dialect.py
inject_prompt_cache ¶
inject_prompt_cache(messages: list[dict], prompt_data: PromptData)
Modifies the formatted messages list IN-PLACE to add cache control flags based on the model type and specific caching rules.
Source code in azad/prompts/base_dialect.py
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 | |
format_messages ¶
format_messages(prompt_data: PromptData, rules_path: Optional[str]) -> list[dict]
Source code in azad/prompts/base_dialect.py
format_system_prompt ¶
format_system_prompt(prompt_data: PromptData, rules_path: Optional[str]) -> dict
Format the system prompt for the dialect. This method handles the replacement of placeholders in the system prompt with the actual values from the prompt data. If there is no placeholder it will format the system prompt in following way: TOOL_USE_INSTRUCTION AVAILABLE_TOOLS USER AGENT PROMPT SYSTEM GENERAL INSTRUCTIONS USER CUSTOM INSTRUCTIONS
Source code in azad/prompts/base_dialect.py
format_system_rules ¶
Source code in azad/prompts/base_dialect.py
format_history ¶
format_history(prompt_data: PromptData) -> List[dict]
Format the entire message history from the mindmap.
Source code in azad/prompts/base_dialect.py
format_user_prompt ¶
format_user_prompt(prompt_data: PromptData) -> str
Source code in azad/prompts/base_dialect.py
format_user_agent_prompt ¶
format_user_agent_prompt(prompt_data: PromptData) -> str
Source code in azad/prompts/base_dialect.py
format_tool_docs ¶
format_tool_docs(prompt_data: PromptData) -> str
Format documentation for available tools.
This base implementation handles the structure, while specific dialects format the individual examples.
Parameters:
-
tools–List of Tool classes or ToolSignature objects to document
Returns:
-
str–Formatted tool documentation string
Source code in azad/prompts/base_dialect.py
format_dialect_rules ¶
format_dialect_rules(prompt_data: PromptData) -> str
Return the native dialect rules.
dict_to_human_readable_simple ¶
Converts a dictionary into a simple human-readable string.
Parameters:
-
data_dict(dict) –The dictionary to convert.
Returns:
-
str–A string representation with each key-value pair on a new line,
-
str–or a message if the input is not a dictionary or is empty.
Source code in azad/prompts/dialects/native/dialect.py
format_example ¶
Format an example tool call in native format.
Source code in azad/prompts/dialects/native/dialect.py
format_tool_call ¶
format_tool_call(tool_call: ToolCallPart) -> dict
Format a tool call into native format.
Source code in azad/prompts/dialects/native/dialect.py
format_tool_result ¶
format_tool_result(tool_result: ToolResultPart) -> dict
Format a tool result into native format.
Source code in azad/prompts/dialects/native/dialect.py
format_history_item ¶
format_history_item(item: Message) -> Optional[dict]
Convert a Message to a LiteLLM message with native tool calls and image support.
Source code in azad/prompts/dialects/native/dialect.py
create_parser ¶
create_parser(prompt_data: PromptData) -> DialectParser
Create an native dialect parser configured with the specified tools.
Source code in azad/prompts/dialects/native/dialect.py
Modules¶
dialect ¶
Attributes¶
Classes¶
NativeDialect ¶
NativeDialect(config: NativeDialectConfig)
Bases: Dialect
Native dialect for AI agent communication using native tool calling format.
Source code in azad/prompts/dialects/native/dialect.py
format_dialect_rules(prompt_data: PromptData) -> str
Return the native dialect rules.
Converts a dictionary into a simple human-readable string.
Parameters:
-
data_dict(dict) –The dictionary to convert.
Returns:
-
str–A string representation with each key-value pair on a new line,
-
str–or a message if the input is not a dictionary or is empty.
Source code in azad/prompts/dialects/native/dialect.py
Format an example tool call in native format.
Source code in azad/prompts/dialects/native/dialect.py
format_tool_call(tool_call: ToolCallPart) -> dict
Format a tool call into native format.
Source code in azad/prompts/dialects/native/dialect.py
format_tool_result(tool_result: ToolResultPart) -> dict
Format a tool result into native format.
Source code in azad/prompts/dialects/native/dialect.py
format_history_item(item: Message) -> Optional[dict]
Convert a Message to a LiteLLM message with native tool calls and image support.
Source code in azad/prompts/dialects/native/dialect.py
create_parser(prompt_data: PromptData) -> DialectParser
Create an native dialect parser configured with the specified tools.
Source code in azad/prompts/dialects/native/dialect.py
format_tool_schema(tool: ToolMetadata) -> dict
Format a tool's metadata into a JSON schema format.
Parameters:
-
tool(ToolMetadata) –The tool metadata to format
Returns:
-
dict–A dictionary representing the formatted tool schema
Source code in azad/prompts/base_dialect.py
format_tools_schema(tools: List[ToolMetadata]) -> List[dict]
Format multiple tools' metadata into JSON schema format.
Parameters:
-
tools(List[ToolMetadata]) –A list of tool metadata objects to format
Returns:
-
List[dict]–A list of dictionaries representing the formatted tool schemas
Source code in azad/prompts/base_dialect.py
inject_prompt_cache(messages: list[dict], prompt_data: PromptData)
Modifies the formatted messages list IN-PLACE to add cache control flags based on the model type and specific caching rules.
Source code in azad/prompts/base_dialect.py
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 | |
format_messages(prompt_data: PromptData, rules_path: Optional[str]) -> list[dict]
Source code in azad/prompts/base_dialect.py
format_system_prompt(prompt_data: PromptData, rules_path: Optional[str]) -> dict
Format the system prompt for the dialect. This method handles the replacement of placeholders in the system prompt with the actual values from the prompt data. If there is no placeholder it will format the system prompt in following way: TOOL_USE_INSTRUCTION AVAILABLE_TOOLS USER AGENT PROMPT SYSTEM GENERAL INSTRUCTIONS USER CUSTOM INSTRUCTIONS
Source code in azad/prompts/base_dialect.py
Source code in azad/prompts/base_dialect.py
format_history(prompt_data: PromptData) -> List[dict]
Format the entire message history from the mindmap.
Source code in azad/prompts/base_dialect.py
format_user_prompt(prompt_data: PromptData) -> str
Source code in azad/prompts/base_dialect.py
format_user_agent_prompt(prompt_data: PromptData) -> str
Source code in azad/prompts/base_dialect.py
format_tool_docs(prompt_data: PromptData) -> str
Format documentation for available tools.
This base implementation handles the structure, while specific dialects format the individual examples.
Parameters:
-
tools–List of Tool classes or ToolSignature objects to document
Returns:
-
str–Formatted tool documentation string
Source code in azad/prompts/base_dialect.py
Functions¶
parser ¶
Native dialect parser for streaming tool calls with real-time event emission.
Attributes¶
Classes¶
NativeDialectConfig ¶
Bases: DialectConfig
Configuration for Native dialect parser.
class-attribute
instance-attribute
¶parameter_buffer_threshold: int = Field(default=15, description='Minimum characters for parameter chunks')
NativeDialectParser ¶
NativeDialectParser(schema: Dict, prompt_data: PromptData, config: NativeDialectConfig)
Bases: DialectParser
Native dialect parser for processing streaming tool call deltas.
This parser processes tool call deltas directly from the model and efficiently emits events with proper buffering to reduce event frequency while maintaining responsiveness. It implements both size-based and time-based buffering mechanisms to optimize the trade-off between low latency and reducing excessive event emissions.
Initialize the parser with the given schema and configuration.
Source code in azad/prompts/dialects/native/parser.py
Reset the parser state for a new tool call.
Source code in azad/prompts/dialects/native/parser.py
feed(data: bytes) -> List[AINetworkEventUnion]
Process plain text content (outside of a tool call).
This method is called when the model outputs regular text instead of a tool call.
Source code in azad/prompts/dialects/native/parser.py
feed_tool_call_delta(tool_call: Union[ChatCompletionDeltaToolCall, ChatCompletionMessageToolCall]) -> List[AINetworkEventUnion]
Process tool call deltas from the model with efficient buffering.
This method handles the incremental parts of a tool call that come from the model, buffering small chunks for improved efficiency.
Source code in azad/prompts/dialects/native/parser.py
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 | |
test_native_parser ¶
Test suite for the Native dialect parser.
Attributes¶
Classes¶
MockPromptData ¶
Mock prompt data for testing.
Source code in azad/prompts/dialects/native/test_native_parser.py
TestNativeParser ¶
Bases: TestCase
Test suite for the Native dialect parser.
create_tool_call_delta(tool_id: Optional[str] = None, tool_name: Optional[str] = None, arguments: str = '', tool_type: str = 'function', index: int = 0) -> ChatCompletionDeltaToolCall
Helper to create a tool call delta with the specified properties.
Source code in azad/prompts/dialects/native/test_native_parser.py
Test parsing a realistic stream of tool call deltas.
Source code in azad/prompts/dialects/native/test_native_parser.py
Test parsing a stream with a longer parameter value that comes in many pieces.