Skip to main content
Agents emit events you can listen to - track progress, log activity, and extend behavior.

Quick Start

1

Listen to Events

import { Agent } from 'praisonai';

const agent = new Agent({
  instructions: 'You are a helpful assistant'
});

agent.on('message', (event) => {
  console.log('Agent said:', event.content);
});

agent.on('tool_call', (event) => {
  console.log('Tool used:', event.name);
});

await agent.chat('Search for weather');
2

Track All Events

agent.on('*', (event) => {
  console.log(`[${event.type}]`, event.data);
});

User Interaction Flow


Configuration Levels

// Level 1: Method - Simple listener
agent.on('message', (e) => console.log(e));

// Level 2: Array - Multiple events
agent.on(['start', 'complete'], (e) => {
  console.log(`${e.type} at ${e.timestamp}`);
});

// Level 3: Instance - Event bus
import { AgentEventBus } from 'praisonai';

const bus = new AgentEventBus();

bus.subscribe('agent.*', (event) => {
  sendToAnalytics(event);
});

const agent = new Agent({ eventBus: bus });

Event Types

EventWhen
startAgent begins processing
messageAgent produces output
tool_callAgent calls a tool
errorSomething goes wrong
completeAgent finishes

API Reference

Events Module

Complete events module

AgentEventBus

Event bus class

Best Practices

Track tool calls and errors for debugging.
Subscribe to specific events for better performance.
Always listen for ‘error’ events in production.