***

title: to_swaig_function
slug: /reference/python/agents/data-map/to-swaig-function
description: Convert the DataMap to a SWAIG function definition dictionary.
max-toc-depth: 3
---------------------

For a complete index of all SignalWire documentation pages, fetch https://signalwire.com/docs/llms.txt

[ref-datamap]: /docs/server-sdks/reference/python/agents/data-map

Convert this [DataMap][ref-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**

```python {19}
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()
```