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

1from signalwire import AgentBase
2from signalwire import FunctionResult
3
4agent = AgentBase(name="my-agent", route="/agent")
5agent.set_prompt_text("You are a helpful assistant.")
6
7@agent.tool(name="deal_cards", description="Deal cards and notify the UI")
8def deal_cards(args, raw_data):
9 return (
10 FunctionResult("You have blackjack!")
11 .swml_user_event({
12 "type": "cards_dealt",
13 "player_hand": ["Ace", "King"],
14 "dealer_hand": ["7", "hidden"],
15 "player_score": 21
16 })
17 )
18
19agent.serve()