Package com.tnsai.annotations
Annotation Interface ToolExample
Defines an example for a tool/action to help LLMs understand usage patterns.
Tool examples significantly improve LLM accuracy when calling tools, especially for complex parameter handling. Anthropic reports that tool use examples improved accuracy from 72% to 90% on complex parameter handling in their internal testing — see the engineering blog link below for the source.
Usage
@ActionSpec(
type = ActionType.LLM,
description = "Searches academic papers on arXiv",
examples = {
@ToolExample(
description = "Search for recent papers on transformers",
input = "{\"query\": \"transformer architecture\", \"maxResults\": 5}",
output = "Found 5 papers: 1. Attention Is All You Need..."
),
@ToolExample(
description = "Search with date filter",
input = "{\"query\": \"LLM agents\", \"yearFrom\": 2023}",
output = "Found 12 papers from 2023 onwards..."
)
}
)
public ActionResult searchPapers(String query, int maxResults, Integer yearFrom) {
return result;
}
Best Practices
- Provide 2-3 examples covering common use cases
- Include edge cases and complex parameter combinations
- Use realistic input/output values
- Add negative examples to show what NOT to do
- Since:
- 0.3.0
- Author:
- TnsAI Team
- See Also:
-
Required Element Summary
Required Elements -
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionBrief description of what this example demonstrates.booleanWhether this is a negative example (showing what NOT to do).Expected output or result description.Explanation for negative examples - why this is wrong.
-
Element Details
-
description
String descriptionBrief description of what this example demonstrates. Should clearly state the use case or scenario.- Returns:
- example description
- Default:
""
-
input
String inputExample input as JSON string. Should match the tool's parameter schema.Example:
"{\"query\": \"machine learning\", \"limit\": 10}"- Returns:
- JSON input string
-
output
String outputExpected output or result description. Can be actual output or a description of what to expect.- Returns:
- output string
- Default:
""
-
negative
boolean negativeWhether this is a negative example (showing what NOT to do). Negative examples help LLMs avoid common mistakes.- Returns:
- true if this is a negative/bad example
- Default:
false
-
whyBad
String whyBadExplanation for negative examples - why this is wrong. Only applicable whennegative = true.- Returns:
- explanation of why this example is wrong
- Default:
""
-