multi-agent-attribution.ts
1 /** 2 * Multi-Agent Attribution Example 3 * 4 * Demonstrates tracking agent_id, run_id, and trace_id across 5 * multi-agent workflows for proper attribution. 6 */ 7 8 import { Agent, Agents, MemoryObservabilityAdapter, setObservabilityAdapter } from 'praisonai'; 9 10 async function main() { 11 // Create memory adapter 12 const obs = new MemoryObservabilityAdapter(); 13 setObservabilityAdapter(obs); 14 15 // Create agents 16 const researcher = new Agent({ 17 name: 'Researcher', 18 instructions: 'Research topics and gather information.' 19 }); 20 21 const writer = new Agent({ 22 name: 'Writer', 23 instructions: 'Write clear summaries based on research.' 24 }); 25 26 // Create multi-agent workflow 27 const agents = new Agents({ 28 agents: [researcher, writer], 29 tasks: [ 30 { agent: researcher, description: 'Research: {topic}' }, 31 { agent: writer, description: 'Summarize the research findings' } 32 ] 33 }); 34 35 console.log('Running multi-agent workflow with attribution...\n'); 36 37 await agents.start({ topic: 'TypeScript best practices' }); 38 39 // View traces with attribution 40 const traces = obs.getAllTraces(); 41 42 console.log('\n=== Attribution Report ==='); 43 for (const trace of traces) { 44 console.log(`\nTrace ID: ${trace.id}`); 45 console.log(` Name: ${trace.name}`); 46 47 if (trace.attribution) { 48 console.log(` Agent ID: ${trace.attribution.agentId || 'N/A'}`); 49 console.log(` Run ID: ${trace.attribution.runId || 'N/A'}`); 50 console.log(` Session ID: ${trace.attribution.sessionId || 'N/A'}`); 51 } 52 53 console.log(` Spans: ${trace.spans.length}`); 54 for (const span of trace.spans) { 55 console.log(` - [${span.kind}] ${span.name}`); 56 } 57 } 58 } 59 60 main().catch(console.error);