Skip to content

fix: allow multiple AsyncToolsets by deduplicating management tools#5369

Merged
longcw merged 6 commits intomainfrom
longc/async-toolset-dedup
Apr 14, 2026
Merged

fix: allow multiple AsyncToolsets by deduplicating management tools#5369
longcw merged 6 commits intomainfrom
longc/async-toolset-dedup

Conversation

@longcw
Copy link
Copy Markdown
Contributor

@longcw longcw commented Apr 7, 2026

Summary

  • Move get_running_tasks and cancel_task from AsyncToolset instance methods to module-level singleton @function_tools, fixing duplicate tool name errors when multiple AsyncToolsets are used on the same agent
  • Registry is scoped by AgentSession (dict[AgentSession, set[AsyncToolset]]) so sessions in thread mode can't see each other's tasks
  • Toolsets lazily register on first tool call via RunContext.session, unregister in aclose()
  • ToolContext.update_tools now deduplicates same-instance tools (is check) instead of raising ValueError

Move get_running_tasks and cancel_task from instance methods to module-level
singleton function tools with a module-level registry. This allows multiple
AsyncToolsets to coexist on the same agent without duplicate tool name errors.

ToolContext now skips duplicate tools that are the same instance (is check)
rather than raising ValueError.
@chenghao-mou chenghao-mou requested a review from a team April 7, 2026 15:48
devin-ai-integration[bot]

This comment was marked as resolved.

longcw added 2 commits April 8, 2026 09:48
Use dict[AgentSession, set[AsyncToolset]] registry with lazy registration
on first tool call and cleanup in aclose(). Management tools filter by
ctx.session so sessions in thread mode can't see each other's tasks.
devin-ai-integration[bot]

This comment was marked as resolved.

longcw added 2 commits April 8, 2026 10:48
Replace session-scoped toolset registry with a flat task registry keyed
by (JobContext | None, call_id). Tasks auto-register in _wrap_tool and
auto-remove via done callback. No setup/aclose overrides needed.

Add get_job_context(required=False) overload that returns None instead
of raising, and use it to simplify agent_session.py as well.
Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 new potential issue.

View 4 additional findings in Devin Review.

Open in Devin Review

Comment thread livekit-agents/livekit/agents/llm/async_toolset.py
@longcw longcw merged commit 9bb5804 into main Apr 14, 2026
22 of 23 checks passed
@longcw longcw deleted the longc/async-toolset-dedup branch April 14, 2026 02:09
jayeshp19 pushed a commit to jayeshp19/agents that referenced this pull request Apr 14, 2026
* fix: allow multiple AsyncToolsets by deduplicating management tools (livekit#5369)

* feat(beta/workflows): add InstructionParts for modular instruction customization (livekit#5077)

* add ToolSearchToolset and ToolProxyToolset for dynamic tool discovery (livekit#5140)

* Feature - Configurable session close transcript timeout (livekit#5328)

* Fix FrameProcessor lifecycle for selector based noise cancellation (livekit#5433)

---------

Co-authored-by: Long Chen <longch1024@gmail.com>
Co-authored-by: Benjamin Lowe <ben.lowe.uk@googlemail.com>
Co-authored-by: Topherhindman <topher.hindman@livekit.io>
osimhi213 added a commit to de-id/livekit-agents that referenced this pull request Apr 15, 2026
* upstream/main: (31 commits)
  chore: reduce renovate noise (livekit#5421)
  Rename e2ee to encryption in JobContext.connect (livekit#5454)
  feat: add Runway Characters avatar plugin (livekit#5355)
  Fix FrameProcessor lifecycle for selector based noise cancellation (livekit#5433)
  Feature - Configurable session close transcript timeout (livekit#5328)
  add ToolSearchToolset and ToolProxyToolset for dynamic tool discovery (livekit#5140)
  feat(beta/workflows): add InstructionParts for modular instruction customization (livekit#5077)
  fix: allow multiple AsyncToolsets by deduplicating management tools (livekit#5369)
  fix: empty transcript blocks commit_user_turn until timeout (livekit#5429)
  Feature/krisp viva sdk support (livekit#4370)
  feat: add service_tier parameter to Responses API LLM (livekit#5346)
  fix(inworld): do not leak connections when when cancelled (livekit#5427)
  update: Sarvam STT - add verbose error loggin and remove retry connection (livekit#5373)
  chore(deps): update github workflows (major) (livekit#5424)
  (azure openai): ensure gpt-realtime-1.5 compatibility (livekit#5407)
  chore(deps): update dependency nltk to v3.9.4 [security] (livekit#5418)
  chore(deps): update dependency aiohttp to v3.13.4 [security] (livekit#5416)
  chore(deps): update dependency langchain-core to v1.2.28 [security] (livekit#5417)
  chore: pin GHA by commit (livekit#5415)
  fix(aws): unwrap doubly-encoded JSON tool arguments from Nova Sonic (livekit#5411)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants