Skip to main content
The <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

In the tool-call payloads, 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 the toolType 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):
The tool-call-completed and tool-call-failed events report the outcome of each call, which is useful for logging and analytics:
You still define and configure the tools on your persona in Anam Lab. See Client Tools and Events for how tools are created.
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

Track session starts, message counts, and engagement duration:
React to widget expand/collapse to adjust your page layout:
Display user-facing messages or trigger fallback behavior:
Last modified on June 25, 2026