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
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:
@@ -0,0 +1,27 @@
|
||||
# Live Non-Blocking Tool Agent Sample
|
||||
|
||||
## Overview
|
||||
|
||||
This sample provides a minimal agent to demonstrate non-blocking tool execution in ADK Live mode (`adk web` / `run_live`).
|
||||
|
||||
When a tool declaration is configured with `response_scheduling` set to `WHEN_IDLE`, `SILENT`, or `INTERRUPT`, it indicates to the model that response handling can occur asynchronously.
|
||||
|
||||
## Sample Inputs
|
||||
|
||||
- `Please start a slow background task for data processing, and then let's keep talking.`
|
||||
|
||||
*Triggers `slow_background_task` which sleeps for 10 seconds. While it runs, continue speaking to the agent.*
|
||||
|
||||
## Reproduction Instructions
|
||||
|
||||
1. Run the sample via `adk web`:
|
||||
```bash
|
||||
uv run adk web contributing/samples/live/live_non_blocking_tool_agent
|
||||
```
|
||||
1. Open the ADK web interface and start a Live Session with the agent.
|
||||
1. Trigger the tool by saying: *"Please start a slow background task and keep talking with me."*
|
||||
1. Continue speaking to the agent while the background task runs in console (`[Tool] Starting slow background task...`).
|
||||
|
||||
### Expected Behavior
|
||||
|
||||
The model should continue conversing and generating audio/transcription responses immediately while the tool executes in the background. The tool result is delivered later per the `response_scheduling` mode.
|
||||
@@ -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,72 @@
|
||||
# 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.
|
||||
|
||||
import asyncio
|
||||
from typing import Any
|
||||
from typing import Dict
|
||||
|
||||
from google.adk.agents.llm_agent import Agent
|
||||
from google.adk.tools.function_tool import FunctionTool
|
||||
from google.genai import types
|
||||
|
||||
|
||||
async def slow_background_task(task_description: str) -> Dict[str, Any]:
|
||||
"""Performs a long-running background computation or data retrieval.
|
||||
|
||||
Args:
|
||||
task_description: Description of the task to run in the background.
|
||||
|
||||
Returns:
|
||||
A dictionary containing the completion status and task result.
|
||||
"""
|
||||
print(f"[Tool] Starting slow background task: {task_description}")
|
||||
# Simulate a 10-second non-blocking background operation
|
||||
await asyncio.sleep(10)
|
||||
print(f"[Tool] Completed slow background task: {task_description}")
|
||||
return {
|
||||
"status": "completed",
|
||||
"task": task_description,
|
||||
"result": "Background task finished successfully after 10 seconds.",
|
||||
}
|
||||
|
||||
|
||||
# Create a FunctionTool wrapping the long-running async function
|
||||
non_blocking_tool = FunctionTool(slow_background_task)
|
||||
|
||||
# Configure response_scheduling to indicate non-blocking behavior for Live mode.
|
||||
# Options: WHEN_IDLE, SILENT, or INTERRUPT.
|
||||
non_blocking_tool.response_scheduling = (
|
||||
types.FunctionResponseScheduling.WHEN_IDLE
|
||||
)
|
||||
|
||||
|
||||
root_agent = Agent(
|
||||
model="gemini-live-2.5-flash-native-audio",
|
||||
name="non_blocking_tool_agent",
|
||||
description=(
|
||||
"Agent demonstrating non-blocking tool execution in ADK Live mode."
|
||||
),
|
||||
instruction="""
|
||||
You are a helpful assistant for testing live mode non-blocking tool execution.
|
||||
|
||||
You have access to a tool `slow_background_task` which is configured with
|
||||
NON_BLOCKING response scheduling (WHEN_IDLE).
|
||||
|
||||
When the user asks you to run a long-running or background task, call the `slow_background_task` tool.
|
||||
Inform the user that the task has started and continue conversing with them normally while the task runs in the background.
|
||||
""",
|
||||
tools=[
|
||||
non_blocking_tool,
|
||||
],
|
||||
)
|
||||
Reference in New Issue
Block a user