AgentsAgentBase

register_swaig_function

View as MarkdownOpen in Claude

Register a raw SWAIG function definition dictionary. This is the primary way to register server-side functions created by DataMap, which generates complete SWAIG function definitions including URL mappings, expressions, and output templates.

Unlike define_tool(), this method does not take a Python handler — the function executes on the SignalWire server (for DataMap functions) or at an external webhook URL.

Parameters

function_dict
dict[str, Any]Required

Complete SWAIG function definition dictionary. Must follow the SWAIG function schema, typically generated by DataMap.to_swaig_function().

Returns

AgentBase — Returns self for method chaining.

Example

from signalwire import AgentBase, FunctionResult
from signalwire.core.data_map import DataMap
agent = AgentBase(name="weather-agent", route="/weather")
agent.set_prompt_text("You are a helpful assistant.")
# Create a DataMap that calls a weather API server-side
weather_tool = (
DataMap("get_weather")
.description("Get the current weather")
.parameter("city", param_type="string", description="City name", required=True)
.webhook("GET", "https://api.weather.example.com/current?city=${args.city}")
.output(FunctionResult("The weather in ${args.city} is ${response.temp}F."))
)
# Register the DataMap as a SWAIG function
agent.register_swaig_function(weather_tool.to_swaig_function())
agent.serve()