Skip to content

Commit 579c1ad

Browse files
authored
Merge branch 'main' into fix/improve-adk-web-error-message
2 parents becc786 + af74eba commit 579c1ad

85 files changed

Lines changed: 4431 additions & 1425 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎contributing/samples/adk_pr_triaging_agent/agent.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,10 @@ def get_pull_request_details(pr_number: int) -> str:
6969
repository(owner: $owner, name: $repo) {
7070
pullRequest(number: $prNumber) {
7171
id
72+
number
7273
title
7374
body
75+
state
7476
author {
7577
login
7678
}

‎contributing/samples/adk_pr_triaging_agent/main.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# limitations under the License.
1414

1515
import asyncio
16+
import logging
1617
import time
1718

1819
from adk_pr_triaging_agent import agent
@@ -21,11 +22,14 @@
2122
from adk_pr_triaging_agent.settings import REPO
2223
from adk_pr_triaging_agent.utils import call_agent_async
2324
from adk_pr_triaging_agent.utils import parse_number_string
25+
from google.adk.cli.utils import logs
2426
from google.adk.runners import InMemoryRunner
2527

2628
APP_NAME = "adk_pr_triaging_app"
2729
USER_ID = "adk_pr_triaging_user"
2830

31+
logs.setup_adk_logger(level=logging.DEBUG)
32+
2933

3034
async def main():
3135
runner = InMemoryRunner(
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# OAuth Sample
2+
3+
## Introduction
4+
5+
This sample data science agent uses Agent Engine Code Execution Sandbox to execute LLM generated code.
6+
7+
8+
## How to use
9+
10+
* 1. Follow https://cloud.google.com/vertex-ai/generative-ai/docs/agent-engine/code-execution/overview to create a code execution sandbox environment.
11+
12+
* 2. Replace the SANDBOX_RESOURCE_NAME with the one you just created. If you dont want to create a new sandbox environment directly, the Agent Engine Code Execution Sandbox will create one for you by default using the AGENT_ENGINE_RESOURCE_NAME you specified, however, please ensure to clean up sandboxes after use, otherwise, it will consume quotas.
13+
14+
15+
## Sample prompt
16+
17+
* Can you write a function that calculates the sum from 1 to 100.
18+
* The dataset is given as below. Store,Date,Weekly_Sales,Holiday_Flag,Temperature,Fuel_Price,CPI,Unemployment Store 1,2023-06-01,1000,0,70,3.0,200,5 Store 2,2023-06-02,1200,1,80,3.5,210,6 Store 3,2023-06-03,1400,0,90,4.0,220,7 Store 4,2023-06-04,1600,1,70,4.5,230,8 Store 5,2023-06-05,1800,0,80,5.0,240,9 Store 6,2023-06-06,2000,1,90,5.5,250,10 Store 7,2023-06-07,2200,0,90,6.0,260,11 Plot a scatter plot showcasing the relationship between Weekly Sales and Temperature for each store, distinguishing stores with a Holiday Flag.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Copyright 2025 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from . import agent
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# Copyright 2025 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
"""Data science agent."""
16+
17+
from google.adk.agents.llm_agent import Agent
18+
from google.adk.code_executors.agent_engine_sandbox_code_executor import AgentEngineSandboxCodeExecutor
19+
20+
21+
def base_system_instruction():
22+
"""Returns: data science agent system instruction."""
23+
24+
return """
25+
# Guidelines
26+
27+
**Objective:** Assist the user in achieving their data analysis goals within the context of a Python Colab notebook, **with emphasis on avoiding assumptions and ensuring accuracy.** Reaching that goal can involve multiple steps. When you need to generate code, you **don't** need to solve the goal in one go. Only generate the next step at a time.
28+
29+
**Code Execution:** All code snippets provided will be executed within the Colab environment.
30+
31+
**Statefulness:** All code snippets are executed and the variables stays in the environment. You NEVER need to re-initialize variables. You NEVER need to reload files. You NEVER need to re-import libraries.
32+
33+
**Output Visibility:** Always print the output of code execution to visualize results, especially for data exploration and analysis. For example:
34+
- To look a the shape of a pandas.DataFrame do:
35+
```tool_code
36+
print(df.shape)
37+
```
38+
The output will be presented to you as:
39+
```tool_outputs
40+
(49, 7)
41+
42+
```
43+
- To display the result of a numerical computation:
44+
```tool_code
45+
x = 10 ** 9 - 12 ** 5
46+
print(f'{{x=}}')
47+
```
48+
The output will be presented to you as:
49+
```tool_outputs
50+
x=999751168
51+
52+
```
53+
- You **never** generate ```tool_outputs yourself.
54+
- You can then use this output to decide on next steps.
55+
- Print just variables (e.g., `print(f'{{variable=}}')`.
56+
57+
**No Assumptions:** **Crucially, avoid making assumptions about the nature of the data or column names.** Base findings solely on the data itself. Always use the information obtained from `explore_df` to guide your analysis.
58+
59+
**Available files:** Only use the files that are available as specified in the list of available files.
60+
61+
**Data in prompt:** Some queries contain the input data directly in the prompt. You have to parse that data into a pandas DataFrame. ALWAYS parse all the data. NEVER edit the data that are given to you.
62+
63+
**Answerability:** Some queries may not be answerable with the available data. In those cases, inform the user why you cannot process their query and suggest what type of data would be needed to fulfill their request.
64+
65+
"""
66+
67+
68+
root_agent = Agent(
69+
model="gemini-2.0-flash-001",
70+
name="agent_engine_code_execution_agent",
71+
instruction=base_system_instruction() + """
72+
73+
74+
You need to assist the user with their queries by looking at the data and the context in the conversation.
75+
You final answer should summarize the code and code execution relevant to the user query.
76+
77+
You should include all pieces of data to answer the user query, such as the table from code execution results.
78+
If you cannot answer the question directly, you should follow the guidelines above to generate the next step.
79+
If the question can be answered directly with writing any code, you should do that.
80+
If you doesn't have enough data to answer the question, you should ask for clarification from the user.
81+
82+
You should NEVER install any package on your own like `pip install ...`.
83+
When plotting trends, you should make sure to sort and order the data by the x-axis.
84+
85+
86+
""",
87+
code_executor=AgentEngineSandboxCodeExecutor(
88+
# Replace with your sandbox resource name if you already have one.
89+
sandbox_resource_name="SANDBOX_RESOURCE_NAME",
90+
# "projects/vertex-agent-loadtest/locations/us-central1/reasoningEngines/6842889780301135872/sandboxEnvironments/6545148628569161728",
91+
# Replace with agent engine resource name used for creating sandbox if
92+
# sandbox_resource_name is not set.
93+
agent_engine_resource_name="AGENT_ENGINE_RESOURCE_NAME",
94+
),
95+
)

‎contributing/samples/built_in_multi_tools/agent.py‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
from dotenv import load_dotenv
1919
from google.adk import Agent
20-
from google.adk.tools.google_search_tool import google_search
20+
from google.adk.tools.google_search_tool import GoogleSearchTool
2121
from google.adk.tools.tool_context import ToolContext
2222
from google.adk.tools.vertex_ai_search_tool import VertexAiSearchTool
2323

@@ -57,7 +57,9 @@ def roll_die(sides: int, tool_context: ToolContext) -> int:
5757
""",
5858
tools=[
5959
roll_die,
60-
VertexAiSearchTool(data_store_id=VERTEXAI_DATASTORE_ID),
61-
google_search,
60+
VertexAiSearchTool(
61+
data_store_id=VERTEXAI_DATASTORE_ID, bypass_multi_tools_limit=True
62+
),
63+
GoogleSearchTool(bypass_multi_tools_limit=True),
6264
],
6365
)
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# Computer Use Agent
2+
3+
This directory contains a computer use agent that can operate a browser to complete user tasks. The agent uses Playwright to control a Chromium browser and can interact with web pages by taking screenshots, clicking, typing, and navigating.
4+
5+
This agent is to demo the usage of ComputerUseToolset.
6+
7+
8+
## Overview
9+
10+
The computer use agent consists of:
11+
- `agent.py`: Main agent configuration using Google's gemini-2.5-computer-use-preview-10-2025 model
12+
- `playwright.py`: Playwright-based computer implementation for browser automation
13+
- `requirements.txt`: Python dependencies
14+
15+
## Setup
16+
17+
### 1. Install Python Dependencies
18+
19+
Install the required Python packages from the requirements file:
20+
21+
```bash
22+
uv pip install -r internal/samples/computer_use/requirements.txt
23+
```
24+
25+
### 2. Install Playwright Dependencies
26+
27+
Install Playwright's system dependencies for Chromium:
28+
29+
```bash
30+
playwright install-deps chromium
31+
```
32+
33+
### 3. Install Chromium Browser
34+
35+
Install the Chromium browser for Playwright:
36+
37+
```bash
38+
playwright install chromium
39+
```
40+
41+
## Usage
42+
43+
### Running the Agent
44+
45+
To start the computer use agent, run the following command from the project root:
46+
47+
```bash
48+
adk web internal/samples
49+
```
50+
51+
This will start the ADK web interface where you can interact with the computer_use agent.
52+
53+
### Example Queries
54+
55+
Once the agent is running, you can send queries like:
56+
57+
```
58+
find me a flight from SF to Hawaii on next Monday, coming back on next Friday. start by navigating directly to flights.google.com
59+
```
60+
61+
The agent will:
62+
1. Open a browser window
63+
2. Navigate to the specified website
64+
3. Interact with the page elements to complete your task
65+
4. Provide updates on its progress
66+
67+
### Other Example Tasks
68+
69+
- Book hotel reservations
70+
- Search for products online
71+
- Fill out forms
72+
- Navigate complex websites
73+
- Research information across multiple pages
74+
75+
## Technical Details
76+
77+
- **Model**: Uses Google's `gemini-2.5-computer-use-preview-10-2025` model for computer use capabilities
78+
- **Browser**: Automated Chromium browser via Playwright
79+
- **Screen Size**: Configured for 600x800 resolution
80+
- **Tools**: Uses ComputerUseToolset for screen capture, clicking, typing, and scrolling
81+
82+
## Troubleshooting
83+
84+
If you encounter issues:
85+
86+
1. **Playwright not found**: Make sure you've run both `playwright install-deps chromium` and `playwright install chromium`
87+
2. **Dependencies missing**: Verify all packages from `requirements.txt` are installed
88+
3. **Browser crashes**: Check that your system supports Chromium and has sufficient resources
89+
4. **Permission errors**: Ensure your user has permission to run browser automation tools
90+
91+
## Notes
92+
93+
- The agent operates in a controlled browser environment
94+
- Screenshots are taken to help the agent understand the current state
95+
- The agent will provide updates on its actions as it works
96+
- Be patient as complex tasks may take some time to complete
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Copyright 2025 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from google.adk import Agent
16+
from google.adk.models.google_llm import Gemini
17+
from google.adk.tools.computer_use.computer_use_toolset import ComputerUseToolset
18+
from typing_extensions import override
19+
20+
from .playwright import PlaywrightComputer
21+
22+
root_agent = Agent(
23+
model='gemini-2.5-computer-use-preview-10-2025',
24+
name='hello_world_agent',
25+
description=(
26+
'computer use agent that can operate a browser on a computer to finish'
27+
' user tasks'
28+
),
29+
instruction="""
30+
you are a computer use agent
31+
""",
32+
tools=[
33+
ComputerUseToolset(computer=PlaywrightComputer(screen_size=(1280, 936)))
34+
],
35+
)

0 commit comments

Comments
 (0)