Handoff
Handoff enables seamless transfer of conversation context between agents.Quick Start
Copy
import { Handoff, handoff, Agent } from 'praisonai';
const specialistAgent = new Agent({
name: 'Specialist',
instructions: 'You are a technical specialist.'
});
const myHandoff = handoff({
target: specialistAgent,
condition: (ctx) => ctx.input.includes('technical')
});
const mainAgent = new Agent({
name: 'Main',
instructions: 'You are a helpful assistant.',
handoffs: [myHandoff]
});
Configuration
Copy
interface HandoffConfig {
target: Agent;
condition: (ctx: HandoffContext) => boolean;
onHandoff?: (ctx: HandoffContext) => void;
}
interface HandoffContext {
input: string;
history: Message[];
metadata?: Record<string, any>;
}
Handoff Filters
Copy
import { handoffFilters } from 'praisonai';
// Built-in filters
const technicalHandoff = handoff({
target: techAgent,
condition: handoffFilters.containsKeywords(['code', 'debug', 'error'])
});
const urgentHandoff = handoff({
target: urgentAgent,
condition: handoffFilters.matchesPattern(/urgent|asap|emergency/i)
});
Example
Copy
import { Agent, handoff } from 'praisonai';
// Create specialized agents
const codeAgent = new Agent({
name: 'CodeExpert',
instructions: 'You are a coding expert.'
});
const supportAgent = new Agent({
name: 'Support',
instructions: 'You handle customer support.'
});
// Create main agent with handoffs
const mainAgent = new Agent({
name: 'Assistant',
instructions: 'You are a helpful assistant.',
handoffs: [
handoff({
target: codeAgent,
condition: (ctx) => /code|programming|debug/i.test(ctx.input),
onHandoff: (ctx) => console.log('Handing off to code expert...')
}),
handoff({
target: supportAgent,
condition: (ctx) => /help|support|issue/i.test(ctx.input)
})
]
});
CLI Usage
Copy
praisonai-ts handoff info

