How do you test out your deployed instance of agent A2A in vertex AI

How do you test out your deployed instance of agent A2A in vertex AI? I assume that we have already deploy the agent to Vertex AI. 

All you have to do is run the following code - importing the required libraries


import asyncio
import json
import os
import requests
import uuid

import vertexai
from a2a.types import (
    Message,
    MessageSendParams,
    Part,
    Role,
    SendStreamingMessageRequest,
    TextPart,
)
from IPython.display import Markdown, display
from google.adk.artifacts import InMemoryArtifactService
from google.adk.sessions import InMemorySessionService

from app.agent_engine_app import AgentEngineApp
from tests.helpers import (
    build_get_request,
    build_post_request,
    poll_task_completion,
)

Setup your vertex ai client 

LOCATION = "us-central1"

client = vertexai.Client(
    location=LOCATION,
)

Setting up your agent deployed url 

REASONING_ENGINE_ID = "projects/YOUR-PROJECT-ID/locations/us-central1/
reasoningEngines/YOUR-AGENT-DEPLOYED-ID"

print(f"Using REASONING_ENGINE_ID: {REASONING_ENGINE_ID}")

# Extract project_id, location, and engine_id from REASONING_ENGINE_ID
parts = REASONING_ENGINE_ID.split("/")
project_id = parts[1]
location = parts[3]
engine_id = parts[5]

# Construct API endpoints
base_url = f"https://{location}-aiplatform.googleapis.com"
a2a_base_path = f"/v1beta1/projects/{project_id}/locations/{location}/
reasoningEngines/{engine_id}/a2a/v1"

print(f"Base URL: {base_url}")
print(f"A2A base path: {a2a_base_path}")

Fetching your agent card

import google.auth
import google.auth.transport.requests

# Get authentication token
creds, project = google.auth.default()
auth_req = google.auth.transport.requests.Request()
creds.refresh(auth_req)

headers = {"Content-Type": "application/json", "Authorization": f"Bearer {creds.token}"}

# GET request to fetch agent card
response = requests.get(
    f"{base_url}{a2a_base_path}/card",
    headers=headers,
)

print(f"Response status code: {response.status_code}")




Comments

Popular posts from this blog

vllm : Failed to infer device type

NodeJS: Error: spawn EINVAL in window for node version 20.20 and 18.20

android studio kotlin source is null error