withAgent()
Wrap an async function as a traced agent
Overview
Use withAgent(options, fn) for agentic patterns where an agent orchestrates multiple tools or sub-tasks. Agents are specialized workflow units designed for AI agent architectures.
Signature
Basic Usage
Agent with Tools
Multi-Agent Workflow
With OpenAI Integration
Parameters
name
Agent display name for identification in the Respan dashboard
version
Version number for tracking agent iterations
associationProperties
Custom metadata to associate with the agent (agent type, model, user context, etc.)
Return Value
Returns a Promise that resolves to the return value of the provided function.
Best Practices
- Use agents for autonomous decision-making components
- Nest tools within agents to track tool usage
- Add association properties to identify agent types and contexts
- Combine multiple agents in workflows for complex multi-agent systems
- Agents automatically capture all nested tool calls and LLM interactions