chore: import upstream snapshot with attribution
Continuous Integration / Pre-commit Linter (push) Has been cancelled
Continuous Integration / Mypy Check (Python 3.10) (push) Has been cancelled
Continuous Integration / Mypy Check (Python 3.11) (push) Has been cancelled
Continuous Integration / Mypy Check (Python 3.12) (push) Has been cancelled
Continuous Integration / Mypy Check (Python 3.13) (push) Has been cancelled
Continuous Integration / Unit Tests (Python 3.10) (push) Has been cancelled
Continuous Integration / Unit Tests (Python 3.11) (push) Has been cancelled
Continuous Integration / Unit Tests (Python 3.12) (push) Has been cancelled
Continuous Integration / Unit Tests (Python 3.13) (push) Has been cancelled
Continuous Integration / Unit Tests (Python 3.14) (push) Has been cancelled
Continuous Integration / A2A v0.3 Tests (Python 3.10) (push) Has been cancelled
Continuous Integration / A2A v0.3 Tests (Python 3.11) (push) Has been cancelled
Continuous Integration / A2A v0.3 Tests (Python 3.12) (push) Has been cancelled
Copybara PR Handler / close-imported-pr (push) Has been cancelled
Continuous Integration / A2A v0.3 Tests (Python 3.13) (push) Has been cancelled
Continuous Integration / A2A v0.3 Tests (Python 3.14) (push) Has been cancelled

This commit is contained in:
wehub-resource-sync
2026-07-13 13:25:13 +08:00
commit ec2b666284
2231 changed files with 491535 additions and 0 deletions
@@ -0,0 +1,15 @@
# Copyright 2026 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from . import agent
@@ -0,0 +1,96 @@
# Copyright 2026 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Sample agent using Vertex AI Agent Engine Sandbox for computer use.
This sample demonstrates how to use the AgentEngineSandboxComputer with ADK
to create a computer use agent that operates in a remote sandbox environment.
Prerequisites:
1. A GCP project with Agent Engine setup (https://docs.cloud.google.com/agent-builder/agent-engine/set-up)
2. A service account with roles/iam.serviceAccountTokenCreator permission
3. Environment variables in contributing/samples/.env:
- GOOGLE_CLOUD_PROJECT: Your GCP project ID
- VMAAS_SERVICE_ACCOUNT: Your service account email
- VMAAS_SANDBOX_NAME: (Optional) Existing sandbox resource name for BYOS mode
- VMAAS_SANDBOX_TEMPLATE_NAME: (Optional) Sandbox template name to create a new sandbox (mutually exclusive with VMAAS_SANDBOX_NAME)
- VMAAS_SANDBOX_SNAPSHOT_NAME: (Optional) Sandbox snapshot name to create a new sandbox (mutually exclusive with VMAAS_SANDBOX_NAME)
Usage:
# Run via ADK web UI
adk web contributing/samples/sandbox_computer_use
# Run via main.py
cd contributing/samples
python -m sandbox_computer_use.main
"""
import os
from dotenv import load_dotenv
from google.adk import Agent
from google.adk.integrations.vmaas import AgentEngineSandboxComputer
from google.adk.tools.computer_use.computer_use_toolset import ComputerUseToolset
# Load environment variables from .env file
load_dotenv(override=True)
# Configuration from environment variables
PROJECT_ID = os.environ.get("GOOGLE_CLOUD_PROJECT")
SERVICE_ACCOUNT = os.environ.get("VMAAS_SERVICE_ACCOUNT")
# Optional: Use existing sandbox (BYOS mode)
# Format: projects/{project}/locations/{location}/reasoningEngines/{id}/sandboxEnvironments/{id}
SANDBOX_NAME = os.environ.get("SANDBOX_NAME") or os.environ.get(
"VMAAS_SANDBOX_NAME"
)
SANDBOX_TEMPLATE_NAME = os.environ.get("VMAAS_SANDBOX_TEMPLATE_NAME")
SANDBOX_SNAPSHOT_NAME = os.environ.get("VMAAS_SANDBOX_SNAPSHOT_NAME")
# Create the sandbox computer
sandbox_computer = AgentEngineSandboxComputer(
project_id=PROJECT_ID,
service_account_email=SERVICE_ACCOUNT,
sandbox_name=SANDBOX_NAME,
sandbox_template_name=SANDBOX_TEMPLATE_NAME,
sandbox_snapshot_name=SANDBOX_SNAPSHOT_NAME,
search_engine_url="https://www.google.com",
)
# Create agent with the computer use toolset
root_agent = Agent(
model="gemini-2.5-computer-use-preview-10-2025",
name="sandbox_computer_use_agent",
description=(
"A computer use agent that operates a browser in a remote Vertex AI"
" sandbox environment to complete user tasks."
),
instruction="""You are a computer use agent that can operate a web browser
to help users complete tasks. You have access to browser controls including:
- Navigation (go to URLs, back, forward, search)
- Mouse actions (click, hover, scroll, drag and drop)
- Keyboard input (type text, key combinations)
- Screenshots (to see the current state)
When given a task:
1. Think about what steps are needed to accomplish it
2. Take actions one at a time, observing the results
3. If something doesn't work, try alternative approaches
4. Report back when the task is complete or if you encounter issues
Be careful with sensitive information and always respect website terms of service.
""",
tools=[ComputerUseToolset(computer=sandbox_computer)],
)
@@ -0,0 +1,165 @@
# Copyright 2026 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Main script to run the sandbox computer use agent.
This script demonstrates how to run the sandbox computer use agent
programmatically using the InMemoryRunner.
Prerequisites:
1. Set environment variables:
- GOOGLE_CLOUD_PROJECT: Your GCP project ID
- VMAAS_SERVICE_ACCOUNT: Your service account email with
roles/iam.serviceAccountTokenCreator permission
- VMAAS_SANDBOX_NAME: (Optional) Existing sandbox resource name for BYOS mode
- VMAAS_SANDBOX_TEMPLATE_NAME: (Optional) Sandbox template name to create a new sandbox (mutually exclusive with VMAAS_SANDBOX_NAME)
- VMAAS_SANDBOX_SNAPSHOT_NAME: (Optional) Sandbox snapshot name to create a new sandbox (mutually exclusive with VMAAS_SANDBOX_NAME)
Usage:
cd contributing/samples
python -m sandbox_computer_use.main
"""
import asyncio
import os
import time
from dotenv import load_dotenv
from google.adk.cli.utils import logs
from google.adk.runners import InMemoryRunner
from google.adk.sessions.session import Session
from google.genai import types
# Import the agent module
from . import agent
load_dotenv(override=True)
logs.log_to_tmp_folder()
async def run_prompt(
runner: InMemoryRunner,
session: Session,
user_id: str,
message: str,
) -> None:
"""Run a single prompt and print the response.
Args:
runner: The agent runner.
session: The session to use.
user_id: The user ID.
message: The user message.
"""
content = types.Content(
role="user", parts=[types.Part.from_text(text=message)]
)
print(f"\n** User says: {message}")
print("-" * 40)
async for event in runner.run_async(
user_id=user_id,
session_id=session.id,
new_message=content,
):
if event.content and event.content.parts:
for part in event.content.parts:
if part.text:
print(f"** {event.author}: {part.text}")
elif hasattr(part, "inline_data") and part.inline_data:
# Screenshot received
print(f"** {event.author}: [Screenshot received]")
async def main():
"""Main function to run the sandbox computer use agent."""
# Validate environment
project_id = os.environ.get("GOOGLE_CLOUD_PROJECT")
service_account = os.environ.get("VMAAS_SERVICE_ACCOUNT")
if not project_id:
print("ERROR: GOOGLE_CLOUD_PROJECT environment variable is not set.")
print("Please set it to your GCP project ID.")
return
if not service_account:
print("ERROR: VMAAS_SERVICE_ACCOUNT environment variable is not set.")
print(
"Please set it to your service account email with"
" roles/iam.serviceAccountTokenCreator permission."
)
return
print("=" * 60)
print("Sandbox Computer Use Agent Demo")
print("=" * 60)
print(f"Project: {project_id}")
print(f"Service Account: {service_account}")
print("=" * 60)
app_name = "sandbox_computer_use_demo"
user_id = "demo_user"
# Create runner and session
runner = InMemoryRunner(
agent=agent.root_agent,
app_name=app_name,
)
session = await runner.session_service.create_session(
app_name=app_name, user_id=user_id
)
print(f"\nSession created: {session.id}")
print("\nStarting agent interaction...")
start_time = time.time()
# Example interaction: Navigate and describe
await run_prompt(
runner,
session,
user_id,
"Navigate to https://www.google.com and tell me what you see.",
)
# Example interaction: Search for something
await run_prompt(
runner,
session,
user_id,
"Search for 'Vertex AI Agent Engine' and tell me the first result.",
)
end_time = time.time()
print("\n" + "=" * 60)
print(f"Demo completed in {end_time - start_time:.2f} seconds")
print("=" * 60)
# Print session state to show sandbox info
session = await runner.session_service.get_session(
app_name=app_name, user_id=user_id, session_id=session.id
)
print("\nSession state (sandbox info):")
for key, value in session.state.items():
if key.startswith("_vmaas_"):
# Mask token for security
if "token" in key.lower():
print(f" {key}: [REDACTED]")
else:
print(f" {key}: {value}")
if __name__ == "__main__":
asyncio.run(main())