导入
调试、优化与强化我们的代理
通过分析详细日志并优化工具描述和系统提示,学习诊断和修复常见的代理失败问题。
...
The four common agent failure modes can be grouped into two main categories: Cognitive failures (errors in the agent’s internal reasoning) and execution failures (errors that occur when interacting with tools and the environment)
代码示例
1Thought: 用户在询问“什么是...”某事物,这听起来像是在请求定义。我应该使用 `definition_tool` 来定义“四层查询”。 2Action: definition_tool 3Action Input: {"term": "four levels of queries"} 4Observation: Error: Could not find a Wikipedia page for 'four levels of queries'. Please try a different term. 5Thought: 该工具未能找到定义。我无法回答用户的问题。
代码示例
1description=( 2 "包含用户提供的特定研究论文的详细信息。" 3 "使用此工具来回答关于这些论文的深入、上下文相关问题。" 4)
代码示例
1description=( 2 "此工具提供对一系列关于 RAG 的特定研究论文的访问。" 3 "它能够回答这些论文内容的深入、上下文相关问题," 4 "包括其作者、如 eRAG 的方法,以及查询层级(L1-L4)。" 5)
1.
Why does the description narrow the scope to ‘eRAG’ and specific query levels (L1–L4)? Wouldn’t this potentially exclude other relevant papers?
0/500
代码示例
1except wikipedia.exceptions.DisambiguationError as e: 2 return f"Error: '{term}' is ambiguous. Please be more specific."
代码示例
1except wikipedia.exceptions.DisambiguationError as e: 2 # 给代理提供可用来恢复的选项! 3 return f"Error: '{term}' is ambiguous. Please be more specific. Did you mean one of these: {e.options[:3]}?"
代码示例
1system_prompt = """You are a helpful assistant... 2Only use a tool if the user's question directly relates to the tool's description."""
代码示例
1system_prompt = """You are a helpful assistant. Your primary goal is to answer user questions accurately. 2You have access to a set of tools. Here are the descriptions of your tools: 3--- 4{tool_desc} 5--- 6Carefully analyze the user's query and the tool descriptions to decide if a tool is relevant. 7If a tool returns an error or if the information is insufficient, 8do not give up. Re-evaluate the query and decide if you should try another tool 9or if you can answer from your own knowledge. 10"""
代码示例
1Thought: The user is asking about a person and a topic related to my documents ("Transformers"). I should use the `rag_research_paper_tool` to find this information. 2Action: rag_research_paper_tool 3Action Input: {"query": "Information on Yann LeCun and what he wrote about Transformers"} 4Observation: I'm sorry, but the provided documents do not contain specific information about Yann LeCun's writings on Transformers. The papers focus on the work of other authors. 5Thought: The tool could not find the information. I am unable to answer the user's question.
代码示例
1description=( 2 "This tool provides access to a collection of specific research papers about RAG..." 3),
代码示例
1description=( 2 "Contains detailed information from specific research papers by authors like Vaswani and Salemi. " 3 "It is an expert on the 'RAG and Beyond' and 'eRAG' papers. Use this for deep, contextual questions about THEIR content." 4),
代码示例
1Thought: The user is asking about "Yann LeCun". I will check my tool descriptions. The `rag_research_paper_tool` description mentions Vaswani and Salemi, not LeCun. Therefore, that tool is not relevant. I should first find out who Yann LeCun is. The `definition_tool` is best for this. 2Action: definition_tool 3Action Input: {"term": "Yann LeCun"} 4Observation: Yann LeCun is a French computer scientist working primarily in the fields of machine learning, computer vision, mobile robotics, and computational neuroscience... 5Thought: Now that I know who Yann LeCun is, I need to find what he wrote about Transformers. The `arxiv_search_tool` is the correct tool for finding papers by a specific author. 6Action: arxiv_search_tool 7Action Input: {"query": "Transformers", "author": "Yann LeCun"} 8Observation: [List of papers by Yann LeCun related to Transformers] 9Thought: I have successfully found who Yann LeCun is and a list of his relevant papers. I can now synthesize this information into a final answer.
一个示例追踪
1Running step init_run 2Step init_run → AgentInput 3Running step setup_agent 4Step setup_agent → AgentSetup 5Running step run_agent_step 6LLM Thought: "User is asking for a definition." 7Parsed Action: CALL_TOOL name="definition_tool" 8Parsed Action Input: {"query": "hyperparameter"} # <-- note the key 9Running step call_tool 10Tool definition_tool invoked with kwargs={'query': 'hyperparameter'} 11ToolError: TypeError: define_term() missing 1 required positional argument: 'term' 12Step call_tool → ToolExecutionError 13Running step aggregate_tool_results 14Agent Observation: "definition_tool failed: missing required arg 'term'" 15Running step run_agent_step 16LLM Thought: "Tool failed. Returning general answer." 17Agent Output: "A hyperparameter is..."
Coming soon to support pageflux-note