操作输入不是有效的键、值字典

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

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

背景:

在过去的 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 -rrequirements.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
投票

我和克劳德有同样的问题。来自 cli 的工具输入值似乎有效,但crewai 说它无效。 我还发现了这个讨论https://community.crewai.com/t/issue-with-ast-literal-eval-parsing-json-tool-input-in-toolusage-class/449

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