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

from signalwire import AgentBase, DataMap
from signalwire import FunctionResult
class WeatherAgent(AgentBase):
def __init__(self):
super().__init__(name="weather-agent")
self.set_prompt_text("You are a helpful assistant.")
weather = (
DataMap("get_weather")
.description("Get current weather for a city")
.parameter("city", "string", "City name", required=True)
.webhook("GET", "https://api.weatherapi.com/v1/current.json?key=KEY&q=${enc:args.city}")
.output(FunctionResult("Weather: ${response.current.condition.text}, ${response.current.temp_f}F"))
.fallback_output(FunctionResult("Weather data unavailable for ${args.city}"))
)
# Convert DataMap to a SWAIG function definition and register it
self.register_swaig_function(weather.to_swaig_function())
if __name__ == "__main__":
WeatherAgent().run()