Skip to content

AI Agent don't use tool || issue #1077

@Sarah-Salah

Description

@Sarah-Salah

i wrote a simple code like this:

"""""""""
import logging
logging.basicConfig(level=logging.DEBUG)
import posthog
posthog.disabled = True
import os
import sys
import litellm
litellm.extra_body = {
"chat_template_kwargs": {"enable_thinking": False},
"tool_choice": "auto",
"tool_call_parser": "hermes",
}
import gradio as gr
from praisonaiagents import Agent, MCP
import httpx
os.environ["GRADIO_ANALYTICS_ENABLED"] = "False"
import requests
requests.packages.urllib3.disable_warnings()
litellm.client_session = httpx.Client(verify=False)
litellm.aclient_session = httpx.AsyncClient(verify=False)
litellm.verify_ssl = False
litellm.request_timeout = 1200
litellm.num_retries = 5
litellm.retry = True
litellm.stream = False
litellm.drop_params = False
os.environ["OPENAI_API_KEY"] = "dummy_key"
os.environ["OPENAI_API_BASE"] = "[https://myurl/v1"]
os.environ["OPENAI_MODEL_NAME"] = "openai/Qwen/Qwen2.5-VL-7B-Instruct"
litellm.temperature = 0.6
litellm.top_p = 0.95
litellm.top_k = 20
litellm.max_tokens = 2000
tools = MCP("npx -y mcp-server-kubernetes --kubeconfig ./kubeconfig.yaml --port 8080")

agent = Agent(

instructions="""You are a DevOps engineer.

Always use one of the MCP tools to answer. Do NOT answer without using a tool.""",

role="Devops & SRE Enginer",
goal="Answer after using the right tools",
backstory="You are the best DevOps engineer ever",
llm=os.environ["OPENAI_MODEL_NAME"],
tools=tools,
verbose=True,
markdown=True,
allow_delegation=True,

)
def run_agent(task):
result = agent.start(task)
print("DEBUG >>>>>>>", result)
return result
def gradio_interface(task):
return run_agent(task)
if name == "main":
if len(sys.argv) > 1:
task = " ".join(sys.argv[1:])
print(run_agent(task))
else:
demo = gr.Interface(fn=gradio_interface, inputs="text", outputs="text")
demo.launch()

'''''''''''''''''''''''''''''''''''''''''''''

and when i run the app and start send to it tasks , it answer without using the tools, although the tools appear as below in the terminal of the agent :

'''''''''''

[16:35:15] INFO [16:35:15] llm.py:827 INFO Getting response from openai/Qwen/Qwen2.5-VL-7B-Instruct llm.py:827
╭─ Agent Info ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ │
│ 👤 Agent: Agent │
│ Role: Devops & SRE Enginer │
│ Tools: cleanup, kubectl_get, kubectl_describe, kubectl_apply, kubectl_delete, kubectl_create, kubectl_logs, kubectl_scale, kubectl_patch, │
│ kubectl_rollout, kubectl_context, explain_resource, install_helm_chart, upgrade_helm_chart, uninstall_helm_chart, port_forward, stop_port_forward, │
│ exec_in_pod, list_api_resources, kubectl_generic, ping │
│ │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯

Response generated in 53.4s
╭─────────────────────────────────────────────────────────────────────────── Task ───────────────────────────────────────────────────────────────────────────╮
│ list all the pods in test namespace in the cluster using mcp and tools │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
╭───────────────────────────────────────────────────────────────────────── Response ─────────────────────────────────────────────────────────────────────────╮
│ To list all the pods in the test namespace in a Kubernetes cluster, you can use the kubectl_get tool with the -n flag to specify the namespace and the -o │
│ flag to output the list of pods. │
│ │
│ Here's how you can do it: │
│ │
│ │
│ kubectl_get pods -n test -o json │
│ │
│ │
│ This command will return a JSON list of all the pods in the test namespace. If you want to see the list in a more human-readable format, you can add the │
│ --no-headers flag: │
│ │
│ │
│ kubectl_get pods -n test --no-headers │
│ │
│ │
│ Alternatively, if you prefer to see the list in a table format, you can use the --output flag with table: │
│ │
│ │
│ kubectl_get pods -n test --output=table │
│ │
│ │
│ These commands should provide you with the necessary information about the pods in the test namespace. │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯

'''''''''''''''''''''''''''

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions