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

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