AgentsDataMap

to_swaig_function

View as MarkdownOpen in Claude

Convert this DataMap to a SWAIG function definition dictionary. Register the result with your agent using agent.register_swaig_function().

Returns

dict[str, Any] — A dictionary containing the function name, description, parameter schema, and data_map configuration (instead of a webhook URL).

Example

1from signalwire import AgentBase, DataMap
2from signalwire import FunctionResult
3
4class WeatherAgent(AgentBase):
5 def __init__(self):
6 super().__init__(name="weather-agent")
7 self.set_prompt_text("You are a helpful assistant.")
8
9 weather = (
10 DataMap("get_weather")
11 .description("Get current weather for a city")
12 .parameter("city", "string", "City name", required=True)
13 .webhook("GET", "https://api.weatherapi.com/v1/current.json?key=KEY&q=${enc:args.city}")
14 .output(FunctionResult("Weather: ${response.current.condition.text}, ${response.current.temp_f}F"))
15 .fallback_output(FunctionResult("Weather data unavailable for ${args.city}"))
16 )
17
18 # Convert DataMap to a SWAIG function definition and register it
19 self.register_swaig_function(weather.to_swaig_function())
20
21if __name__ == "__main__":
22 WeatherAgent().run()