google adk - how to consume agent deployed to vertex ai or agentic platform
To consume Agentic Platform (Vertex AI), we just need to use the following code to call from python.
So the endpoint can be obtained from here:
Then ensure you have the vertexai libraries installed. You can use either this PYPI package - google-cloud-aiplatform or google-adk.
And then we have the codes here
import asyncio
import vertexai
LOCATION = "us-central1"
client = vertexai.Client(
location=LOCATION,
)
# Copy from your AI Platform
# "projects/PROJECT_ID/locations/us-central1/reasoningEngines/ENGINE_ID"
REASONING_ENGINE_ID = "projects/PROJECT_ID/locations/us-central1/reasoningEngines/ENGINE_ID"
# if REASONING_ENGINE_ID is None:
# try:
# with open("../deployment_metadata.json") as f:
# metadata = json.load(f)
# REASONING_ENGINE_ID = metadata.get("remote_agent_engine_id")
# except (FileNotFoundError, json.JSONDecodeError):
# pass
async def main():
print(f"Using REASONING_ENGINE_ID: {REASONING_ENGINE_ID}")
# Get the existing agent engine
remote_agent_engine = client.agent_engines.get(name=REASONING_ENGINE_ID)
async for event in remote_agent_engine.async_stream_query(
message="hi!", user_id="test"
):
print(event)
asyncio.run(main())
After you run this command, you can see it is being invoke in Agentic platform
Comments