ai

View as MarkdownOpen in Claude

Add an ai verb to the main section. Starts an AI-powered conversation on the call.

prompt_text and prompt_pom are mutually exclusive. Provide one or the other to set the AI system prompt, but not both.

Parameters

prompt_text
Optional[str]

Plain text system prompt for the AI. Mutually exclusive with prompt_pom.

prompt_pom
Optional[list[dict[str, Any]]]

Prompt Object Model (POM) structure for the AI prompt. A list of section dictionaries with keys like "section", "body", and "bullets". Mutually exclusive with prompt_text.

post_prompt
Optional[str]

Instructions for summarizing the call after the AI conversation ends.

post_prompt_url
Optional[str]

URL where the post-prompt summary is sent via webhook.

swaig
Optional[dict[str, Any]]

SWAIG (SignalWire AI Gateway) configuration with tool function definitions and defaults. Structure: {"defaults": {"web_hook_url": "..."}, "functions": [...]}.

**kwargs
Any

Additional AI verb parameters passed directly into the verb config (e.g., hints, languages, params, global_data).

Returns

Self — The builder instance for method chaining.

Example

1from signalwire import SWMLService, SWMLBuilder
2
3service = SWMLService(name="ai-agent")
4builder = SWMLBuilder(service)
5
6swml_json = (
7 builder
8 .answer()
9 .ai(
10 prompt_text="You are a helpful customer service assistant.",
11 post_prompt="Summarize what was discussed.",
12 post_prompt_url="https://example.com/post_prompt",
13 swaig={
14 "defaults": {"web_hook_url": "https://example.com/swaig"},
15 "functions": [
16 {
17 "function": "check_order",
18 "description": "Check order status",
19 "parameters": {
20 "type": "object",
21 "properties": {
22 "order_id": {"type": "string", "description": "The order ID"}
23 },
24 "required": ["order_id"]
25 }
26 }
27 ]
28 },
29 hints=["order", "tracking", "refund"],
30 params={"end_of_speech_timeout": 500}
31 )
32 .render()
33)
34print(swml_json)