***

title: to_dict
slug: /reference/python/agents/function-result/to-dict
description: Serialize a FunctionResult to the SWAIG response format.
max-toc-depth: 3
---------------------

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

Serialize to the JSON structure expected by SWAIG. Called automatically when the
result is returned from a tool function -- you rarely need to call this directly.

The output contains `response` (if set), `action` (if any actions were added),
and `post_process` (only when `True` and actions are present). If neither
`response` nor `action` is present, defaults to `{"response": "Action completed."}`.

## **Parameters**

None.

## **Returns**

`dict[str, Any]` -- SWAIG-formatted response dictionary.

## **Example**

```python {15}
from signalwire import AgentBase
from signalwire import FunctionResult

agent = AgentBase(name="my-agent", route="/agent")
agent.set_prompt_text("You are a helpful assistant.")

@agent.tool(name="transfer", description="Transfer the call")
def transfer(args, raw_data):
    result = (
        FunctionResult("Transferring you now.")
        .connect("+15551234567")
    )

    # Inspect the serialized output
    print(result.to_dict())
    # {"response": "Transferring you now.", "action": [{"SWML": {...}, "transfer": "true"}]}
    return result

agent.serve()
```