


ConnectOnion 是一款专为 Python 开发者设计的智能体(Agent)框架,旨在极大地简化 AI 智能体的构建、管理与连接。它让你能够使用简洁的 Python 函数来创建强大的 AI 智能体,告别复杂的类结构,实现代码的优雅与高效!
llm_do 函数实现,提供一致且强大的功能。plugins=[re_act])即可轻松集成复杂推理能力(如 ReAct 模式)。只需几行代码,即可创建你的第一个 AI 智能体:
from connectonion import Agent
agent = Agent("You are helpful", tools=[get_weather])
agent.input("What's the weather in NYC?")
就是这么简单!ConnectOnion 秉承“保持简单事物的简洁,使复杂事物变为可能”的哲学。
Agent 类
Agent 是 ConnectOnion 的核心,它能够根据你提供的工具自动完成任务。
使用标准的 Python 函数定义智能体可以执行的操作。函数签名(特别是类型提示)会被自动解析,无需手动创建复杂的工具描述。
def add(a: float, b: float) -> float:
return a + b
实例化 Agent 时传入名称、工具列表以及可选的系统提示(个性设定)和模型参数。
agent = Agent(name="my_bot", system_prompt="You are a helpful assistant.", tools=[add, multiply])
通过 agent.input() 方法与智能体交互,它将根据内部逻辑和可用工具完成任务。
result = agent.input("What is 5 + 3, then multiply by 2?")
llm_do
ConnectOnion 提供了一个统一的 llm_do 函数,让你能够轻松地进行一次性 LLM 调用,支持结构化输出和多种模型。
answer = llm_do("What's 2+2?", model="gemini-1.5-flash")
class Analysis(BaseModel):
sentiment: str
confidence: float
keywords: list[str]
result = llm_do("I love this product!", output=Analysis)
智能体的对话记忆在 ConnectOnion 中被视为一个工具,集成方式非常自然。
Memory() 实例添加到智能体的工具列表中。
from connectonion import Agent, Memory
memory = Memory()
agent = Agent("You remember user preferences", tools=[memory])
ConnectOnion 允许通过插件轻松扩展智能体的推理能力,例如集成 ReAct(Plan + Act + Reflect)循环。
from connectonion.useful_plugins import re_act
agent = Agent("You are a research assistant", tools=[search], plugins=[re_act])
ConnectOnion 认识到将智能体投入生产的重要性,提供简单且灵活的部署选项。
co deploy 命令即可将智能体项目部署到生产环境。
框架提供详细的活动日志功能,方便调试和分析智能体行为。
.co/logs/ 和 .co/sessions/ 目录。
“ConnectOnion: AI Agent = Prompt + Function”
这就是 ConnectOnion 的全部!现在,去创造一些有用的东西吧!