google / google/adk-python

BaseToolset caches prefixed tools by a single invocation ID, breaking multi-agent concurrency

Offen
#5,721 1 Kommentar 0 Reaktionen 2 zugewiesene Personen Beansprucht von @rohityan Auf GitHub ansehen
needs review tools
Vorherrschende Sprache
Python
Sterne
21.5k
Forks
4k
Ø Merge
1 T. 14 Std.
Gemergte PRs (30 T.)
37

Beschreibung

### Description
In `google.adk.tools.base_toolset.BaseToolset`, prefixed tool wrappers are cached using a single instance variable `self._cached_invocation_id`.

When orchestrating multiple agents concurrently (e.g., via `ParallelAgent` or custom `asyncio.TaskGroup` harnesses), concurrent worker coroutines call `get_tools(invocation_id="worker_N")`. Because `self._cached_invocation_id` only stores the last caller's ID, concurrent workers constantly overwrite each other's cached ID. This results in a cache miss on every single turn, forcing redundant tool wrapper re-instantiations and causing severe lock contention.

### Proposed Solution
Refactor `self._cached_prefixed_tools` to be a dictionary keyed by `invocation_id`:
```python
self._cached_prefixed_tools: dict[Optional[str], list[BaseTool]] = {}
```
When `get_tools` is called, check `if invocation_id in self._cached_prefixed_tools` and return the cached list for that specific agent thread. Ensure `close()` clears the dictionary (`self._cached_prefixed_tools.clear()`).

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.