Agent Chat SDK
Actions
Register handlers for agent tool calls to trigger behavior in your app.
Actions let you respond to tool calls made by the agent during a conversation. When the agent invokes a tool, your registered handler runs and returns a result back to the agent.
Registering an action
import { registerAction } from '@zelto/agent-chat-sdk';
registerAction('showPricingPage', async (params) => {
window.location.href = '/pricing';
return { success: true, message: 'Navigated to pricing' };
});The handler receives any parameters the agent passes and must return an ActionResult:
type ActionHandler = (
params: Record<string, unknown>
) => Promise<{
success: boolean;
message?: string;
data?: unknown;
}>;Unregistering an action
import { unregisterAction } from '@zelto/agent-chat-sdk';
unregisterAction('showPricingPage');Example: opening a modal
registerAction('openContactForm', async (params) => {
const modal = document.getElementById('contact-modal');
if (modal) {
modal.style.display = 'block';
return { success: true };
}
return { success: false, message: 'Modal not found' };
});How it works
- The user sends a message in the chat widget.
- The agent decides to call a tool (e.g.
showPricingPage). - The SDK receives a
tool_callevent via WebSocket. - Your registered handler is invoked with the tool's parameters.
- The result is sent back to the agent, which can use it to continue the conversation.
If no handler is registered for a tool call, the SDK ignores it.