Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions contributing/samples/tools/agent_dispatcher/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Agent Dispatcher Sample

Demonstrates [`AgentDispatcherToolset`](../../../../src/google/adk/tools/agent_dispatcher/_agent_dispatcher_toolset.py) for [issue #4759](https://github.com/google/adk-python/issues/4759).

## Capabilities

- **Background dispatch** (default): orchestrator continues while specialists run
- **Parallel multi-dispatch**: multiple `dispatch_agent` calls in one turn
- **`await_agent` / `get_agent_result`**: poll or wait for completion
- **`message_agent`**: follow-ups on the same persistent child session
- **Allowlisted tools + skills** via toolset constructor
- **Shared session service**: child sessions use the parent session service by default

## Run

```bash
adk run contributing/samples/tools/agent_dispatcher
```

Try:

- "Dispatch two researchers in parallel on ADK and Gemini, then await both."
- "Research ADK, then ask the same specialist a follow-up."
15 changes: 15 additions & 0 deletions contributing/samples/tools/agent_dispatcher/__init__.py
Original file line number Diff line number Diff line change
@@ -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
61 changes: 61 additions & 0 deletions contributing/samples/tools/agent_dispatcher/agent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# 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 orchestrator that dispatches runtime agents with follow-ups.

Demonstrates AgentDispatcherToolset for issue #4759: spawn an arbitrary
child agent mid-run, then message it again on the same persistent session.
"""

from __future__ import annotations

from google.adk import Agent
from google.adk.tools.agent_dispatcher import AgentDispatcherToolset


def lookup_fact(topic: str) -> dict[str, str]:
"""Return a tiny canned fact for the dispatched researcher."""
facts = {
'adk': "ADK is Google's Agent Development Kit for building agents.",
'gemini': "Gemini is Google's family of multimodal models.",
}
key = topic.strip().lower()
return {
'topic': topic,
'fact': facts.get(key, f'No canned fact for {topic}.'),
}


dispatcher = AgentDispatcherToolset(
model='gemini-2.5-flash',
tool_allowlist={'lookup_fact': lookup_fact},
)

root_agent = Agent(
name='orchestrator',
model='gemini-2.5-flash',
instruction="""\
You coordinate research by dispatching specialist agents.

When the user asks for research:
1. Call dispatch_agent (background by default) with name, instruction, user_message.
Optionally pass tool_names=["lookup_fact"]. Use wait=true only if you must block.
2. You may dispatch multiple specialists in parallel, then call await_agent per id.
3. For follow-ups, call message_agent with the same dispatch_id.
4. Use get_agent_result to poll status without waiting.

Keep the user updated with a concise final answer.
""",
tools=[dispatcher],
)
4 changes: 4 additions & 0 deletions src/google/adk/tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@
_LAZY_MAPPING = {
'AuthToolArguments': ('..auth.auth_tool', 'AuthToolArguments'),
'AgentTool': ('.agent_tool', 'AgentTool'),
'AgentDispatcherToolset': (
'.agent_dispatcher._agent_dispatcher_toolset',
'AgentDispatcherToolset',
),
'APIHubToolset': ('.apihub_tool.apihub_toolset', 'APIHubToolset'),
'BaseTool': ('.base_tool', 'BaseTool'),
'DiscoveryEngineSearchTool': (
Expand Down
19 changes: 19 additions & 0 deletions src/google/adk/tools/agent_dispatcher/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# 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.

"""Runtime agent dispatch tools for orchestrators."""

from ._agent_dispatcher_toolset import AgentDispatcherToolset

__all__ = ['AgentDispatcherToolset']
Loading