You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Agno Agent Run模式无法调用MCP工具,AgentOS模式正常

问题:Agno框架Run模式下无法触发MCP服务器工具调用

问题描述

使用Agno框架时,AgentOS模式下Agent可正常调用MCP服务器并返回正确结果,但直接调用Agent.run()的Run模式中,Agent始终不会触发MCP工具调用,返回的是模型默认回答(将“agno”误认为化学物质)。

代码示例

from agno.agent import Agent
from agno.db.sqlite import SqliteDb
from agno.models.openai import OpenAIChat
from agno.tools.mcp import MCPTools
from agno.agent import RunOutput
from agno.utils.pprint import pprint_run_response

# 创建Agent
agno_agent = Agent(
  name="Agno Agent",
  model=OpenAIChat(id="gpt-4o"),
  db=SqliteDb(db_file="agno.db"),
  tools=[MCPTools(transport="streamable-http",  url="https://docs.agno.com/mcp")],
  add_history_to_context=True,
  markdown=True,
  debug_mode=True
)

# AgentOS模式(已注释)
# agent_os = AgentOS(agents=[agno_agent])
# app = agent_os.get_app()

# Run模式调用
response: RunOutput =agno_agent.run("what is agno?")

pprint_run_response(response, markdown=True)

关键运行日志片段

DEBUG ============================================================================================================== system =============================================================================================================
DEBUG <additional_information>

Use markdown to format your answers.
</additional_information>
DEBUG =============================================================================================================== user ==============================================================================================================
DEBUG what is agno?
DEBUG ============================================================================================================ assistant ============================================================================================================
DEBUG “AgNO” does not appear to be a commonly recognized term or acronym. However, in chemistry, “AgNO” could be a typographical error or shorthand for silver nitrate...

解决方案

1. 显式启用工具调用参数

尝试在run()方法中添加启用工具的参数(需匹配Agno框架的API定义):

response: RunOutput = agno_agent.run("what is agno?", enable_tools=True)

2. 手动注入工具调用引导的系统提示

AgentOS模式会自动添加工具调用的系统提示,Run模式下需手动补充:

agno_agent = Agent(
  name="Agno Agent",
  model=OpenAIChat(id="gpt-4o"),
  db=SqliteDb(db_file="agno.db"),
  tools=[MCPTools(transport="streamable-http",  url="https://docs.agno.com/mcp")],
  add_history_to_context=True,
  markdown=True,
  debug_mode=True,
  system_prompt="你必须使用提供的MCP工具获取关于Agno的信息,优先调用工具回答问题,禁止依赖自身知识库作答。"
)

3. 手动触发工具初始化

AgentOS会自动完成工具初始化流程,Run模式下可手动触发:

# 调用run前手动初始化工具
agno_agent._init_tools()

response: RunOutput = agno_agent.run("what is agno?")

4. 使用工具调用专用方法

若run()默认不处理工具调用,尝试框架中专门的工具调用方法(如call_tool,需参考官方文档):

# 示例:手动指定调用MCP工具
response = agno_agent.call_tool("MCPTools", query="what is agno?")

内容的提问来源于stack exchange,提问作者garg10may

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.12 06:14:52