crewAIInc / crewAI

Framework for orchestrating role-playing, autonomous AI agents. By fostering collaborative intelligence, CrewAI empowers agents to work together seamlessly, tackling complex tasks.
https://crewai.com
MIT License
19k stars 2.62k forks source link

Forcing a llamaIndex query engine Tool Output as Result? #1014

Closed allex083 closed 1 month ago

allex083 commented 1 month ago

How to Force a llamaIndex query engine Tool Output as Result? NEED HELP

Example codes in docs:

# ...
# Define a custom tool that returns the result as the answer
coding_agent =Agent(
        role="Data Scientist",
        goal="Product amazing resports on AI",
        backstory="You work with data and AI",
        tools=[MyCustomTool(result_as_answer=True)],
    )
# ...

My codes:

query_engine = index.as_query_engine(
                    include_text=True, 
                    response_mode="tree_summarize", 
                    verbose=True, 
                    embedding_mode="hybrid", 
                    similarity_top_k=15, 
                    streaming=False,
                )
  tool = LlamaIndexTool.from_query_engine(
      query_engine,
      name=f"{knowledge.id} Knowledge Base Tool", 
      description=f"Tool for querying the {knowledge.id} (or its aliases {knowledge.alias}) knowledge base of organization {organization.name}. "
                  f"This knowledge base covers: {knowledge.description}. "
                  f"Use this tool for queries related to organization {organization.name} "
                  f"or its aliases: {', '.join(organization.aliases)}. "
                  f"Always pass the full user query to this tool without extracting keywords."
  )
agent = Agent(
            role = "an agent",
            goal = "xxxxxxxxxxx",
            backstory = dedent(f"""\
                               xxxxxxxxxxxxx
            """),
            allow_delegation=False,
            llm=self.llm,
            verbose=True,
            tools=[tool],
        )