Skip to Content
🎉 Welcome to handit.ai Documentation!
TracingTracing GuideAgent Wrapper/Decorator

Agent Wrapper/Decorator Tracing

The easiest way to trace complete AI workflows. Agent wrappers automatically capture your entire agent execution from start to finish with just one decorator or wrapper function.

Perfect for main application entry points like API endpoints, chat handlers, and workflow orchestrators where you want comprehensive observability with minimal code changes.

Agent wrappers are the most convenient tracing method—add one decorator and get complete visibility into your AI agent workflows, including all nested operations.

How It Works

Agent wrapper tracing provides comprehensive coverage by:

  • Wrapping entire workflows - Captures complete execution from start to finish
  • Automatic context management - Links all child operations together seamlessly
  • Universal compatibility - Works with both sync and async functions
  • Built-in error tracking - Captures and reports errors with full context
  • Performance monitoring - Records execution time and resource usage

Implementation

Python: @start_agent_tracing()

JavaScript: startAgentTracing()

agent_wrapper.js
const { config, startAgentTracing } = require('handit-sdk'); config({ apiKey: 'your-api-key' }); // Define your agent function async function ecommerceRecommendationAgent(userId, productCategory) { // Step 1: Get user preferences const userPreferences = await getUserPreferences(userId); // Step 2: Fetch product catalog const products = await getProductCatalog(productCategory); // Step 3: Generate recommendations using ML model const recommendations = await generateRecommendations( userPreferences, products ); // Step 4: Personalize and rank const personalizedRecs = await personalizeRecommendations( recommendations, userId ); return { recommendations: personalizedRecs, userId: userId, category: productCategory }; } // Wrap with agent tracing const trackedRecommendationAgent = startAgentTracing(ecommerceRecommendationAgent); // Usage - automatically traces the entire workflow const recommendations = await trackedRecommendationAgent("user123", "electronics");

Real-World Examples

Multi-Modal AI Assistant

Error Handling with Agent Wrappers

What Gets Tracked

When you use agent wrappers, Handit.ai automatically captures:

Data TypeWhat’s Captured
📊 Execution DataComplete function input/output, execution timing, success/failure status, performance metrics
🔗 Context LinkingAll nested function calls, LLM interactions, tool executions, error propagation

Agent wrappers provide the most comprehensive tracing with minimal code changes. Just add one decorator/wrapper and get complete visibility into your AI workflows.

Best Practices

Implementation Guidelines:

  1. Use for main entry points - Wrap your primary agent functions that handle complete workflows
  2. Keep functions focused - Each wrapped function should represent a complete, cohesive workflow
  3. Handle errors gracefully - Let the wrapper track errors while you handle them appropriately
  4. Combine with node tracing - Use node decorators for detailed sub-function tracking when needed

Next Steps

Last updated on