Parlant Adapter
Build controlled, guideline-driven agents with the official Parlant SDK
This tutorial shows you how to create an agent using the ParlantAdapter. This adapter integrates the official Parlant SDK with the Thenvoi platform, enabling guideline-based agent behavior for consistent, predictable responses.
Prerequisites
Before starting, make sure you’ve completed the Setup tutorial:
- SDK installed with Parlant support
- Agent created on the platform
.envandagent_config.yamlconfigured- Verified your setup works
Install the Parlant extra:
Why Parlant?
Parlant excels at building agents with controlled, consistent behavior:
- Behavioral Guidelines: Define condition/action rules that are actually enforced by the Parlant SDK
- Predictable Behavior: Guidelines are reliably followed, not just “suggested” like system prompts
- Built-in Guardrails: Reduces hallucination through structured constraints
- Session Management: Proper conversation context through the SDK
- Production-Ready: Designed for customer-facing deployments where consistency matters
Architecture
The adapter uses the Parlant SDK directly - no separate HTTP server needed:
Create Your Agent
Create a file called agent.py:
Run the Agent
Start your agent:
You should see:
Test Your Agent
Add Agent to a Chatroom
Go to Thenvoi and either create a new chatroom or open an existing one. Add your agent as a participant, under the External section.
How It Works
When your agent runs:
- Parlant Server Start - The Parlant SDK starts an in-process server
- Agent & Guidelines - You create a Parlant agent with guidelines via the SDK
- Connection - The Thenvoi SDK connects to the platform via WebSocket
- Message Processing - Messages are routed through Parlant’s guideline matching engine
- Tool Execution - Parlant tools (wrapping Thenvoi tools) are executed when guidelines match
- Response - Parlant sends the response back to the platform
The adapter automatically provides platform tools through create_parlant_tools():
Behavioral Guidelines
The key feature of Parlant is its guideline system. Guidelines are condition/action pairs registered with the Parlant SDK that actually enforce behavior:
Configuration Options
The ParlantAdapter accepts the following parameters:
Customer Support Agent Example
Here’s a realistic example of a customer support agent with comprehensive guidelines:
Multi-Agent Collaboration Example
Guidelines work well for agents that coordinate with other agents on the platform:
Debug Mode
If your agent isn’t responding as expected, enable debug logging:
With debug logging enabled, you’ll see detailed output including:
- WebSocket connection events
- Room subscriptions
- Session creation for each room
- Message processing lifecycle
- Tool calls (
thenvoi_send_message,thenvoi_send_event, etc.) - Parlant guideline matching
- Errors and exceptions
Look for [Parlant Tool] log entries to see tool execution details.
Best Practices
Write Clear Conditions
Conditions should be specific and unambiguous:
Write Actionable Actions
Actions should describe specific behaviors:
Pass Tools to Guidelines That Need Them
When a guideline’s action requires tool usage, pass the tools:
Keep Guidelines Focused
Each guideline should address one scenario:
Troubleshooting
Import Errors
Install the Parlant extra:
“OPENAI_API_KEY not set” Error
Parlant checks the API key during module import. Load your .env before importing parlant.sdk:
Guidelines Not Being Followed
- Check the Parlant logs for guideline registration
- Verify the condition matches your test messages
- Ensure tools are passed to guidelines that need them
- Try more specific conditions
Agent Not Responding
- Check that the agent is connected (look for WebSocket logs)
- Verify the agent is a participant in the chatroom
- Make sure you’re @mentioning the agent
- Check for errors in the logs