> This page is for Server SDKs.

> Fetch clean Markdown by appending `.md` to any page URL under https://signalwire.com/docs or requesting it with the HTTP header `Accept: text/markdown`. The root index at https://signalwire.com/docs/llms.txt lists the available documentation indexes.

# 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.

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

## **Parameters**

**`message_text`** `str | None` — default: None

The message text to send to the AI agent.

---

**`role`** `str | None` — default: None

The role of the message sender. Valid values:

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

---

**`reset`** `dict | None` — default: None

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

---

**`global_data`** `dict | None` — default: None

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

---

## **Returns**

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

## **Example**

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

client = RelayClient(
    project="your-project-id",
    token="your-api-token",
    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()
```