Skip to content

Custom tool not working properly in the Chatbot #620

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
MervinPraison opened this issue Jun 6, 2025 · 5 comments
Open

Custom tool not working properly in the Chatbot #620

MervinPraison opened this issue Jun 6, 2025 · 5 comments

Comments

@MervinPraison
Copy link
Owner

Discussed in #458

Originally posted by Ajaychaki2004 April 10, 2025
I am using an agent with a custom tool to get the database details for my chatbot. While running the agent independently, it works perfectly, but when integrated into the chatbot, the agent runs, but the custom tool is not used instead its hallucinating

Let me know if you need further assistance with the integration!

@MervinPraison
Copy link
Owner Author

@Ajaychaki2004 Can you please provide the full code ?

@MervinPraison
Copy link
Owner Author

@BugBot review this error

@Ajaychaki2004
Copy link

Here is the code

#agent.py file
from praisonaiagents import Agent
from tools import fetch_product_from_mongodb
from dotenv import load_dotenv
load_dotenv()

import os
google_api_key = os.getenv("GOOGLE_API_KEY")

agent = Agent(
name="Product Lookup Agent",
role="Database Query Handler",
goal="Get details about the product from the MongoDB database",
backstory="You are a helpful assistant with access to a product database.",
tools=[fetch_product_from_mongodb],
verbose=True,
llm="gemini/gemini-1.5-flash-8b",
markdown=True
)
agent.start("Get details about the product named 'CCE'")

#tools.py
from pymongo import MongoClient
from typing import Dict

def fetch_product_from_mongodb(product_name: str) -> Dict:
"""
Fetch product details from MongoDB by product name.

Args:
    product_name (str): The name of the product to search.

Returns:
    Dict: The product document or an error message.
"""
try:
    client = MongoClient("mongodb+srv://ihub:[email protected]/")
    db = client["GENAI"]
    collection = db["Chatbot_Knowledgebase"]

    result = collection.find_one({"product_name": product_name})
    if result:
        result["_id"] = str(result["_id"])  # Convert ObjectId to string for readability
        return result
    return {"message": "Product not found."}
except Exception as e:
    return {"error": f"Error fetching product: {str(e)}"}

@MervinPraison
Copy link
Owner Author

/gemini review

@MervinPraison
Copy link
Owner Author

@gemini-code-assist review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants