Intermediate9 min
Few-Shot Examples for Agent Tasks
Using few-shot examples to teach agents complex behaviors: example trajectories, tool call demonstrations, and dynamic example selection.
Quick Reference
- →Few-shot examples for agents include full trajectories: user query → tool calls → observations → final response
- →Place 2-3 examples in the system prompt showing the ideal reasoning and tool usage pattern for your domain
- →Use dynamic example selection: embed the user query, retrieve the most relevant examples from a library, inject into the prompt
- →Examples teach formatting, tool selection order, and reasoning depth more effectively than instructions alone
- →Balance example count vs context budget — each trajectory example consumes 200-500 tokens
Why Trajectory Examples Work
Regular few-shot examples show input → output. Agent few-shot examples show the full trajectory: input → reasoning → tool call → observation → more reasoning → final output. This teaches the LLM not just what to answer, but how to think through the problem.
| Example type | What it teaches | Token cost | Effectiveness |
|---|---|---|---|
| Input → Output | What to say | Low (50-100 tokens) | Low for agents — doesn't show reasoning |
| Input → Tool → Output | Which tool to use | Medium (150-300 tokens) | Medium — shows tool selection but not iteration |
| Full trajectory | How to think and iterate | High (300-500 tokens) | High — teaches the complete reasoning pattern |