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

# ai_message

> Send a message to an active AI agent session.

[ai]: /docs/server-sdks/reference/python/relay/call/ai

Send a message to an active AI agent session on the call. Use this to inject
context, instructions, or simulated user input into a running AI conversation.

This method requires an active AI session started via
[`ai()`][ai]. Calling it without
an active session has no effect.

## **Parameters**

The message text to send to the AI agent.

The role of the message sender. Valid values:

* `"user"` -- simulate user input
* `"system"` -- send a system-level instruction
* `"assistant"` -- inject an assistant response

Reset configuration. Allows resetting AI state such as the conversation
history or functions.

Update the global data accessible to the AI and SWAIG functions.

## **Returns**

`dict` -- Server response confirming the message was sent.

## **Example**

```python {22}
import asyncio
from signalwire.relay import RelayClient

client = RelayClient(
    project="your-project-id",
    token="your-api-token",
    host="your-space.signalwire.com",
    contexts=["default"],
)

@client.on_call
async def handle_call(call):
    await call.answer()

    # Start an AI agent
    action = await call.ai(
        prompt={"text": "You are a helpful assistant."},
    )

    # Inject a system message after 10 seconds
    await asyncio.sleep(10)
    await call.ai_message(
        message_text="The caller is a VIP customer. Be extra helpful.",
        role="system",
    )

    await action.wait()

client.run()
```