swml_user_event

View as MarkdownOpen in Claude

Send a custom user event through SWML. Events are delivered to connected clients in real time, commonly used to drive UI updates in interactive applications (e.g., updating a scoreboard, dealing cards, showing status).

Parameters

event_data
dict[str, Any]Required

Dictionary containing the event payload. Include a "type" key to help clients distinguish between different event types.

Returns

FunctionResult — self, for chaining.

Example

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="deal_cards", description="Deal cards and notify the UI")
def deal_cards(args, raw_data):
return (
FunctionResult("You have blackjack!")
.swml_user_event({
"type": "cards_dealt",
"player_hand": ["Ace", "King"],
"dealer_hand": ["7", "hidden"],
"player_score": 21
})
)
agent.serve()