Few-Shots
Few-Shots
Custom interactions are naturally diverse–especially across different business verticals–and your agent should be able to adapt to each situation while staying true to the guidelines and tools you’ve set, according to your intentions. However, guidelines alone may not always suffice. Conversations can take unexpected turns, and sometimes guidelines might be misapplied or misinterpreted due to their limited context or wording.
To fill this room for interpretation, Parlant uses a prompting technique called few-shots. Few-Shots allow you to provide examples within a prompt to guide your agent’s behavior to improve its ability to follow instructions in accordance with your expectation. They clarify intent, add depth, and help the agent interpret and apply guidelines more effectively, even in edge-cases. It’s worth noting, however, that few-shots are not strictly necessary. They’re an advanced feature, best suited for refining and enhancing your agent’s performance in scenarios where clearer contextual understanding is required. For a deeper dive into few-shots, check out this guide
Parlant’s engine has built-in shots baked into it. While these shots are researched to be as comprehensive as possible for general applicability—making them a great starting point for most applications—they don’t guarantee perfection. That’s why we’ve made it easy to integrate your own custom shots into your application, allowing you to tune your agent’s behavior to enhance its effectiveness and consistency.
In the following sections, we’ll explore how few-shots are implemented in Parlant, and how you can expand Parlant’s capabilities by adding your own shots. These shots can make a big difference, like helping your agent format responses more consistently, prioritize key guidelines, handle nuanced or idiosyncratic conversations, and use tools more effectively. With these customizations, you can ensure your agent is precise, reliable, and always aligned with your goals.
Our Approach to LLM Reasoning
We take a unique approach to reasoning in our LLM. Traditional methods like Chain-of-Thought (CoT) rely on an open-ended process in which models are instructed to generate their own planning and reasoning with little guidance.
However, as prompts grow more complex (e.g., more instructions or longer, interactive conversations), this free-form approach often struggles to attend to various relevant information and instructions in the prompt. This is because, In addition to considering the conversation itself and its subtle contextual instructions, it’s also biased by its own unconstrained outputs and reasoning process, which may easily diverge from the intended thought process, leading to inconsistencies in behavior and outputs.
To solve these challenges, we’ve devised a new approach (a research paper is coming soon), which we call Attentive Reasoning Queries (ARQs). ARQs are like reasoning blueprints we give the LLM in order to generate a structured reasoning process with more guidance and specificity. It involves a series of systematic questions, reminders, and validations that guide the LLM to follow a reasoning process that’s more true to the context.
Finally, note that ARQs in Parlant are being improved between versions to improve out-of-the-box behavior. For this reason, if you decide to implement your own custom shots, please keep in mind that you may have to adapt them when upgrading to a newer version. Additionally, it is always a good idea to jump on our Discord server and get advice on how to implement shots effectively.
This guide may come out of sync every now and then because of this continuous improvement process. For this reason, we will focus here on the more stable aspects of each shot class, explaining the principles and motivations behind it, rather than the nitty-gritty changing details.
Guideline Matching Shots
Guideline Matching Shots help the agent understand and evaluate the relevance of a guideline. You provide it with a set of guideline examples, along with a sample conversation where those guidelines are evaluated. For each sample, you add your expected evaluation, explaining why some guidelines stand out as more effective or relevant compared to the others in the set.
Core Structure
This shot is composed of four key components:
from parlant.core.engines.alpha import GuidelineMatchingShot
GuidelineMatchingShot(
description=SHOT_PURPOSE_AND_CONTEXT,
guidelines=EXAMPLE_GUIDELINES_FOR_THIS_SHOT,
interaction_events=EXAMPLE_CONVERSATION_FLOW_FOR_THIS_SHOT,
expected_result=EVALUATION_SCHEMA_FOR_THIS_SHOT,
)
description
: The description should explain the unique value this shot adds with respect to the GuidelineMatcher
’s ability to understand and respond to nuances.
For example, “Avoiding repetitive responses to not sound too robotic.”
guidelines
: A set of guideline examples provided to your shot.
interaction_events
: A conversation example used as the context for evaluating the shot’s guidelines. Define a sequence of message events between the ai_agent
and the customer
. Make sure that the conversation ends with a customer event.
expected_result
: The expected output of the evaluation. This is where you can define and explain the nuanced applicability of each guideline within the context of the conversation example. To set up these evaluations, use the GuidelineMatchingSchema
class.
Message Event Composition Shots
Message Event Composition Shots help you tune agent responses throughout a conversation and teach the agent how to more precisely implement specific guidelines or respond in specific conversational scenarios.
These shots incorporate multiple evaluation schemas, teaching your agent how to address customer needs in relation to available information and evaluate instructions for guidelines in order to determine the best course of action by providing examples on how to respond in those example situations.
Core Structure
This shot is initialized with two essential components:
from parlant.core.engines.alpha.message_event_generator import MessageEventCompositionShot
MessageEventCompositionShot(
description=SHOT_PURPOSE_AND_CONTEXT,
expected_result=EVALUATION_SCHEMA,
)
expected_result
: A detailed evaluation schema that guides how your agent verifies and forms a message. This schema considers the last message received from the customer,
evaluates any relevant guidelines that should be triggered, and analyzes the example responses you define in order to craft a concise reply. To create this schema, use the MessageEventSchema
class from the core library, passing in all the necessary parameters.
In addition to the main schema, there are component classes that you’ll use to refine the evaluation process. The InstructionEvaluation
class lets you evaluate the relevance of each guideline individually within the shot.
Tool Call Inference Shots
Tool Call Inference Shots allow you to improve the evaluation of tools used within conversations, teaching your agents which tools are most suitable based on the customer's request and the associated guidelines, as well as how to properly parameterize their calls.
For example, if a guideline is associated with multiple tools, and one offers a more suitable function than the others, you can train the agent to prioritize the most effective tool for the situation. Consider a scenario where a customer asks about a laptop with a specific Intel chip, in which two tools are available: one that processes "laptop" as its argument and another that takes both "laptop" and the chip name as separate arguments. In this case, you would probably want the agent to use the tool that activates the more specific query.
Using the Tool Call Inference Shot, you can teach the agent with examples, emphasizing why certain tools are more suitable to specific customer requests. This helps the agent match and prioritize tools effectively, ensuring it selects the option best suited to provide consistent and contextually accurate answers.
Core Structure
This shot is initialized with two essential components:
from parlant.core.engines.alpha.tool_caller import ToolCallerInferenceShot
ToolCallerInferenceShot(
description=DESCRIPTION_OF_THE_CONTEXT,
expected_result=EXPECTED_OUTCOME_SCHEMA"
)
description
: A brief, free-form description of the context, such as what is the tool being evaluated (the “candidate tool”) and under what circumstances.
expected_result
: An evaluation schema detailing how your agent should understand and use tools based on context, subtleties, and any reference tools you’ve set.
It includes multiple assessments to help the agent decide when and how to use a tool effectively in different situations.
Implementation and Use Cases
Recall that shots in Parlant are regularly researched and updated to improve performance. It’s important to stay up to date with the latest version to ensure compatibility and take advantage of these improvements.
Add your shots to Parlant’s engine with the ShotCollection class in the initialize_module :
#yam please insert code here
We encourage you to take a look at our built-in few-shots. Keep in mind that these are regularly updated to improve performance, so it’s important to stay up to date.
Built-in Few-Shots
#yam please insert code here