Parlant: Build AI Agents That Follow Rules, Not Prompts

8月21日 Published inAI Agent Tools

Parlant is an open-source behavior modeling engine designed for LLM agents. It enables developers to deploy conversational agents that interact with customers exactly as intended. The framework provides the structural discipline required for production-grade chatbots.

The Problem Developers Face

An agent may pass every internal test suite, yet falter the moment it encounters real users. In production, performance often degrades quickly:

  • System prompts are frequently ignored or bypassed.
  • Hallucinations occur at critical moments.
  • Unforeseen edge cases disrupt the conversational flow.
  • Every interaction feels like a roll of the dice.

This unpredictability is the primary gap between a successful demo and a reliable, deployed AI agent. Parlant is built to close that gap.

How Parlant Fixes It

Parlant shifts the development paradigm. Instead of merely asking an LLM to follow instructions, it makes compliance the default state.

The traditional approach: Probability 🤞

system_prompt = "You are a helpful assistant. Follow these 47 rules..."

The Parlant approach: Enforcement

await agent.create_guideline(
    condition="customer asks about a refund",
    action="first check order status to see if they qualify",
    tools=[check_order_status],
)

Core Capabilities

Conversation Journeys
Map out specific customer flows and define exactly how the agent should respond at each milestone.

Behavioral Guidelines
Define rules in plain language. Parlant dynamically matches the most relevant guidelines to the current conversation context.

Tool Binding
Link external APIs, data fetchers, or backend services to specific interaction events with precision.

Domain Adaptation
Equip the agent with industry-specific terminology and shape replies to match a personalized brand voice.

Hard-Coded Responses
Utilize response templates to eliminate hallucinations and maintain a consistent communication style.

Explainability
Trace which guideline was triggered and why. Every agent decision is transparent and auditable.

Install and Run

1. Install Parlant

pip install parlant

2. Write Some Code

import parlant.sdk as p

@p.tool
async def get_weather(context: p.ToolContext, city: str) -> p.ToolResult:
    # Your weather API logic goes here
    return p.ToolResult(f"{city}: sunny, 72°F")

async def main():
    async with p.Server() as server:
        agent = await server.create_agent(
            name="WeatherBot",
            description="A helpful weather assistant"
        )

        # Define behavior in plain English
        await agent.create_guideline(
            condition="user asks about the weather",
            action="fetch the current weather and reply with a friendly suggestion",
            tools=[get_weather]
        )

        # Test UI is ready at http://localhost:8800
        # Embed the official React components or build your own frontend

if __name__ == "__main__":
    import asyncio
    asyncio.run(main())

Your agent is now operational and, more importantly, strictly follows your defined rules.

Traditional Frameworks vs. Parlant

Traditional AI Framework Parlant
Relies on complex system prompts Uses plain-English rules
Hopes for LLM compliance Guarantees compliance
Debugs unpredictable outputs Ensures consistent behavior
Scales via prompt engineering Scales by adding specific guidelines
High risk in production Production-ready from day one

Use Cases

Financial Services Healthcare E-commerce Legal Tech
Compliance-first design HIPAA-aligned interactions High-volume support Precise legal guidance
Built-in risk controls Patient data protection Automated order processing Document review support

Enterprise-Grade Features

  • Conversation Journeys: Guide customers through multi-step processes.
  • Dynamic Guideline Matching: Rules are applied intelligently based on context.
  • Reliable Tool Integration: Connect directly to APIs, databases, and external services.
  • Conversation Analytics: Inspect and audit agent behavior in real time.
  • Iterative Refinement: Improve response accuracy over time through feedback.
  • Built-in Guardrails: Effectively block hallucinations and off-topic tangents.
  • React Components: Quickly integrate a chat interface into any web application.
  • Full Explainability: Understand the logic behind every agent decision.

Create Your First Agent

Once installed, start with a basic agent configuration and layer in behaviors as needed.

# main.py
import asyncio
import parlant.sdk as p

async def main():
    async with p.Server() as server:
        agent = await server.create_agent(
            name="Otto Carmen",
            description="You work at a car dealership",
        )

asyncio.run(main())

Parlant utilizes async/await patterns, allowing your application to handle multiple tasks concurrently—essential for high-traffic production environments.

By default, Parlant uses OpenAI for natural language processing. Ensure your API key is set before running.

export OPENAI_API_KEY="<your-api-key>"
python main.py

Using Other LLM Providers

Parlant supports several providers out of the box. These can be accessed via p.NLPServices, or you can implement the p.NLPService interface to use a custom backend.

To specify a provider, pass it during server initialization:

async with p.Server(nlp_service=p.NLPServices.cerebras) as server:
    ...

Note that some providers may require additional packages:

pip install parlant[cerebras]

Current testing indicates that OpenAI and Anthropic models offer the most reliable performance for completions and JSON schema adherence. It is recommended to start with one of these.

Test the Agent

Navigate to http://localhost:8800 to access the built-in UI. Start a new session to begin interacting with your agent.

Write Your First Guideline

Guidelines are the foundation of Parlant’s behavior model. They instruct the agent on how to react to specific inputs or environmental conditions. Parlant manages the context of these guidelines internally, meaning you can add a high volume of rules without encountering context window issues or scaling bottlenecks.

# main.py
import asyncio
import parlant.sdk as p

async def main():
    async with p.Server() as server:
        agent = await server.create_agent(
            name="Otto Carmen",
            description="You work at a car dealership",
        )
        ##############################
        ##    Add this part:        ##
        ##############################
        await agent.create_guideline(
            condition="customer greets you",
            action="offer them a cold drink",
        )

asyncio.run(main())

Rerun your script:

python main.py

Refresh the UI at http://localhost:8800, start a new session, and test the new greeting logic.

Use the Official React Components

For teams building a React-based frontend, the official Parlant component provides the fastest integration path.

import React from 'react';
import ParlantChatbox from 'parlant-chat-react';

function App() {
  return (
    <div>
      <h1>My Application</h1>
      <ParlantChatbox
        server="PARLANT_SERVER_URL"
        agentId="AGENT_ID"
      />
    </div>
  );
}

export default App;

Parlant provides the necessary scaffolding to move AI agents from experimental demos to reliable production tools. By replacing fragile prompts with enforceable guidelines, your agents become predictable, traceable, and ready for the real world.