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
str | NoneDefaults to None

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

prompt_pom
list[dict[str, Any]] | NoneDefaults to None

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
str | NoneDefaults to None

Instructions for summarizing the call after the AI conversation ends.

post_prompt_url
str | NoneDefaults to None

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

swaig
dict[str, Any] | NoneDefaults to None

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

from signalwire import SWMLService, SWMLBuilder
service = SWMLService(name="ai-agent")
builder = SWMLBuilder(service)
swml_json = (
builder
.answer()
.ai(
prompt_text="You are a helpful customer service assistant.",
post_prompt="Summarize what was discussed.",
post_prompt_url="https://example.com/post_prompt",
swaig={
"defaults": {"web_hook_url": "https://example.com/swaig"},
"functions": [
{
"function": "check_order",
"description": "Check order status",
"parameters": {
"type": "object",
"properties": {
"order_id": {"type": "string", "description": "The order ID"}
},
"required": ["order_id"]
}
}
]
},
hints=["order", "tracking", "refund"],
params={"end_of_speech_timeout": 500}
)
.render()
)
print(swml_json)