withContext
Provides domain-specific context and background knowledge to the agent. Context gives the agent essential information about the domain it’s operating in, including facts, conventions, operational details, and any other background knowledge needed to respond appropriately. This is critical for specialized agents that need to understand specific business rules, industry practices, or organizational details. Context differs from identity and capabilities:- Identity: Who/what the agent is
- Capabilities: What the agent can do
- Context: What the agent needs to know
Contextual information for the agent. Can be multi-line. Should contain factual, relevant information that helps the agent understand its operating environment.
The builder instance for method chaining
Examples
- Medical Scheduling
- E-commerce
- Financial Services
withExamples
Provides examples of desired agent behavior through few-shot learning. Examples are one of the most effective techniques for teaching an AI agent how to behave. By showing concrete input-output pairs, you demonstrate the exact pattern of responses you want. This is especially powerful for:- Establishing consistent response style
- Demonstrating proper tool usage
- Showing how to handle edge cases
- Teaching domain-specific interaction patterns
An array of Example objects showing input-output pairs. Use either
user/assistant (conversational) or input/output (functional). Include explanation to clarify what the example demonstrates.The builder instance for method chaining
Examples
- Tool Usage
- Response Style
- Accumulating Examples
withErrorHandling
Defines how the agent should handle uncertainty, errors, and ambiguous situations. This method specifies the agent’s behavior when it encounters situations it’s not confident about, including:- Ambiguous user requests
- Missing required information
- Uncertainty about the correct response
- Error conditions
- Requests outside its capabilities
- Hallucinations (making up information when uncertain)
- Inappropriate assumptions
- Unhelpful or incorrect responses
- Poor user experience during edge cases
Clear guidelines for handling uncertainty and errors. Should specify what the agent should do when it encounters various types of problematic situations. Can be multi-line for complex instructions.
The builder instance for method chaining
Examples
- Basic
- Comprehensive
- Domain-Specific