@intentsolutionsio/jeremy-adk-orchestrator 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/plugin.json +23 -0
- package/LICENSE +21 -0
- package/README.md +776 -0
- package/agents/a2a-protocol-manager.md +411 -0
- package/package.json +44 -0
- package/skills/adk-deployment-specialist/SKILL.md +54 -0
- package/skills/adk-deployment-specialist/references/ARD.md +71 -0
- package/skills/adk-deployment-specialist/references/PRD.md +67 -0
- package/skills/adk-deployment-specialist/references/errors.md +106 -0
- package/skills/adk-deployment-specialist/references/examples.md +89 -0
- package/skills/adk-deployment-specialist/references/how-it-works.md +191 -0
- package/skills/adk-deployment-specialist/references/workflow-examples.md +167 -0
- package/skills/adk-deployment-specialist/scripts/deploy-agent.sh +157 -0
- package/skills/adk-deployment-specialist/scripts/test-a2a-protocol.py +277 -0
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
# Error Handling Reference
|
|
2
|
+
|
|
3
|
+
## Deployment Failures
|
|
4
|
+
|
|
5
|
+
### `google.api_core.exceptions.NotFound: 404 Reasoning engine not found`
|
|
6
|
+
- **Cause**: The reasoning engine resource name is incorrect or the resource was deleted.
|
|
7
|
+
- **Fix**: Verify the resource name with `client.agent_engines.list()` and confirm the project/location match.
|
|
8
|
+
|
|
9
|
+
### `google.api_core.exceptions.PermissionDenied: 403 Permission denied on resource`
|
|
10
|
+
- **Cause**: The service account or user lacks required IAM roles.
|
|
11
|
+
- **Fix**: Grant `roles/aiplatform.user` for querying agents, `roles/aiplatform.admin` for creating/deleting. Use `gcloud projects get-iam-policy PROJECT_ID` to audit current bindings.
|
|
12
|
+
|
|
13
|
+
### `google.api_core.exceptions.InvalidArgument: 400 Invalid agent configuration`
|
|
14
|
+
- **Cause**: The agent definition has invalid fields, unsupported model, or malformed tools.
|
|
15
|
+
- **Fix**: Verify the model string (e.g., `gemini-2.5-flash`), ensure all tool functions have proper type hints and docstrings, and check that `requirements` list includes all needed packages.
|
|
16
|
+
|
|
17
|
+
### `google.api_core.exceptions.ResourceExhausted: 429 Quota exceeded`
|
|
18
|
+
- **Cause**: Project has hit the Agent Engine quota (default: 10 reasoning engines per project).
|
|
19
|
+
- **Fix**: Request quota increase via Cloud Console > IAM & Admin > Quotas, or delete unused agents with `client.agent_engines.delete(name=resource_name)`.
|
|
20
|
+
|
|
21
|
+
### Deployment hangs or times out
|
|
22
|
+
- **Cause**: Large dependency list, network issues, or package build failures in the remote environment.
|
|
23
|
+
- **Fix**: Minimize `requirements` to only what the agent needs. Pin exact versions. Check Cloud Build logs via `gcloud builds list --project=PROJECT_ID`.
|
|
24
|
+
|
|
25
|
+
## Authentication & Authorization Issues
|
|
26
|
+
|
|
27
|
+
### `google.auth.exceptions.DefaultCredentialsError: Could not automatically determine credentials`
|
|
28
|
+
- **Cause**: No Application Default Credentials configured.
|
|
29
|
+
- **Fix**: Run `gcloud auth application-default login` for local development, or set `GOOGLE_APPLICATION_CREDENTIALS` to a service account key path. For production, use Workload Identity Federation.
|
|
30
|
+
|
|
31
|
+
### `google.auth.exceptions.RefreshError: ('invalid_grant: Token has been expired or revoked')`
|
|
32
|
+
- **Cause**: Cached credentials are stale or the service account key was rotated.
|
|
33
|
+
- **Fix**: Re-authenticate with `gcloud auth application-default login`. For service accounts, generate a new key and update `GOOGLE_APPLICATION_CREDENTIALS`.
|
|
34
|
+
|
|
35
|
+
### Agent runs but returns permission errors at runtime
|
|
36
|
+
- **Cause**: The Agent Engine service agent (the identity the deployed agent runs as) lacks permissions to call downstream APIs (e.g., GKE, Cloud Run).
|
|
37
|
+
- **Fix**: Grant the Agent Engine service agent (`service-PROJECT_NUMBER@gcp-sa-aiplatform-re.iam.gserviceaccount.com`) the required roles for the APIs the agent's tools invoke.
|
|
38
|
+
|
|
39
|
+
## Orchestration Failures
|
|
40
|
+
|
|
41
|
+
### Sub-agent in SequentialAgent fails mid-pipeline
|
|
42
|
+
- **Cause**: One agent in the chain returned an error or produced output the next agent could not process.
|
|
43
|
+
- **Fix**: Wrap each sub-agent in error-handling instructions. Add a `try/except` around the orchestrator call. Check which sub-agent failed by inspecting the `events` in the runner response.
|
|
44
|
+
|
|
45
|
+
### ParallelAgent produces inconsistent results
|
|
46
|
+
- **Cause**: Parallel sub-agents share no state by default; if they depend on each other's output, results are non-deterministic.
|
|
47
|
+
- **Fix**: Use `SequentialAgent` when ordering matters. Only use `ParallelAgent` for truly independent tasks.
|
|
48
|
+
|
|
49
|
+
### LoopAgent exceeds max iterations
|
|
50
|
+
- **Cause**: The exit condition was never met, or the loop agent's `should_continue` logic has a bug.
|
|
51
|
+
- **Fix**: Set `max_iterations` on the `LoopAgent`. Add explicit exit conditions in the agent's instructions. Monitor iteration count in logs.
|
|
52
|
+
|
|
53
|
+
## SDK & Import Errors
|
|
54
|
+
|
|
55
|
+
### `ImportError: cannot import name 'Agent' from 'google.adk'`
|
|
56
|
+
- **Cause**: Using the wrong import path.
|
|
57
|
+
- **Fix**: The correct import is `from google.adk.agents import Agent`. Other common imports:
|
|
58
|
+
- `from google.adk.agents import SequentialAgent, ParallelAgent, LoopAgent`
|
|
59
|
+
- `from google.adk.runners import Runner`
|
|
60
|
+
- `from google.adk.sessions import VertexAiSessionService`
|
|
61
|
+
- `from google.adk.tools import FunctionTool`
|
|
62
|
+
|
|
63
|
+
### `ModuleNotFoundError: No module named 'google.adk'`
|
|
64
|
+
- **Cause**: ADK SDK not installed or wrong Python environment.
|
|
65
|
+
- **Fix**: Install with `pip install google-adk>=1.15.1`. Verify with `python -c "import google.adk; print(google.adk.__version__)"`.
|
|
66
|
+
|
|
67
|
+
## Agent Engine Management (No gcloud CLI)
|
|
68
|
+
|
|
69
|
+
There is no `gcloud ai agents` or `gcloud alpha ai agent-engines` CLI. All Agent Engine management is done via the Python SDK:
|
|
70
|
+
|
|
71
|
+
```python
|
|
72
|
+
import vertexai
|
|
73
|
+
|
|
74
|
+
client = vertexai.Client(project="PROJECT_ID", location="us-central1")
|
|
75
|
+
|
|
76
|
+
# List agents
|
|
77
|
+
agents = client.agent_engines.list()
|
|
78
|
+
|
|
79
|
+
# Get a specific agent
|
|
80
|
+
agent = client.agent_engines.get(
|
|
81
|
+
name="projects/PROJECT/locations/LOC/reasoningEngines/ID"
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
# Create/deploy an agent
|
|
85
|
+
remote = client.agent_engines.create(agent_engine=my_agent, requirements=[...])
|
|
86
|
+
|
|
87
|
+
# Delete an agent
|
|
88
|
+
client.agent_engines.delete(name=agent.resource_name)
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## A2A Protocol Errors
|
|
92
|
+
|
|
93
|
+
### AgentCard not found at `/.well-known/agent-card`
|
|
94
|
+
- **Cause**: The agent does not expose an A2A-compliant AgentCard, or the URL is wrong.
|
|
95
|
+
- **Fix**: Verify the agent was deployed with A2A support. The AgentCard endpoint is `/.well-known/agent-card` (note: no trailing slash). Ensure the agent framework generates this endpoint.
|
|
96
|
+
|
|
97
|
+
### `tasks/send` returns 405 Method Not Allowed
|
|
98
|
+
- **Cause**: The agent endpoint does not support the A2A task submission method.
|
|
99
|
+
- **Fix**: Confirm the agent was built with A2A protocol support (`a2a-sdk`). Check that the server handles POST to `/tasks/send` with JSON-RPC 2.0 format.
|
|
100
|
+
|
|
101
|
+
### Task polling returns stale status
|
|
102
|
+
- **Cause**: Eventual consistency or caching in the agent's task store.
|
|
103
|
+
- **Fix**: Implement exponential backoff in polling (start at 2s, max 30s). Use the task's `updatedAt` timestamp to detect stale responses.
|
|
104
|
+
|
|
105
|
+
---
|
|
106
|
+
*[Tons of Skills](https://tonsofskills.com) by [Intent Solutions](https://intentsolutions.io) | [jeremylongshore.com](https://jeremylongshore.com)*
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# Examples
|
|
2
|
+
|
|
3
|
+
## Natural Language Prompts
|
|
4
|
+
|
|
5
|
+
These prompts activate the skill and demonstrate common usage patterns:
|
|
6
|
+
|
|
7
|
+
### Deployment
|
|
8
|
+
- "Deploy this ADK agent to Agent Engine with session persistence enabled."
|
|
9
|
+
- "Create a reasoning engine from my agent.py with gemini-2.5-flash."
|
|
10
|
+
- "Deploy my multi-agent pipeline to Vertex AI Agent Engine in us-central1."
|
|
11
|
+
|
|
12
|
+
### Agent Management (SDK)
|
|
13
|
+
- "List all deployed agents in my project using the Vertex AI SDK."
|
|
14
|
+
- "Get the status of reasoning engine ID 12345 in us-central1."
|
|
15
|
+
- "Delete the old version of my sentiment-analysis agent from Agent Engine."
|
|
16
|
+
|
|
17
|
+
### Multi-Agent Orchestration
|
|
18
|
+
- "Build a SequentialAgent pipeline: validate config, deploy resources, run health check."
|
|
19
|
+
- "Create a ParallelAgent that runs data extraction and sentiment analysis simultaneously."
|
|
20
|
+
- "Set up a LoopAgent that retries deployment until health check passes (max 5 iterations)."
|
|
21
|
+
|
|
22
|
+
### A2A Protocol
|
|
23
|
+
- "Expose an A2A AgentCard at `/.well-known/agent-card` for my deployed agent."
|
|
24
|
+
- "Send a task to the agent at [endpoint] using A2A JSON-RPC protocol."
|
|
25
|
+
- "Discover capabilities of the agent at [endpoint] via its AgentCard."
|
|
26
|
+
|
|
27
|
+
### Session & Memory
|
|
28
|
+
- "Create a stateful agent with VertexAiSessionService for cross-turn persistence."
|
|
29
|
+
- "Set up a runner with session auto-save for compliance."
|
|
30
|
+
- "Query my deployed agent with session_id to maintain conversation context."
|
|
31
|
+
|
|
32
|
+
## Code Snippets
|
|
33
|
+
|
|
34
|
+
### Deploy an Agent
|
|
35
|
+
```python
|
|
36
|
+
import vertexai
|
|
37
|
+
from google.adk.agents import Agent
|
|
38
|
+
|
|
39
|
+
agent = Agent(
|
|
40
|
+
name="my-agent",
|
|
41
|
+
model="gemini-2.5-flash",
|
|
42
|
+
instruction="You help users analyze data.",
|
|
43
|
+
tools=[my_analysis_tool],
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
client = vertexai.Client(project="my-project", location="us-central1")
|
|
47
|
+
remote = client.agent_engines.create(
|
|
48
|
+
agent_engine=agent,
|
|
49
|
+
requirements=["google-adk>=1.15.1"],
|
|
50
|
+
display_name="data-analyst",
|
|
51
|
+
)
|
|
52
|
+
print(f"Deployed: {remote.resource_name}")
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### List and Query Agents
|
|
56
|
+
```python
|
|
57
|
+
import vertexai
|
|
58
|
+
|
|
59
|
+
client = vertexai.Client(project="my-project", location="us-central1")
|
|
60
|
+
|
|
61
|
+
# List all agents
|
|
62
|
+
for agent in client.agent_engines.list():
|
|
63
|
+
print(f"{agent.display_name}: {agent.resource_name}")
|
|
64
|
+
|
|
65
|
+
# Get and query a specific agent
|
|
66
|
+
agent = client.agent_engines.get(
|
|
67
|
+
name="projects/my-project/locations/us-central1/reasoningEngines/12345"
|
|
68
|
+
)
|
|
69
|
+
response = agent.query(input="Summarize Q3 revenue trends")
|
|
70
|
+
print(response)
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### Multi-Agent Sequential Pipeline
|
|
74
|
+
```python
|
|
75
|
+
from google.adk.agents import Agent, SequentialAgent
|
|
76
|
+
|
|
77
|
+
extractor = Agent(name="extractor", model="gemini-2.5-flash", instruction="Extract key data points.")
|
|
78
|
+
analyzer = Agent(name="analyzer", model="gemini-2.5-pro", instruction="Analyze extracted data.")
|
|
79
|
+
reporter = Agent(name="reporter", model="gemini-2.5-flash", instruction="Generate summary report.")
|
|
80
|
+
|
|
81
|
+
pipeline = SequentialAgent(
|
|
82
|
+
name="etl-pipeline",
|
|
83
|
+
sub_agents=[extractor, analyzer, reporter],
|
|
84
|
+
description="Extract -> Analyze -> Report",
|
|
85
|
+
)
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
---
|
|
89
|
+
*[Tons of Skills](https://tonsofskills.com) by [Intent Solutions](https://intentsolutions.io) | [jeremylongshore.com](https://jeremylongshore.com)*
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
# How It Works
|
|
2
|
+
|
|
3
|
+
## How It Works
|
|
4
|
+
|
|
5
|
+
### Phase 1: Agent Architecture Design
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
User Request -> Analyze:
|
|
9
|
+
- Single agent vs multi-agent system?
|
|
10
|
+
- Tools needed (Code Exec, Memory Bank, custom tools)?
|
|
11
|
+
- Orchestration pattern (Sequential, Parallel, Loop)?
|
|
12
|
+
- Integration with LangChain/Genkit?
|
|
13
|
+
- Deployment target (local, Agent Engine, Cloud Run)?
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
### Phase 2: ADK Agent Implementation
|
|
17
|
+
|
|
18
|
+
**Simple Agent (Python)**:
|
|
19
|
+
```python
|
|
20
|
+
from google.adk.agents import Agent
|
|
21
|
+
|
|
22
|
+
# Define agent with tools
|
|
23
|
+
agent = Agent(
|
|
24
|
+
model="gemini-2.5-flash",
|
|
25
|
+
name="gcp-deployer",
|
|
26
|
+
description="GCP deployment specialist",
|
|
27
|
+
instruction="""
|
|
28
|
+
You are a GCP deployment specialist.
|
|
29
|
+
Help users deploy resources securely.
|
|
30
|
+
""",
|
|
31
|
+
tools=[my_deploy_tool, my_validate_tool],
|
|
32
|
+
)
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
**Multi-Agent Orchestrator (Python)**:
|
|
36
|
+
```python
|
|
37
|
+
from google.adk.agents import Agent, SequentialAgent
|
|
38
|
+
|
|
39
|
+
# Define specialized sub-agents
|
|
40
|
+
validator_agent = Agent(
|
|
41
|
+
name="validator",
|
|
42
|
+
model="gemini-2.5-flash",
|
|
43
|
+
instruction="Validate GCP configurations",
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
deployer_agent = Agent(
|
|
47
|
+
name="deployer",
|
|
48
|
+
model="gemini-2.5-flash",
|
|
49
|
+
instruction="Deploy validated GCP resources",
|
|
50
|
+
tools=[deploy_tool],
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
monitor_agent = Agent(
|
|
54
|
+
name="monitor",
|
|
55
|
+
model="gemini-2.5-flash",
|
|
56
|
+
instruction="Monitor deployment status",
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
# Orchestrate with Sequential pattern
|
|
60
|
+
orchestrator = SequentialAgent(
|
|
61
|
+
name="deploy-orchestrator",
|
|
62
|
+
sub_agents=[validator_agent, deployer_agent, monitor_agent],
|
|
63
|
+
description="Coordinate validation -> deployment -> monitoring",
|
|
64
|
+
)
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Phase 3: Code Execution Integration
|
|
68
|
+
|
|
69
|
+
The Code Execution tool provides:
|
|
70
|
+
- **Security**: Isolated sandbox environment, no access to your system
|
|
71
|
+
- **State Persistence**: Stateful within a session
|
|
72
|
+
- **Stateful Sessions**: Builds on previous executions
|
|
73
|
+
|
|
74
|
+
```python
|
|
75
|
+
from google.adk.agents import Agent
|
|
76
|
+
from google.adk.tools import built_in_code_execution
|
|
77
|
+
|
|
78
|
+
# Agent with Code Execution
|
|
79
|
+
agent = Agent(
|
|
80
|
+
name="code-runner",
|
|
81
|
+
model="gemini-2.5-flash",
|
|
82
|
+
tools=[built_in_code_execution],
|
|
83
|
+
instruction="""
|
|
84
|
+
Execute code in the secure sandbox.
|
|
85
|
+
Remember previous operations in this session.
|
|
86
|
+
""",
|
|
87
|
+
)
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Phase 4: Session & Memory Integration
|
|
91
|
+
|
|
92
|
+
Persistent conversation state across interactions:
|
|
93
|
+
|
|
94
|
+
```python
|
|
95
|
+
from google.adk.agents import Agent
|
|
96
|
+
from google.adk.sessions import VertexAiSessionService
|
|
97
|
+
from google.adk.runners import Runner
|
|
98
|
+
|
|
99
|
+
agent = Agent(
|
|
100
|
+
name="stateful-agent",
|
|
101
|
+
model="gemini-2.5-flash",
|
|
102
|
+
instruction="Remember user preferences and project context",
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
# Session service persists state across turns
|
|
106
|
+
session_service = VertexAiSessionService(
|
|
107
|
+
project="my-project",
|
|
108
|
+
location="us-central1",
|
|
109
|
+
)
|
|
110
|
+
|
|
111
|
+
runner = Runner(
|
|
112
|
+
app_name="my-app",
|
|
113
|
+
agent=agent,
|
|
114
|
+
session_service=session_service,
|
|
115
|
+
)
|
|
116
|
+
|
|
117
|
+
# Session 1 (Monday) — state persists via session_id
|
|
118
|
+
# runner.run(user_id="user-123", session_id="sess-abc", ...)
|
|
119
|
+
# Session 2 (Wednesday) — same session_id, agent remembers context
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### Phase 5: Deploy to Agent Engine
|
|
123
|
+
|
|
124
|
+
Deploy agent to Vertex AI Agent Engine using the Python SDK:
|
|
125
|
+
|
|
126
|
+
```python
|
|
127
|
+
import vertexai
|
|
128
|
+
|
|
129
|
+
# Initialize the Vertex AI client
|
|
130
|
+
client = vertexai.Client(project="my-project", location="us-central1")
|
|
131
|
+
|
|
132
|
+
# Deploy agent to Agent Engine (creates a Reasoning Engine resource)
|
|
133
|
+
remote_agent = client.agent_engines.create(
|
|
134
|
+
agent_engine=agent,
|
|
135
|
+
requirements=["google-adk>=1.15.1", "google-cloud-aiplatform>=1.120.0"],
|
|
136
|
+
display_name="gcp-deployer-agent",
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
print(f"Agent deployed: {remote_agent.resource_name}")
|
|
140
|
+
# projects/my-project/locations/us-central1/reasoningEngines/12345
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
After deployment, the agent is accessible via the Vertex AI API. There is no separate A2A HTTP endpoint automatically exposed -- you interact with the deployed agent through the SDK:
|
|
144
|
+
|
|
145
|
+
```python
|
|
146
|
+
# Query the deployed agent
|
|
147
|
+
response = remote_agent.query(input="Deploy a GKE cluster named prod-api")
|
|
148
|
+
print(response)
|
|
149
|
+
|
|
150
|
+
# List all deployed agents
|
|
151
|
+
agents = client.agent_engines.list()
|
|
152
|
+
for a in agents:
|
|
153
|
+
print(f"{a.display_name}: {a.resource_name}")
|
|
154
|
+
|
|
155
|
+
# Get a specific agent by resource name
|
|
156
|
+
agent = client.agent_engines.get(
|
|
157
|
+
name="projects/my-project/locations/us-central1/reasoningEngines/12345"
|
|
158
|
+
)
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
### Phase 6: A2A Protocol for Inter-Agent Communication
|
|
162
|
+
|
|
163
|
+
The A2A (Agent-to-Agent) protocol enables standardized communication between agents. When deploying with A2A support, agents expose an AgentCard at `/.well-known/agent-card`:
|
|
164
|
+
|
|
165
|
+
```python
|
|
166
|
+
import requests
|
|
167
|
+
|
|
168
|
+
def discover_agent(agent_url: str) -> dict:
|
|
169
|
+
"""Discover agent capabilities via A2A AgentCard."""
|
|
170
|
+
response = requests.get(f"{agent_url}/.well-known/agent-card")
|
|
171
|
+
card = response.json()
|
|
172
|
+
print(f"Agent: {card['name']}")
|
|
173
|
+
print(f"Skills: {[s['id'] for s in card.get('skills', [])]}")
|
|
174
|
+
return card
|
|
175
|
+
|
|
176
|
+
def send_task(agent_url: str, message: str, token: str) -> dict:
|
|
177
|
+
"""Send a task via A2A protocol."""
|
|
178
|
+
response = requests.post(
|
|
179
|
+
f"{agent_url}/tasks/send",
|
|
180
|
+
json={
|
|
181
|
+
"jsonrpc": "2.0",
|
|
182
|
+
"method": "tasks/send",
|
|
183
|
+
"params": {
|
|
184
|
+
"message": {"role": "user", "parts": [{"text": message}]}
|
|
185
|
+
},
|
|
186
|
+
"id": "req-1"
|
|
187
|
+
},
|
|
188
|
+
headers={"Authorization": f"Bearer {token}"},
|
|
189
|
+
)
|
|
190
|
+
return response.json()
|
|
191
|
+
```
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
# Workflow Examples
|
|
2
|
+
|
|
3
|
+
## Workflow Examples
|
|
4
|
+
|
|
5
|
+
### Example 1: GCP Deployment Agent
|
|
6
|
+
|
|
7
|
+
**User**: "Create an ADK agent that deploys GCP resources"
|
|
8
|
+
|
|
9
|
+
**Implementation**:
|
|
10
|
+
```python
|
|
11
|
+
from google.adk.agents import Agent
|
|
12
|
+
from google.adk.tools import FunctionTool
|
|
13
|
+
|
|
14
|
+
def deploy_gke_cluster(cluster_name: str, region: str, node_count: int = 3) -> str:
|
|
15
|
+
"""Deploy a GKE cluster with the given parameters."""
|
|
16
|
+
# Implementation would call GCP APIs
|
|
17
|
+
return f"GKE cluster '{cluster_name}' created in {region} with {node_count} nodes"
|
|
18
|
+
|
|
19
|
+
def deploy_cloud_run(service_name: str, image: str, region: str) -> str:
|
|
20
|
+
"""Deploy a Cloud Run service from a container image."""
|
|
21
|
+
return f"Cloud Run service '{service_name}' deployed from {image} in {region}"
|
|
22
|
+
|
|
23
|
+
deployment_agent = Agent(
|
|
24
|
+
name="gcp-deployer",
|
|
25
|
+
model="gemini-2.5-flash",
|
|
26
|
+
tools=[deploy_gke_cluster, deploy_cloud_run],
|
|
27
|
+
instruction="""
|
|
28
|
+
You are a GCP deployment specialist.
|
|
29
|
+
|
|
30
|
+
CAPABILITIES:
|
|
31
|
+
- Deploy GKE clusters
|
|
32
|
+
- Deploy Cloud Run services
|
|
33
|
+
- Deploy Vertex AI Pipelines
|
|
34
|
+
- Manage IAM permissions
|
|
35
|
+
- Monitor deployments
|
|
36
|
+
|
|
37
|
+
SECURITY:
|
|
38
|
+
- Validate all configurations before deployment
|
|
39
|
+
- Use least-privilege IAM
|
|
40
|
+
- Log all operations
|
|
41
|
+
- Never expose credentials
|
|
42
|
+
""",
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
# Deploy to Agent Engine via Python SDK
|
|
46
|
+
import vertexai
|
|
47
|
+
|
|
48
|
+
client = vertexai.Client(project="my-project", location="us-central1")
|
|
49
|
+
remote_agent = client.agent_engines.create(
|
|
50
|
+
agent_engine=deployment_agent,
|
|
51
|
+
requirements=["google-adk>=1.15.1"],
|
|
52
|
+
display_name="gcp-deployer",
|
|
53
|
+
)
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### Example 2: Multi-Agent Pipeline System
|
|
57
|
+
|
|
58
|
+
**User**: "Build a multi-agent pipeline with ADK orchestrating retrieval and analysis"
|
|
59
|
+
|
|
60
|
+
**Implementation**:
|
|
61
|
+
```python
|
|
62
|
+
from google.adk.agents import Agent, SequentialAgent
|
|
63
|
+
|
|
64
|
+
def retrieve_documents(query: str) -> str:
|
|
65
|
+
"""Retrieve relevant documents from Vertex AI Search."""
|
|
66
|
+
# Implementation calls Vertex AI Search
|
|
67
|
+
return f"Retrieved 5 documents matching: {query}"
|
|
68
|
+
|
|
69
|
+
def analyze_documents(documents: str) -> str:
|
|
70
|
+
"""Analyze retrieved documents and extract insights."""
|
|
71
|
+
return f"Analysis complete: key themes identified from {documents}"
|
|
72
|
+
|
|
73
|
+
# Sub-Agent 1: Document Retriever
|
|
74
|
+
retriever_agent = Agent(
|
|
75
|
+
name="retriever",
|
|
76
|
+
model="gemini-2.5-flash",
|
|
77
|
+
tools=[retrieve_documents],
|
|
78
|
+
instruction="Retrieve relevant documents for the user's query.",
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
# Sub-Agent 2: Document Analyzer
|
|
82
|
+
analyzer_agent = Agent(
|
|
83
|
+
name="analyzer",
|
|
84
|
+
model="gemini-2.5-pro", # More powerful model for analysis
|
|
85
|
+
tools=[analyze_documents],
|
|
86
|
+
instruction="Analyze retrieved documents and generate comprehensive insights.",
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
# Orchestrator runs them in sequence
|
|
90
|
+
orchestrator = SequentialAgent(
|
|
91
|
+
name="rag-pipeline",
|
|
92
|
+
sub_agents=[retriever_agent, analyzer_agent],
|
|
93
|
+
description="First retrieve docs, then generate analysis",
|
|
94
|
+
)
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### Example 3: Deploying and Managing Agents via SDK
|
|
98
|
+
|
|
99
|
+
**User**: "Deploy a GKE cluster agent and check its status"
|
|
100
|
+
|
|
101
|
+
**Implementation**:
|
|
102
|
+
```python
|
|
103
|
+
import vertexai
|
|
104
|
+
|
|
105
|
+
# Initialize client
|
|
106
|
+
client = vertexai.Client(project="my-project", location="us-central1")
|
|
107
|
+
|
|
108
|
+
# Deploy agent
|
|
109
|
+
remote_agent = client.agent_engines.create(
|
|
110
|
+
agent_engine=deployment_agent,
|
|
111
|
+
requirements=["google-adk>=1.15.1", "google-cloud-container>=2.0.0"],
|
|
112
|
+
display_name="gke-deployer",
|
|
113
|
+
)
|
|
114
|
+
print(f"Deployed: {remote_agent.resource_name}")
|
|
115
|
+
|
|
116
|
+
# Query the deployed agent
|
|
117
|
+
response = remote_agent.query(
|
|
118
|
+
input="Deploy GKE cluster named prod-api with 5 nodes in us-central1"
|
|
119
|
+
)
|
|
120
|
+
print(f"Response: {response}")
|
|
121
|
+
|
|
122
|
+
# List all deployed agents
|
|
123
|
+
for agent in client.agent_engines.list():
|
|
124
|
+
print(f" {agent.display_name}: {agent.resource_name}")
|
|
125
|
+
|
|
126
|
+
# Get a specific deployed agent
|
|
127
|
+
agent = client.agent_engines.get(
|
|
128
|
+
name="projects/my-project/locations/us-central1/reasoningEngines/12345"
|
|
129
|
+
)
|
|
130
|
+
print(f"Agent status: {agent.display_name}")
|
|
131
|
+
|
|
132
|
+
# Delete an agent when no longer needed
|
|
133
|
+
# client.agent_engines.delete(name=agent.resource_name)
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### Example 4: Agent with Session Persistence
|
|
137
|
+
|
|
138
|
+
**User**: "Build a stateful agent that remembers context across turns"
|
|
139
|
+
|
|
140
|
+
**Implementation**:
|
|
141
|
+
```python
|
|
142
|
+
from google.adk.agents import Agent
|
|
143
|
+
from google.adk.runners import Runner
|
|
144
|
+
from google.adk.sessions import VertexAiSessionService
|
|
145
|
+
|
|
146
|
+
agent = Agent(
|
|
147
|
+
name="stateful-assistant",
|
|
148
|
+
model="gemini-2.5-flash",
|
|
149
|
+
instruction="You are a helpful assistant. Remember user preferences from prior turns.",
|
|
150
|
+
)
|
|
151
|
+
|
|
152
|
+
session_service = VertexAiSessionService(
|
|
153
|
+
project="my-project",
|
|
154
|
+
location="us-central1",
|
|
155
|
+
)
|
|
156
|
+
|
|
157
|
+
runner = Runner(
|
|
158
|
+
app_name="stateful-app",
|
|
159
|
+
agent=agent,
|
|
160
|
+
session_service=session_service,
|
|
161
|
+
)
|
|
162
|
+
|
|
163
|
+
# Turn 1: User sets preference
|
|
164
|
+
# runner.run(user_id="user-1", session_id="sess-1", new_message=...)
|
|
165
|
+
# Turn 2: Agent remembers preference from Turn 1
|
|
166
|
+
# runner.run(user_id="user-1", session_id="sess-1", new_message=...)
|
|
167
|
+
```
|