我遇到一个持续存在的问题,即模型(在 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 字符串作为参数传递给工具并取回研究论文
Windows 11
Python 3.10
crewAI 0.80.0
crewAI Tools 0.14.0
Venv
我和克劳德有同样的问题。来自 cli 的工具输入值似乎有效,但crewai 说它无效。 我还发现了这个讨论https://community.crewai.com/t/issue-with-ast-literal-eval-parsing-json-tool-input-in-toolusage-class/449