Parlant

repository·develop·Indexed 12 days ago

https://github.com/emcie-co/parlant

An interaction control harness for customer-facing AI agents that uses context engineering to provide precise behavioral control. Parlant dynamically assembles focused context for LLMs using Guidelines, Observations, Journeys (SOPs), and Canned Responses to ensure agents remain consistent, compliant, and on-brand. It includes a Python SDK and supports integration with Azure OpenAI and frameworks like LangGraph and LlamaIndex.

Tokens
74.6K
Snippets
209
Records
276
Agent score
97%

What's inside Parlant

  1. What is a Session in Parlant

    develop

    A session represents a continuous, structured interaction between an agent and a customer. Unlike many frameworks that assume a rigid turn-by-turn model (Message $\rightarrow$ Reply), Parlant uses a Modern Interaction Model that supports real-world conversational patterns, such as:

    • Multiple customer messages sent before an agent responds.
    • Agent-initiated follow-ups or status updates (e.g., putting a customer on hold).
    • Asynchronous events like tool calls and status indicators.

    Sessions encapsulate the entire conversation history, including message history, status indicators, frontend events, and tool results. This built-in history serves as the agent's 'memory', allowing it to remain aware of the full context to apply instructions and generate appropriate responses.

  2. What is Agentic Behavior Modeling (ABM)?

    develop

    Agentic Behavior Modeling (ABM) is an approach to controlling how AI agents interact with users by using a structured, custom-tailored set of principles, actions, objectives, and ground-truths.

    Unlike traditional approaches, ABM provides:

    • High Adaptability: Unlike rigid flow engines (flowcharts), ABM dynamically adapts to natural user interaction patterns while conforming to business rules.
    • High Predictability: Unlike free-form prompt engineering or RAG, which can lead to inconsistent behavior, ABM uses clear semantic structures and annotations to ensure conformance to business rules.

    A complete Behavior Model in Parlant can include:

    • Guidelines
    • Journeys
    • Tools
    • Capabilities
    • Glossary
    • Variables
    • Semantic Relationships
    • Canned Responses
  3. Understand Tool Calling complexities and failure patterns

    develop

    When agents use tools (functions), they must determine parameters from conversational context rather than explicit specs. This leads to several common failure patterns:

    • Missing Information: The agent attempts to call a tool without all required parameters, leading to hallucinations.
    • Type Confusion: Passing incorrect data types (e.g., a string instead of an integer).
    • Context Misinterpretation: Using the wrong entity when multiple exist in the conversation.
    • False Positive Bias: Calling the first tool that seems relevant rather than the most appropriate one.

    Parlant provides controls to guide contextual relevance and parameterization expectations to mitigate these risks.

  4. How the Guideline processing pipeline works

    develop

    Guidelines are evaluated and matched before the agent composes its response. The processing flow follows this sequence:

    1. Engine receives a message.
    2. GuidelineMatcher matches relevant guidelines.
    3. ToolCaller calls any associated tools.
    4. MessageComposer composes the final message based on the matched guidelines and tool outputs.
    5. Engine returns the generated response.

    Important Constraint: Because guidelines are evaluated before response generation, you cannot easily use guidelines that require temporal sequencing, such as "Do X immediately after you've done Y."

  5. Design effective Guidelines with precision

    develop

    Effective guidelines must avoid vagueness to prevent undesirable behaviors (like unauthorized discounts or inappropriate styles). When creating guidelines, focus on three dimensions of specificity:

    • Condition Precision: Define exactly when the guideline applies. Use specific triggers like "Customer has explicitly declined..." instead of vague states like "Customer is unhappy".
    • Action Clarity: Provide concrete, actionable instructions. Instead of "provide some alternatives", use "provide the three closest available time slots".
    • Action Temporal Scope: Specify how long the guideline's effect lasts (e.g., "...throughout the conversation", "...immediately", or "...until the customer has [condition]").
  6. How guidelines work in Parlant

    develop

    A guideline is the fundamental modeling entity in Parlant used to nudge an AI agent on how to approach specific situations. Instead of using a single large system prompt, you define granular guidelines that consist of two parts:

    1. Condition: Describes the circumstances in which the guideline should apply.
    2. Action: Describes what the agent should do when the condition is met.

    Key Features of Guidelines:

    • Automatic Selection: Parlant automatically filters and selects the most relevant guidelines for any given situation based on the condition and action.
    • State Awareness: Parlant tracks whether a guideline has already been applied to prevent unnecessary repetition.
    • Applicability Types: It distinguishes between guidelines that are always applicable and those that are only applicable once per conversation.
    • Enforcement & Explainability: Parlant enforces matched guidelines and provides logs explaining how the agent interpreted the situation and the guidelines.
    await agent.create_guideline(
      condition="you have suggested a solution that did not work for the user",
      action="ask if they'd prefer to talk to a human agent, or continue troubleshooting with you",
    )
  7. How tools and guidelines work together in Parlant

    develop

    In Parlant, tools are not called based on the LLM's judgment alone. Instead, they are tightly integrated with the guidance system. A tool only executes when its associated guideline is matched to the conversation.

    This creates a separation of concerns:

    • Guidelines (the 'Button'): Determine the when and why (the intent/condition).
    • Tools (the 'API function'): Handle the how (the business logic/execution).

    By associating tools with specific guidelines, you prevent the false-positive tool calls common in standard LLM implementations. You can explicitly define the relationship using agent.create_guideline or let Parlant infer the association from the tool's description using agent.attach_tool.

    # Explicitly connecting a tool to a guideline
    await agent.create_guideline(
        condition=CONDITION,
        action=ACTION,
        tools=[my_tool],
    )
    
    # Or letting Parlant infer the association from the tool description
    await agent.attach_tool(condition=CONDITION, tool=my_tool)
  8. Handle session event types

    develop

    When monitoring events, you should handle different kind values to update your UI:

    • message: Contains the actual conversation content. The event.source indicates who sent it (customer, ai_agent, or human_agent). For human_agent messages, the event.data.participant.display_name is available.
    • status: Indicates the current state of the agent. Common values include processing, typing, and ready.
  9. Implement custom authorization policies in Parlant

    develop

    To secure a production deployment, you can implement custom authorization logic by subclassing AuthorizationPolicy or, more commonly, by extending ProductionAuthorizationPolicy.

    The AuthorizationPolicy Interface

    All policies must implement the following abstract methods:

    • check_permission(request, permission): Returns True if the request has permission for the specific AuthorizationPermission.
    • check_rate_limit(request, permission): Returns True if the request is within allowed frequency limits.
    • authorize(request, permission): A combined check that calls both methods above. This is typically not overridden as its default behavior is to raise an authorization error if either check fails.

    Instead of building from scratch, subclass ProductionAuthorizationPolicy. This allows you to leverage existing production rules while adding custom logic, such as JWT validation or Machine-to-Machine (M2M) token support.

    class AuthorizationPolicy:
        @abstractmethod
        async def check_permission(
            self,
            request: fastapi.Request,
            permission: AuthorizationPermission
        ) -> bool:
            ...
    
        @abstractmethod
        async def check_rate_limit(
            self,
            request: fastapi.Request,
            permission: AuthorizationPermission
        ) -> bool:
            ...
    
        async def authorize(
            self,
            request: fastapi.Request,
            permission: AuthorizationPermission
        ) -> None:
            ...
  10. Distinguish between Glossary, Guidelines, and Agent Description

    develop

    To shape agent behavior effectively, understand the distinct roles of these three components:

    1. Glossary: Teaches the agent "what things are" (vocabulary/static knowledge). Example: "A Club Member is a guest who has stayed with us more than 5 times."
    2. Guidelines: Teaches the agent "how to act in situations" (behavioral rules). Example: "When speaking with Club Members, acknowledge their loyalty status."
    3. Agent Description: Provides the overall context, role, and personality (static persona). Example: "You are a helpful hotel booking assistant for Boogie Nights."

    In short: The glossary builds vocabulary, guidelines shape behavior, and the description sets the tone.

  11. How the glossary interacts with guidelines

    develop

    The glossary is not just for customer understanding; it is also used by the agent to interpret its own Guidelines. When a guideline's condition or action contains specific terminology, the agent uses the glossary to resolve those terms.

    For example, if a guideline triggers when a user asks about "Ocean View rooms", and "Ocean View" is defined in the glossary, the agent can correctly map user phrases like "rooms with a view to the Atlantic" to that guideline.

    # The guideline relies on the terms defined below
    await agent.create_guideline(
        condition="the user asks about Ocean View rooms",
        action="explain the Sunrise Package benefits",
    )
    
    # The glossary provides the necessary context for the guideline to function
    await agent.create_term(
        name="Ocean View",
        description="Our premium rooms on floors 15-20 facing the Atlantic",
        synonyms=["seaside rooms", "beach view"],
    )
    
    await agent.create_term(
        name="Sunrise Package",
        description="Complimentary breakfast and early check-in for Ocean View bookings",
        synonyms=["morning special", "sunrise special"],
    )
  12. How Parlant's context engineering works

    develop

    Unlike traditional LLM applications that use large, static system prompts, Parlant uses an engine to dynamically assemble a focused context for each conversational turn.

    Instead of overwhelming the model with all possible instructions, the engine matches only the relevant components based on the current interaction. The core components used for context assembly include:

    • Observations: Events that trigger specific tools or behaviors.
    • Guidelines: Behavioral rules defined as condition-action pairs.
    • Journeys (SOPs): Multi-turn standard operating procedures that adapt to user interaction.
    • Retrievers: Domain knowledge used to augment context.
    • Glossary: Domain-specific vocabulary.
    • Variables: Memories or stateful information.

    This approach ensures that adding more rules makes the agent smarter rather than more confused, as the engine filters for relevance before the LLM ever sees the prompt.