错误:操作输入不是有效的键值字典。解析 LLM 输出时出错:格式无效:我错过了“想法:”之后的“行动:”

问题描述 投票:0回答:1

我遇到一个持续存在的问题,即模型(在 Groq 上运行的 Llama 3 8B)无法处理作为参数传递的 JSON 字符串。此外,在更广泛的范围内,CrewAI 系统似乎无法将多个参数传递给函数。

背景:

在过去的 10 天里,我尝试了多种方法,包括将输入解析为字典、JSON 字符串,甚至使用 Pydantic 模型。尽管我付出了努力,问题仍然存在,让我感到沮丧并且不确定如何继续。

错误:

# Agent: Academic Research Explorer
## Thought: Let's do it correctly. I'll perform the action and then give the final answer.
Thought: I need to formulate a search strategy to gather relevant papers on the mathematical foundations of AGI and its implications on the P vs NP problem.
## Using tool: arxiv_research_tool
## Tool Input:
"{\"author\": \"\", \"title\": \"\", \"category\": \"cs.AI\", \"keywords\": [\"Artificial General Intelligence\", \"P vs NP\", \"mathematical foundations\"], \"max_results\": 10, \"sort_by\": \"lastUpdatedDate\", \"sort_order\": \"descending\", \"extract_text\": true}"
## Tool Output:
Error: the Action Input is not a valid key, value dictionary.
 Error parsing LLM output, agent will retry: I did it wrong. Invalid Format: I missed the 'Action:' after 'Thought:'. I will do right next, and don't use a tool I have already used.

If you don't need to use any more tools, you must give your best complete final answer, make sure it satisfy the expect criteria, use the EXACT format below:

Thought: I now can give a great answer
Final Answer: my best complete final answer to the task.


 Error parsing LLM output, agent will retry: I did it wrong. Tried to both perform Action and give a Final Answer at the same time, I must do one or the other
 Error parsing LLM output, agent will retry: I did it wrong. Tried to both perform Action and give a Final Answer at the same time, I must do one or the other


# Agent: Academic Research Explorer
## Final Answer: 

任务示例:

下面是我尝试实现的任务的示例。

任务定义:

def task_research(self, agent, conversation: Dict[str, str], research_papers: Dict[str, Any]) -> Task:
    research_template = """
    RESEARCH PROTOCOL:
    
    CONTEXT:
    {conversation_text}
    {research_papers}

    REQUIRED STEPS:
    1. Research Analysis:
       - Extract key findings
       - Document methodology
       - Record empirical results
       - Note implementation details
    
    2. Content Organization:
       - Background/Current State
       - Methodology Analysis
       - Empirical Evidence
    
    3. Content Extraction:
       - Use load_document for PDFs
    
    4. Final Synthesis:
       - Abstract
       - Literature Review
       - Methodology Comparison
       - Results Analysis
       - Conclusions
       - References
    """
    unrolled_research_papers = self.unroll_results(research_papers)
    conversation_text = self.format_input_dict(conversation)
    return Task(
        description=research_template.format(
            conversation_text=conversation_text,
            research_papers=unrolled_research_papers
        ),
        expected_output="A structured dictionary with keys: 'abstract', 'literature_review', 'analysis', 'conclusion', 'references'",
        agent=agent,
        async_execution=True,
        output_json=ResearchOutComeModel
    )

代理配置:

def research_paper_agent(self):
    return Agent(
        llm=self.llm,
        role="Academic Research Explorer",
        goal="""Identify and analyze relevant research papers ...""",
        backstory="""You are an expert Academic Research Explorer specialized in discovering relevant scholarly work ...""",
        allow_delegation=False,
        tools=[ArxivResearchTool()],
        verbose=True,
        max_iter=3,
    )

工具示例:

class ArxivResearchInput(BaseModel):
    argument: str = Field(
        description='JSON string containing search parameters',
        example='{"author": "Alan Turing", "title": "Computing Machinery", "category": "cs.AI", "max_results": 4, "sort_by": "relevance", "sort_order": "descending", "extract_text": true}'
    )

class ArxivResearchTool(BaseTool):
    name: str = 'arxiv_research_tool'
    description: str = """Useful to search the arXiv academic database ..."""
    args_schema: Type[BaseModel] = ArxivResearchInput

    def _run(self, argument: str) -> Dict:
        try:
            params = json.loads(argument)
            return ResearchTool.arxiv_research_tool(argument)
        except Exception as e:
            return {"error": str(e)}

观察到的行为:

  • JSON 参数无法一致解析。
  • 不支持多参数函数调用或静默失败。

预期行为:

系统应该:

  1. 接受有效的 JSON 参数且没有错误。
  2. 允许多参数函数输入,无需大量解决方法。

环境详情:

  • 型号: Llama 3 8B (Groq)
  • 工具: Crew AI、Python、Pydantic、自定义任务系统。

要求:

如何解决这个问题?

重现步骤

  1. 前往https://github.com/Harshal292004/resarch-agent-hub 2.分叉仓库 3.创建虚拟环境 4.pip install -r 需求.txt 5.cd虚拟应用程序
  2. cd 代理
  3. python main.py

预期行为

预期的行为是代理能够正确地将 JSON 字符串作为参数传递给工具并取回研究论文

屏幕截图/代码片段

image

系统信息

Windows 11
Python 3.10
crewAI 0.80.0
crewAI Tools 0.14.0
Venv

证据

image

artificial-intelligence agent crewai
1个回答
0
投票

由于您使用的法学硕士,可能会发生此类错误。不幸的是,规模较小的法学硕士有时很难与 CrewAI 合作。 尝试将LLM转为更有能力的LLM。

  • 使用 Llama 3.2 3B?尝试 Llama 3.2 11B 或 90B。
  • 使用 OpenAI GPT-4o-Mini?尝试 OpenAI GPT-4o。
  • 使用 Anthropic Claude 3 Haiku?尝试 Anthropic Claude 3.5 Haiku 或 Sonnet。

正如 CrewAI 首席执行官在 GitHub 上所说:

嘿伙计们,终于赶上了!

确实,较小的模型确实难以使用某些工具,特别是更多 复杂的,我觉得我们还有优化人员的空间 也许会提示一点,我会调查一下,但最终 较小的模型确实在认知方面存在困难。

我正在收集数据以将这些模型微调为代理模型 将被训练得更像特工,这应该提供方法 即使是小型型号也具有更高的可靠性。

我认为下一步最好的行动可能是提到最好的模型 我们的新文档,并做了一些稍微改变提示的测试 较小的模型,我会看一下,同时我正在关闭它 一个,但如果有请求,可以重新打开:)

© www.soinside.com 2019 - 2024. All rights reserved.