AttributeError: 'AgentEngine' object has no attribute 'stream_query'
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:
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
Here are all the available methods for AgentEngine I got, and it looks like there is no stream_query method
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
Plus 1 to this.
On running adk_app.operation_schemas() stream_query is missing for newly deployed agents. Old agents work fine
Plus 1 to this.
On running
adk_app.operation_schemas()stream_queryis 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.
+1
+1
Appreciate it to point it out. I've searched the internet and barely people talking about this issue.
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 solved it with dependency
google-cloud-aiplatform[adk,agent_engines]==1.90.0. If I use version1.92.0, I have the same error.
I solve the probelm through above method. Thank you for helping.
I solved it with dependency
google-cloud-aiplatform[adk,agent_engines]==1.90.0. If I use version1.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:
But still failed to generate schema for stream_query:
Script to send the message:
And still getting the same error:
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'
I solved it with dependency
google-cloud-aiplatform[adk,agent_engines]==1.90.0. If I use version1.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:
But still failed to generate schema for stream_query:
Script to send the message:
And still getting the same error:
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:
@hangfei Hi Hangfei, do you have any update for us?
This code technically sits in the vertex ai package. Could anyone whos code is working tell me what vertex ai version are they on?
I solved it with dependency
google-cloud-aiplatform[adk,agent_engines]==1.90.0. If I use version1.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:
But still failed to generate schema for stream_query:
Script to send the message:
And still getting the same error:
But, What version did you install in your environment? I'm use
1.90.0in both sides. In therequirementssection, in theagent_engines.createmethod, and in my environment. These are my requirement for my project according to poetry:![]()
Locally, I use 1.92.0
+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 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.
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.
any fix for this?still dont work chaging google-cloud-aiplatform[adk,agent_engines]==1.90.0
works in local but not in remote
any fix for this?still dont work chaging
google-cloud-aiplatform[adk,agent_engines]==1.90.0works in local but not in remote
Still looking around 🥲
+1 Moving local and deployed agent to
google-cloud-aiplatform[adk,agent_engines]==1.90.0works @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 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 did you try using stream_query?