<anam-agent> element dispatches standard DOM Custom Events that cross the Shadow DOM boundary, so you can listen to them with addEventListener on the element itself or any ancestor. Event data is available on event.detail.
Listening to events
Events reference
| Event Name | Payload | Description |
|---|---|---|
anam-agent:session-started | { sessionId: string } | A WebRTC session has been established. |
anam-agent:session-ended | { sessionId: string, reason: string } | The session has ended (user-initiated or server-side). |
anam-agent:message-received | { role: "user" | "agent", content: string } | A transcript message was received from either party. |
anam-agent:message-sent | { content: string } | The user sent a text message via the input field. |
anam-agent:expanded | {} | The widget was expanded (floating layout only). |
anam-agent:collapsed | {} | The widget was collapsed (floating layout only). |
anam-agent:error | { code: string, message: string } | An error occurred (auth failure, network issue, etc.). |
anam-agent:mic-muted | {} | The user muted their microphone. |
anam-agent:mic-unmuted | {} | The user unmuted their microphone. |
anam-agent:tool-call-started | { toolName: string, toolCallId: string, toolType: string, toolSubtype?: string, arguments: object } | The persona invoked a tool. |
anam-agent:tool-call-completed | { toolName: string, toolCallId: string, toolType: string, toolSubtype?: string, result: unknown, executionTime: number, documentsAccessed?: string[] } | A tool call finished successfully. |
anam-agent:tool-call-failed | { toolName: string, toolCallId: string, toolType: string, toolSubtype?: string, errorMessage: string, executionTime: number } | A tool call failed. |
toolType is "client" for browser-side tools and "server" for tools that run on Anam’s side. The optional toolSubtype further identifies the tool and is currently set for server tools, such as "webhook" or "knowledge". executionTime is in milliseconds, and documentsAccessed is present only for knowledge (RAG) tools.
Reacting to tool calls
When your persona invokes a tool, the widget surfaces the tool-call lifecycle as DOM events, so your page can react to it without wiring up the JavaScript SDK directly. Use thetoolType field to act only on client-side tools (those meant to run in the browser, such as navigation or cart updates) and ignore server-side tools (webhook and knowledge tools that run on Anam’s side):
tool-call-completed and tool-call-failed events report the outcome of each call, which is useful for logging and analytics:
These are notification events — the widget reports tool calls but does not send a value back to the persona. Use client-side tools with the widget as fire-and-forget actions (
awaitResult: false). If you need to return a result to the LLM, integrate with the JavaScript SDK’s registerToolCallHandler instead of the embed widget.Common patterns
Analytics tracking
Analytics tracking
Track session starts, message counts, and engagement duration:
Show or hide page elements
Show or hide page elements
React to widget expand/collapse to adjust your page layout:
Error handling
Error handling
Display user-facing messages or trigger fallback behavior:

