Parlant is an open-source framework for AI intelligentsia that aims to address the core challenges currently faced by large-scale language models (LLMs) in real-world applications: unpredictability and lack of controllability. When building AI intelligentsia, developers often encounter problems such as models ignoring system prompts, producing hallucinatory answers, or failing to handle boundary cases. Parlant addresses these challenges with an innovative approach that no longer relies solely on complex cue engineering, but instead enables developers to define clear Behavioral Guidelines. Written in natural language, these guidelines ensure that intelligences act precisely according to business logic and predefined rules in a given context. The framework dynamically applies the guidelines through real-time self-criticism and context-matching mechanisms to ensure consistent and reliable behavior, especially in customer service, finance, and healthcare, where high stability is required. Parlant supports the integration of external APIs and tools and provides full interpretability, allowing developers to clearly understand the reasons behind every decision made by an intelligent body.
Function List
- Behavioral Guidelines: Allows developers to use natural language to define rules that intelligences must follow under specific conditions, ensuring precise execution of business logic.
- Dialogue flow (Journeys): A clear user dialog path can be defined to guide the intelligences to achieve their goals step by step in multiple rounds of dialog.
- Reliable Tool Integration: Support for stabilizing external APIs, databases, or back-end services into specific interaction events of intelligences.
- Domain Adaptation: Ability for intelligences to learn and use industry-specific terminology to provide more personalized and professional responses.
- Canned Responses: By using predefined response templates, the risk of model hallucinations can be effectively eliminated and consistency in response style can be ensured.
- Full Explainability: Provide insight into the decision-making process of an intelligent body, explaining when and why each criterion was matched and followed.
- Built-in Guardrails: Has built-in mechanisms to prevent intelligences from hallucinating and going off-topic, and can handle inappropriate user input through content auditing.
- React widgets: Provides a plug-and-play chat user interface that can be easily embedded into any web application.
Using Help
Parlant aims to provide an easy and fast experience from development to deployment, allowing developers to build and run a behaviorally controlled AI intelligence in minutes.
mounting
Parlant can be easily installed with pip, Python's package manager. Just open your terminal or command line tool and enter the following command:
pip install parlant
This command will automatically download and install the Parlant framework and all its necessary dependencies.
Getting Started Quickly: Creating a Weather Lookup Intelligence
Here's a simple example that demonstrates how to create a smart body that can look up the weather in less than 60 seconds.
1. Import SDK and define tools
First, you need to import theparlant.sdk
. Then, use the@p.tool
Decorators to define the tools that intelligences can use. Tools are essentially ordinary asynchronous Python functions that can perform any function you need, such as calling an API.
import parlant.sdk as p
from datetime import datetime
# 定义一个获取天气的工具
# 它接收一个城市名称作为参数
@p.tool
async def get_weather(context: p.ToolContext, city: str) -> p.ToolResult:
# 在这里编写你自己的天气API调用逻辑
# 为简化示例,我们直接返回一个固定的结果
return p.ToolResult(f"Sunny, 72°F in {city}")
# 定义一个获取当前日期和时间的工具
@p.tool
async def get_datetime(context: p.ToolContext) -> p.ToolResult:
return p.ToolResult(datetime.now())
2. Creating and configuring intelligences
Next, you need to write amain
Asynchronous functions to start services, create intelligences, and configure behavior for them.
async def main():
# 启动Parlant服务器
async with p.Server() as server:
# 创建一个名为"WeatherBot"的智能体
agent = await server.create_agent(
name="WeatherBot",
description="一个乐于助人的天气助手"
)
# 创建一个上下文变量,让智能体在每次回复时都能获取最新时间
# 'get_datetime'工具会被自动调用
await agent.create_variable(name="current-datetime", tool=get_datetime)
# 使用自然语言创建一条行为准则
# 这是Parlant的核心功能,用于确保智能体的行为
await agent.create_guideline(
condition="当用户询问天气时",
action="调用天气工具获取当前天气,并用友好的语气回复,同时给出一些建议",
tools=[get_weather] # 将之前定义的工具绑定到这条准则
)
# 你可以在这里添加更多、更复杂的行为准则...
# 启动成功后,可以在 http://localhost:8800 访问测试界面
print("🎉 智能体测试界面已就绪,请访问 http://localhost:8800")
if __name__ == "__main__":
import asyncio
asyncio.run(main())```
**3. 运行并测试**
将以上代码保存为一个Python文件(例如 `weather_bot.py`),然后在终端中运行它:
```shell
python weather_bot.py
After the program runs, you'll see a message in your terminal indicating that the test interface is in the http://localhost:8800
It's ready to go. Open your browser to this address and you can interact with the "WeatherBot" you just created in real time.
When you ask, "What's the weather like in New York?" When you ask "What's the weather like in New York?Parlant
The framework recognizes that this intent matches the intent you set for thecondition
and then automatically executes the boundaction
cap (a poem)tools
This means that the call to theget_weather
function, and based on theaction
Generate friendly responses to the descriptions in the
Core concept: Guidelines
The Code of Conduct is Parlant's most powerful feature. It solves the problem of traditional methods where intelligences may ignore lengthy system prompts. You no longer need to pray that the LLM understands your intentions, but can directly prescribe its behavior.
A guideline consists of several parts:
condition
:: The conditions that trigger the criterion, described in natural language. Example: "User is agitated and demands a refund".action
:: The actions that the intelligence should perform when the conditions are met, again described in natural language. For example: "First calm the user, then call the order query tool to confirm refund eligibility".tools
:: One or more tools bound to the guideline. These tools will be invoked when the guideline is activated.
Parlant's engine analyzes the context of the conversation in real time and dynamically matches the most appropriate combination of criteria to guide the LLM in generating responses. This approach greatly improves the predictability and reliability of the intelligentsia's behavior.
application scenario
- client service
In the area of customer service, companies can define strict guidelines for conversation flow and problem handling. For example, setting different behavioral guidelines for scenarios such as refund requests, technical support, and order inquiries ensures that intelligences always follow company policies, provide standard, accurate, and empathetic service, and automatically direct users to human customer service when negative sentiment is detected. - financial service
In the financial industry, where compliance is critical, Parlant can ensure that AI intelligences adhere to strict laws and regulations when providing investment advice or handling customer account information. Guidelines can be set to avoid providing unauthorized financial advice and to enforce authentication when sensitive operations are involved. - health care
AI assistants in the healthcare space need to handle sensitive patient data and not provide incorrect medical advice. Using Parlant allows you to set strict privacy guidelines, ensure that conversations are compliant with regulatory requirements such as HIPAA, and immediately advise users to seek professional medical help when describing serious symptoms, rather than attempting to diagnose them on their own. - e-commerce
E-commerce platform shopping bots can use Parlant to guide users through the buying process. By setting up "Journeys", users can be guided through browsing products, answering specification questions, handling inventory inquiries, and ultimately placing an order. When the user strays from the shopping topic, the guidelines can guide them back to the shopping process.
QA
- How is Parlant different from other AI frameworks such as LangChain?
The core difference of Parlant is its design philosophy. While traditional frameworks focus on "requesting" LLMs to follow instructions through hint engineering and chaining calls, which are often unreliable in complex scenarios, Parlant provides a more deterministic approach to "forcing" intelligences to follow rules through its "code of conduct" and real-time context matching mechanisms, thus achieving a higher level of control and reliability. Parlant provides a more deterministic way to "force" intelligences to follow rules through its "Code of Conduct" and real-time context matching mechanisms, thus achieving a higher level of controllability and reliability. - What large language models does Parlant support?
The Parlant framework is designed to be flexible and supports a wide range of LLMs, including OpenAI's family of models as well as various open source models on HuggingFace. This allows developers to choose the most suitable model according to their needs and budget. - Do I need a deep AI background to use Parlant?
No. One of Parlant's design goals is to lower the barriers to developing reliable AI intelligences. Its core features, such as behavioral guidelines, are defined using natural language, which allows developers and even business people without a deep AI background to participate in the design of intelligent body behavior. - How does Parlant deal with hallucinations and inaccurate responses?
Parlant addresses the problem of illusion in a number of ways. First, a "Code of Conduct" ensures that intelligences must call on tools or databases for factual information in business-critical scenarios. Secondly, the "pre-defined response templates" feature allows the use of pre-written text in scenarios where absolute accuracy is required (e.g., price quotes, policy statements), avoiding the need for free-riding by LLMs altogether. - Is the project open source and commercially available?
Yes, Parlant is open source based on the Apache 2.0 license, which means you can use it for free and use it in commercial projects.