Events
React to agent lifecycle events
Agents emit events you can listen to – track progress, log activity, and extend behavior.
Quick Start
- Simple Usage
typescript 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'); - With Configuration
typescript 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
| Event | When |
|---|---|
start | Agent begins processing |
message | Agent produces output |
tool_call | Agent calls a tool |
error | Something goes wrong |
complete | Agent finishes |
API Reference
Events ModuleComplete events module
AgentEventBusEvent bus class
Best Practices
Log important events
Track tool calls and errors for debugging.
Use wildcards sparingly
Subscribe to specific events for better performance.
Handle errors
Always listen for ‘error’ events in production.