|
18 | 18 |
|
19 | 19 | from google.adk.agents.llm_agent import LlmAgent |
20 | 20 | from google.adk.integrations.agent_registry import AgentRegistry |
| 21 | +from google.adk.models.google_llm import Gemini |
21 | 22 |
|
22 | 23 | # Project and location can be set via environment variables: |
23 | 24 | # GOOGLE_CLOUD_PROJECT and GOOGLE_CLOUD_LOCATION |
|
27 | 28 | # Initialize Agent Registry client |
28 | 29 | registry = AgentRegistry(project_id=project_id, location=location) |
29 | 30 |
|
| 31 | +# List agents, MCP servers, and endpoints resource names from the registry. |
| 32 | +# They can be used to initialize the agent, toolset, and model below. |
30 | 33 | print(f"Listing agents in {project_id}/{location}...") |
31 | 34 | agents = registry.list_agents() |
32 | 35 | for agent in agents.get("agents", []): |
|
37 | 40 | for server in mcp_servers.get("mcpServers", []): |
38 | 41 | print(f"- MCP Server: {server.get('displayName')} ({server.get('name')})") |
39 | 42 |
|
| 43 | +print(f"\nListing endpoints in {project_id}/{location}...") |
| 44 | +endpoints = registry.list_endpoints() |
| 45 | +for endpoint in endpoints.get("endpoints", []): |
| 46 | + print(f"- Endpoint: {endpoint.get('displayName')} ({endpoint.get('name')})") |
| 47 | + |
40 | 48 | # Example of using a specific agent or MCP server from the registry: |
41 | 49 | # (Note: These names should be full resource names as returned by list methods) |
42 | 50 |
|
|
52 | 60 | f"projects/{project_id}/locations/{location}/mcpServers/MCP_SERVER_NAME" |
53 | 61 | ) |
54 | 62 |
|
| 63 | +# 3. Getting a specific model endpoint configuration |
| 64 | +# This returns a string like: |
| 65 | +# "projects/adk12345/locations/us-central1/publishers/google/models/gemini-2.5-flash" |
| 66 | +# TODO: Replace ENDPOINT_NAME with your endpoint name |
| 67 | +model_name = registry.get_model_name( |
| 68 | + f"projects/{project_id}/locations/{location}/endpoints/ENDPOINT_NAME" |
| 69 | +) |
| 70 | + |
| 71 | +# Initialize the model using the resolved model name from registry. |
| 72 | +gemini_model = Gemini(model=model_name) |
| 73 | + |
55 | 74 | root_agent = LlmAgent( |
56 | | - model="gemini-2.5-flash", |
| 75 | + model=gemini_model, |
57 | 76 | name="discovery_agent", |
58 | 77 | instruction=( |
59 | 78 | "You have access to tools and sub-agents discovered via Registry." |
|
0 commit comments