阿尔弗雷多
   
一个用于构建具备全面工具执行和自主任务完成能力的AI代理的Python框架。
Alfredo 提供了一个基于 LangGraph 的智能体框架,该框架将规划、执行和验证集成为一个统一的智能体系统。其设计注重可扩展性,支持自定义工具、MCP 集成,并附带了专用的预构建智能体。
主要特点
- 🤖 机器人 自主代理 - 计划-验证-重新计划循环,带自动任务分解功能
- 🔧 修理工具或扳手的符号,常用于表示维修、修理或技术相关的工作。 11 个内置工具 - 文件操作、命令、发现、代码分析、可视化以及工作流控制
- 👁️ 视觉能力 - 使用多模态模型分析图像
- 🔗 MCP集成 - 连接到任何模型上下文协议服务器
- 🎯(目标、靶心) 模型无关的 - OpenAI、Anthropic 或任何支持 LangChain 的大型语言模型(LLM)
- 📊(图表/数据) 执行追踪 - 对代理行为的详细可见性
- 🛠️(工具/螺丝刀等工具的符号,可翻译为“工具”或根据具体语境翻译为相应的具体工具名称) 自定义系统提示 - 使用AlfredoTool微调节点行为
- 📦 翻译为中文是:“📦”(这个符号本身在中文中没有直接对应的翻译,通常保持原样使用,表示包裹或箱子)。如果需要描述其含义,可以翻译为“包裹”或“箱子”,但具体翻译需根据上下文确定。 预构建代理 - 探索代理(ExplorationAgent)和反思代理(ReflexionAgent)已准备好使用
安装
注: Alfredo 尚未在 PyPI 上发布。请直接从 GitHub 安装,使用 uv:
# Clone the repository
git clone https://github.com/biocypher/alfredo.git
cd alfredo
# Install dependencies
uv sync
# Or add as a dependency to your project
uv add git+https://github.com/biocypher/alfredo.git快速入门
from alfredo import Agent
# Create an agent
agent = Agent(
cwd=".",
model_name="gpt-4.1-mini", # or "anthropic/claude-3-5-sonnet-20241022"
verbose=True
)
# Run a task - agent will plan, execute, and verify
agent.run("Create a Python script that computes an approximation of pi using the Monte Carlo method")
# View execution trace
agent.display_trace()
# Access results
print(agent.results["final_answer"])视觉赋能的智能体
Alfredo智能体能够利用视觉模型分析图像,从而实现强大的工作流程,使智能体能够验证其自身的视觉输出:
from alfredo import Agent
# Create an agent with vision capabilities
agent = Agent(
cwd=".",
model_name="gpt-4.1-mini", # Main model for planning and reasoning
vision_model="gpt-4.1-mini", # Vision model for image analysis
parse_reasoning=True
)
# Agent creates visualization AND verifies it by looking at it
agent.run("""
Create a Python script that computes an approximation of pi using the Monte Carlo method.
Also create a visualization of the results and save it as a PNG file.
Make sure that the plot is correct by analyzing the image.
If you miss some package, use uv to initialize a venv and then add what is missing.
""")
# View execution trace to see vision tool in action
agent.display_trace()发生的事情:
- 代理编写蒙特卡洛模拟代码
- 代理运行代码并生成图表
- 代理使用
analyze_image验证可视化是否正确 - 如果发现问题,代理将继续迭代(或:代理会重复执行以解决问题)
视觉技术的应用场景:
- 📸 界面测试中的截图分析
- 📊 图表和图示验证
- 📝 OCR(光学字符识别)和文档处理
- 🎨 图像描述与配文创作
- ✅ 视觉质量保证
建筑学
阿尔弗雷多使用一个 LangGraph状态图 包含以下节点:
START → planner → agent ⇄ tools → verifier
↑ ↓
└── replan ←───┘- 规划者;日程安排者制定实施计划
- 代理执行ReAct风格的推理和工具调用
- 工具执行工具调用
- 验证者检查任务是否完成
- 重新计划如果验证失败,则生成改进后的计划
可以禁用规划功能,直接在代理节点上开始执行。
可用工具
Alfredo 包含11个内置工具,按类别组织:
| 类别 | 工具 |
|---|---|
| 文件操作 | read_file, write_to_file, replace_in_file |
| 发现 | list_files, search_files |
| 代码分析 | list_code_definition_names |
| 命令 | execute_command |
| 愿景 | analyze_image |
| 工作流程 | ask_followup_question, attempt_completion |
MCP 集成
Alfredo支持两种MCP集成模式:
代码行动模式
从MCP服务器生成可导入的Python模块,使代理能够像使用常规函数一样使用工具,而无需通过ReAct循环:
from alfredo import Agent
# Configure remote MCP server (supports both local and remote)
agent = Agent(
cwd="./workspace",
model_name="gpt-4.1-mini",
codeact_mcp_functions={
"biocontext": {
"url": "https://mcp.biocontext.ai/mcp/", # Remote or local server
}
},
verbose=True
)
# Agent can now import and use MCP tools in scripts:
agent.run("Write a script that gets the interactors of gene ENSG00000141510 and save to interactors.txt")
# Agent generates code like:
# from biocontext_mcp import bc_get_protein_interactors
# result = bc_get_protein_interactors(gene_id="ENSG00000141510")特点:
- ✅ 与……兼容/可与……一起使用 远程 服务器(例如。,
https://mcp.biocontext.ai/mcp/) - ✅ 与……兼容/协同工作 当地的 服务器(例如。,
http://localhost:8000) - ✅ 自动生成带类型的Python封装模块
- ✅ 支持SSE和JSON-RPC 2.0协议
- ✅ 会话管理,支持自动重试
- ✅ 基于脚本的工具链集成
ReAct 模式
通过LangChain的工具调用直接使用MCP工具:
from alfredo import Agent
from alfredo.integrations.mcp import load_combined_tools_sync
# Configure MCP servers
server_configs = {
"biocontext": {
"transport": "streamable_http",
"url": "https://mcp.biocontext.ai/mcp/",
}
}
# Load Alfredo + MCP tools
tools = load_combined_tools_sync(cwd=".", mcp_server_configs=server_configs)
# Create agent with combined toolset
agent = Agent(cwd=".", tools=tools)
agent.run("Get the interactors of TP53 in human and save the results to a file called tp53_interactors.txt")自定义系统提示
使用 AlfredoTool 为任何工具添加节点特定的指令:
from alfredo.tools.alfredo_tool import AlfredoTool
# Add instructions that only appear in specific nodes
tool = AlfredoTool.from_alfredo(
tool_id="write_todo_list",
cwd=".",
system_instructions={
"planner": "After making your plan, create an initial checklist to keep track of your progress",
}
)
# Instructions are dynamically injected into node system prompts
agent = Agent(cwd=".", tools=[tool])预构建的代理(或预置代理)
探索代理
浏览目录,并通过智能文件读取和数据分析生成全面的Markdown报告:
from alfredo.prebuilt import ExplorationAgent
agent = ExplorationAgent(
cwd="./my_project",
context_prompt="Data belongs to a transcriptomic study on cancer cell lines"
)
report = agent.explore()反思型智能体(或:反思性代理)
利用网络搜索进行迭代自我批评和修订的研究代理:
from alfredo.prebuilt import ReflexionAgent
agent = ReflexionAgent(model_name="gpt-4.1-mini", max_iterations=2)
answer = agent.research("Create a detailed report about the roles of TP53 in cancer cell lines and save the results to a file called tp53_roles.md")
agent.display_trace()文档
- 代理架构 - 深入探讨LangGraph框架
- 工具 - 完整的工具参考手册及自定义工具的创建
- MCP集成 - 使用模型上下文协议服务器
- 阿尔弗雷多工具 - 为每个节点定制系统提示
- 预构建代理 - 探索代理(ExplorationAgent)和反思代理(ReflexionAgent)
发展
# Install dependencies
make install
# Run tests
uv run pytest
# Run tests with coverage
uv run pytest --cov=src
# Lint and type check
uv run ruff check src
uv run mypy src许可证
在以下(许可/条款)下发布 麻省理工学院许可证(MIT License)。
功劳/学分/资历
受……启发的工具系统设计 克林(Cline,根据上下文,此为人名翻译,具体翻译可能因语境而异) - 一个适用于VSCode的AI编码助手。
______________________________________________________________________
