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
19.73k stars 2.73k forks source link

Tool not getting called within the Agent #812

Closed NamanV closed 3 months ago

NamanV commented 3 months ago

`data = request.json prompt = data.get("prompt") history = data.get("history", []) self.hotel_task = TripTasks().hotel_task(self.hotel_agent, prompt, history)

self.crew = Crew(
        agents=[self.hotel_agent],
        tasks=[self.hotel_task],
        process=Process.sequential,
        verbose=2
    )
    result = self.crew.kickoff()
    print(result)`

 `def hotel_agent(self):
    chroma_tool = ChromaDBTool()
    return Agent(
        role="You are a hotel recommendation expert.",
        goal="""
        Provide hotel suggestions strictly using the Chroma DB tool based on user preferences and budget.
        """,
        backstory="""
        **Who you are:**
        You are a seasoned hotel expert with extensive knowledge of accommodations. Your primary responsibility is to recommend the best hotels that match the user's preferences and budget by querying the Chroma DB.

        **Your approach:**
        - Always use the tool to suggest hotels.
        - Provide detailed information about each hotel retrieved from the Chroma DB to help the user make an informed choice.
        - Consider the entire chat history and mandatory information collected.
        """,
        llm=self.llm_model,
        verbose=True,
        memory=True,
        allow_delegation=False,
        tools=[chroma_tool],
        max_iter=2
    )`

` from database.chroma_langhain import ChromaLangChainClient from langchain.tools import tool from crewai_tools import BaseTool import logging

class ChromaDBTool(BaseTool):

name: str = "fetch_hotels_from_db"
description: str = "Fetch hotels from the Chroma DB based on the given query, which includes specific attributes, names, or destinations."

def _run(self, argument: str) -> str:
    logging.info(f"Querying ChromaDB with: {str}")
    self.chroma_client = ChromaLangChainClient()
    return self.chroma_client.query_data(str, 20)
`

I am storing hotel information in vector DB using chroma, and trying to use the hotel agent to use the hotels from vector db usig the ChormaDBTool, but it's not using the tool at all and directly getting the result from LLM(llama 3).   Can you please have a look at the above code snippet and help me out?

Using Bedrock for LLM

pantlavanya commented 3 months ago

Hi @NamanV, Did you find any solution for this?

NamanV commented 3 months ago

Hi @NamanV, Did you find any solution for this?

It worked after increasing the max_iter, initially I had set it to 2. Somehow Agent is not able to trigger the agent if max_iter is too low!