Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
A comprehensive collection of Agent Skills for context engineering, multi-agent architectures, and production agent systems.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
examples/llm-as-judge-skills/tools/orchestration/delegate-to-agent.md
1# Delegate to Agent Tool23## Purpose45Route a task to a specialized agent for execution. Handles context passing, result collection, and error management.67## Tool Definition89```typescript10import { tool } from "ai";11import { z } from "zod";1213export const delegateToAgent = tool({14description: `Delegate a task to a specialized agent.15Use when a subtask requires specific capabilities.16Pass complete context needed for the agent to succeed.`,1718parameters: z.object({19agentName: z.enum(["evaluator", "researcher", "writer", "analyst"])20.describe("Name of the agent to delegate to"),2122task: z.string()23.describe("Clear description of what the agent should do"),2425context: z.object({26previousOutputs: z.array(z.string()).optional()27.describe("Outputs from prior steps this agent needs"),2829documents: z.array(z.string()).optional()30.describe("Relevant documents or data"),3132constraints: z.array(z.string()).optional()33.describe("Requirements or limitations to observe")34}).optional(),3536expectedOutput: z.object({37format: z.enum(["text", "json", "markdown", "structured"])38.describe("Expected output format"),3940schema: z.string().optional()41.describe("JSON schema if format is structured"),4243maxLength: z.number().optional()44.describe("Maximum length constraint")45}).optional(),4647timeout: z.number().default(60000)48.describe("Timeout in milliseconds")49}),5051execute: async (input) => {52return executeAgentDelegation(input);53}54});55```5657## Input Schema5859| Field | Type | Required | Description |60|-------|------|----------|-------------|61| agentName | enum | Yes | Target agent |62| task | string | Yes | Task description |63| context | object | No | Context and dependencies |64| expectedOutput | object | No | Output requirements |65| timeout | number | No | Timeout ms (default: 60000) |6667## Output Schema6869```typescript70interface DelegationResult {71success: boolean;7273agentName: string;74task: string;7576output: {77content: string | object;78format: string;79};8081execution: {82startTime: string;83endTime: string;84durationMs: number;85tokenUsage: {86prompt: number;87completion: number;88};89};9091error?: {92code: string;93message: string;94retryable: boolean;95};96}97```9899## Available Agents100101### Evaluator Agent102```typescript103await delegateToAgent.execute({104agentName: "evaluator",105task: "Evaluate the quality of this response against accuracy and clarity criteria",106context: {107documents: [responseToEvaluate],108constraints: ["Use 1-5 scale", "Include justification"]109},110expectedOutput: { format: "structured" }111});112```113114### Researcher Agent115```typescript116await delegateToAgent.execute({117agentName: "researcher",118task: "Research current best practices for LLM evaluation",119context: {120constraints: ["Focus on 2024 publications", "Include citations"]121},122expectedOutput: { format: "markdown" }123});124```125126### Writer Agent127```typescript128await delegateToAgent.execute({129agentName: "writer",130task: "Write an executive summary of these research findings",131context: {132previousOutputs: [researchFindings],133constraints: ["Maximum 500 words", "Non-technical audience"]134},135expectedOutput: { format: "text", maxLength: 2500 }136});137```138139### Analyst Agent140```typescript141await delegateToAgent.execute({142agentName: "analyst",143task: "Analyze the trade-offs between direct scoring and pairwise comparison",144context: {145documents: [evaluationData],146constraints: ["Quantitative where possible"]147},148expectedOutput: { format: "structured" }149});150```151152## Error Handling153154```typescript155const errorCodes = {156"AGENT_NOT_FOUND": "Specified agent does not exist",157"TIMEOUT": "Agent did not complete within timeout",158"CONTEXT_TOO_LARGE": "Context exceeds agent's capacity",159"INVALID_OUTPUT": "Agent output did not match expected format",160"AGENT_ERROR": "Agent encountered an error during execution"161};162```163164## Implementation Notes1651661. **Context Optimization**: Compress context if needed before passing1672. **Timeout Handling**: Set realistic timeouts per agent type1683. **Retry Logic**: Implement retries for transient failures1694. **Audit Trail**: Log all delegations for traceability1705. **Resource Management**: Track token usage across delegations171172