adk-python icon indicating copy to clipboard operation
adk-python copied to clipboard

AttributeError: 'AgentEngine' object has no attribute 'stream_query'

Open SankaiAI opened this issue 1 year ago • 30 comments

Describe the bug My multi-agent works fine on my local environment. Now I am deploying and testing my ADK agent with gcloud Vertex AI, but I keep getting error message saying 'AgentEngine' object has no attribute 'stream_query'.

I basically follow the instruction from SDK: https://google.github.io/adk-docs/deploy/agent-engine/#send-queries-to-your-agent-local

I've sucessfully deployed it to the cloud and get a resource_id: Image

However, once I use the following command to send a message to my remote agent, it says 'AgentEngine' object has no attribute 'stream_query': poetry run deploy-remote --send --resource_id [my resource ID] --user_id test_user --session_id [my session ID]

Here is my script for sending the message to my remote app:

remote_app = agent_engines.get(resource_id)
print(type(remote_app))
print(dir(remote_app))
print(f"Sending message to session {session_id}:")
print(f"Message: {message}")
print("\nResponse:")
for event in remote_app.stream_query(
    user_id=user_id,
    session_id=session_id,
    message=message,
):
    print(event)

Screenshots Image

Here are all the available methods for AgentEngine I got, and it looks like there is no stream_query method Image

Expected behavior I should be able to get the response from my remote app.

Desktop (please complete the following information):

  • OS: WINDOWS
  • Python version(python -V): Python 3.11.7
  • ADK version(pip show google-adk): 0.3.0
  • google-cloud-aiplatform version: 1.92.0

SankaiAI avatar May 12 '25 06:05 SankaiAI

Plus 1 to this.

On running adk_app.operation_schemas() stream_query is missing for newly deployed agents. Old agents work fine

bhaskar-nair2 avatar May 12 '25 17:05 bhaskar-nair2

Plus 1 to this.

On running adk_app.operation_schemas() stream_query is missing for newly deployed agents. Old agents work fine

This is weird, and I don't have any other places using steam_query in my agent, so I don't know why it says stream_query is not fully defined.

SankaiAI avatar May 12 '25 21:05 SankaiAI

+1

proninalex avatar May 13 '25 10:05 proninalex

+1

Appreciate it to point it out. I've searched the internet and barely people talking about this issue.

SankaiAI avatar May 13 '25 16:05 SankaiAI

I solved it with dependency google-cloud-aiplatform[adk,agent_engines]==1.90.0. If I use version 1.92.0, I have the same error.

nicolasvasquez avatar May 13 '25 20:05 nicolasvasquez

I solved it with dependency google-cloud-aiplatform[adk,agent_engines]==1.90.0. If I use version 1.92.0, I have the same error.

I solve the probelm through above method. Thank you for helping.

Jacob-9909 avatar May 13 '25 23:05 Jacob-9909

I solved it with dependency google-cloud-aiplatform[adk,agent_engines]==1.90.0. If I use version 1.92.0, I have the same error.

Interesting...

I changed to use 1.90.0 as well, but it doesn't fix the issue.

Screenshots of my code Script to create the deployment: Image

But still failed to generate schema for stream_query: Image

Script to send the message: Image

And still getting the same error: Image

SankaiAI avatar May 14 '25 04:05 SankaiAI

It did not work for me as well using 1.90.0. Same error with the latest version, 1.92.0 right from 1.87.0

Requirement already satisfied: pycparser in /Users/supk/miniconda/envs/google-adk-poc/lib/python3.11/site-packages (from cffi>=1.12->cryptography->authlib>=1.5.1->google-adk>=0.0.2->google-cloud-aiplatform[adk,agent_engines]==1.90.0) (2.22)


(base) supk@FWS-CHE-LT-5272 google-adk % /Users/supk/miniconda/envs/google-adk-poc/bin/python /Users/supk/workspace/google-adk/conversations/test2.py  
/Users/supk/miniconda/envs/google-adk-poc/lib/python3.11/site-packages/google/auth/_default.py:76: UserWarning: Your application has authenticated using end user credentials from Google Cloud SDK without a quota project. You might receive a "quota exceeded" or "API not enabled" error. See the following page for troubleshooting: https://cloud.google.com/docs/authentication/adc-troubleshooting/user-creds. 
  warnings.warn(_CLOUD_SDK_CREDENTIALS_WARNING)
<vertexai.agent_engines._agent_engines.AgentEngine object at 0x11a8ef810> 
resource name: projects/916636527528/locations/us-central1/reasoningEngines/7754996248192483328
Traceback (most recent call last):
  File "/Users/supk/workspace/google-adk/conversations/test2.py", line 90, in <module>
    test()
  File "/Users/supk/workspace/google-adk/conversations/test2.py", line 55, in test
    for event in agent.stream_query(
                 ^^^^^^^^^^^^^^^^^^
AttributeError: 'AgentEngine' object has no attribute 'stream_query'

pksukumar avatar May 14 '25 09:05 pksukumar

I solved it with dependency google-cloud-aiplatform[adk,agent_engines]==1.90.0. If I use version 1.92.0, I have the same error.

Interesting...

I changed to use 1.90.0 as well, but it doesn't fix the issue.

Screenshots of my code Script to create the deployment: Image

But still failed to generate schema for stream_query: Image

Script to send the message: Image

And still getting the same error: Image

But, What version did you install in your environment? I'm use 1.90.0 in both sides. In the requirements section, in the agent_engines.create method, and in my environment. These are my requirement for my project according to poetry:

Image

nicolasvasquez avatar May 14 '25 15:05 nicolasvasquez

@hangfei Hi Hangfei, do you have any update for us?

SankaiAI avatar May 14 '25 19:05 SankaiAI

This code technically sits in the vertex ai package. Could anyone whos code is working tell me what vertex ai version are they on?

bhaskar-nair2 avatar May 14 '25 19:05 bhaskar-nair2

I solved it with dependency google-cloud-aiplatform[adk,agent_engines]==1.90.0. If I use version 1.92.0, I have the same error.

Interesting...

I changed to use 1.90.0 as well, but it doesn't fix the issue.

Screenshots of my code Script to create the deployment: Image

But still failed to generate schema for stream_query: Image

Script to send the message: Image

And still getting the same error: Image

But, What version did you install in your environment? I'm use 1.90.0 in both sides. In the requirements section, in the agent_engines.create method, and in my environment. These are my requirement for my project according to poetry:

Image

Locally, I use 1.92.0

SankaiAI avatar May 14 '25 19:05 SankaiAI

+1 Moving local and deployed agent to google-cloud-aiplatform[adk,agent_engines]==1.90.0 works @SankaiAI I made it work by redeploying the agent and then deleting the local .venv and reinstalling the deps

bhaskar-nair2 avatar May 14 '25 20:05 bhaskar-nair2

I think it is solved in this commit python-aiplatform@674beaa. I guess we'll have to wait for the next version to have that commit.

nicolasvasquez avatar May 14 '25 21:05 nicolasvasquez

Workaround using "streaming_agent_run_with_events" method.

session = agent_engine.create_session(user_id="foo")

request = {
    "user_id": "foo",
    "session_id": session["id"],
    "message": {
        "role": "user",
        "parts": [{"text": "Hello!"}]
    },
    "events": [],
    "artifacts": [],
    "authorizations": {}
}
request_json = json.dumps(request)

for event in agent_engine.streaming_agent_run_with_events(request_json=request_json):
    print(event)

No documentation for this method at all.

sw-savop avatar May 15 '25 11:05 sw-savop

any fix for this?still dont work chaging google-cloud-aiplatform[adk,agent_engines]==1.90.0 works in local but not in remote

dominicdev avatar May 15 '25 14:05 dominicdev

any fix for this?still dont work chaging google-cloud-aiplatform[adk,agent_engines]==1.90.0 works in local but not in remote

Still looking around 🥲

SankaiAI avatar May 15 '25 16:05 SankaiAI

+1 Moving local and deployed agent to google-cloud-aiplatform[adk,agent_engines]==1.90.0 works @SankaiAI I made it work by redeploying the agent and then deleting the local .venv and reinstalling the deps

I did the same thing, but it didn't work for me! Would you mind sharing your script creating the remote app?

SankaiAI avatar May 15 '25 16:05 SankaiAI

@SankaiAI Here's my deploy script.

import os
from dotenv import load_dotenv
import vertexai
from vertexai import agent_engines
from vertexai.preview import reasoning_engines
import logging
from dotenv import set_key
from gmail_agent.agent import gmail_agent

load_dotenv()

logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)

GOOGLE_CLOUD_PROJECT = os.getenv("GOOGLE_CLOUD_PROJECT")
GOOGLE_CLOUD_LOCATION = os.getenv("GOOGLE_CLOUD_LOCATION")
STAGING_BUCKET = os.getenv("STAGING_BUCKET")
# Define the path to the .env file relative to this script
ENV_FILE_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", ".env"))

vertexai.init(
    project=GOOGLE_CLOUD_PROJECT,
    location=GOOGLE_CLOUD_LOCATION,
    staging_bucket=STAGING_BUCKET,
)

# Function to update the .env file
def update_env_file(agent_engine_id, env_file_path):
    """Updates the .env file with the agent engine ID."""
    try:
        set_key(env_file_path, "AGENT_ENGINE_ID", agent_engine_id)
        print(f"Updated AGENT_ENGINE_ID in {env_file_path} to {agent_engine_id}")
    except Exception as e:
        print(f"Error updating .env file: {e}")

print("deploying app...")

app = reasoning_engines.AdkApp(
    agent= gmail_agent,
    enable_tracing=True,
)

logging.debug("deploying agent to agent engine:")

remote_app = agent_engines.create(
    app,
    display_name="gmail_agent",
    requirements=[
        "google-cloud-aiplatform[adk,agent-engines,llama-index]==1.90.0",
        "google-adk",
        "python-dotenv",
        "google-auth",
        "tqdm",
        "requests",
        "pydantic-settings",
        "tabulate",
        "requests",
        "cloudpickle==3.0"
    ],
    extra_packages=[
        "./gmail_agent",
    ],
)

# log remote_app
logging.info(f"Deployed agent to Vertex AI Agent Engine successfully, resource name: {remote_app.resource_name}")

# Update the .env file with the new Agent Engine ID
update_env_file(remote_app.resource_name, ENV_FILE_PATH)

bhaskar-nair2 avatar May 15 '25 17:05 bhaskar-nair2

@bhaskar-nair2 did you try using stream_query?

dominicdev avatar May 16 '25 00:05 dominicdev