0

I am trying to call Flask API which i alrady running on port 5000 on my system, i am desgning a agentic AI code which will invoke GET and then POSt based on some condition , and using google-adk. I have below code

import requests
from google.adk.agents import LlmAgent
from google.adk.tools.function_tool import FunctionTool

def check_trainer_availability(trainer: str) -> str:
    resp = requests.get("http://localhost:5000/availability", params={"trainer": trainer})
    return resp.json().get("availability", "unknown")

def book_trainer(trainer: str, trainee: str) -> str:
    resp = requests.post("http://localhost:5000/book", json={"trainer": trainer, "trainee": trainee})
    return resp.json().get("message", "Booking failed.")

availability_tool = FunctionTool(check_trainer_availability)
booking_tool = FunctionTool(book_trainer)

agent = LlmAgent(
    name="TrainerBookingAgent",
    model="gemini-1.5-flash",
    tools=[availability_tool, booking_tool],
    instruction="""
You are an assistant that checks trainer availability using the tool, and books if available.
"""
)

if __name__ == "__main__":
    result = agent.invoke("Please book Aisha for John.")
    print(" Agent Response:", result.response)

Whenever i am running this i am getting below error:

AttributeError: 'LlmAgent' object has no attribute 'invoke'

I have google-adk version 1.4.1 , still i am getting this issue. Please Help.

1 Answer 1

0

Your issue:
AttributeError: 'LlmAgent' object has no attribute 'invoke'

Root cause:
In google-adk (at least up to v1.4.1), the LlmAgent class does not have an .invoke() method.
The correct method to use is usually .run() or .chat(), depending on the version and agent type.

Solution:
Replace this line:

result = agent.invoke("Please book Aisha for John.")

with:
result = agent.run("Please book Aisha for John.")

# or (if your version/documentation says so):

# result = agent.chat("Please book Aisha for John.")

Additional notes:

  • Always check the official google-adk documentation or run dir(agent) to see which methods are available.

  • If .run() or .chat() are not available, check your library version or update the package:

    pip install --upgrade google-adk

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your suggestions. I updated the google-adk also but still gets the same issue with .run and .chat. AttributeError: 'LlmAgent' object has no attribute 'chat'. AttributeError: 'LlmAgent' object has no attribute 'run'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.