Add base Toolset support #1485
Open
toubatbrian wants to merge 9 commits into
Open
Conversation
🦋 Changeset detectedLatest commit: c5d0149 The changes in this PR will be included in the next version bump. This PR includes changesets to release 31 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
…s-js into brian/base-toolset
Drop the dedicated `toolsets` slot from Agent/AgentActivity in favor of
spreading `someToolset.toolCtx` into the agent's regular `tools` map.
Each tool gets stamped in the Toolset constructor with a back-reference
to its owning Toolset via `Symbol.for("livekit.agents.Toolset")`.
AgentActivity discovers the live Toolsets to set up / close by walking
the ToolContext through the new `collectToolsets()` helper, with
`getToolsetReference()` exposed for per-tool access.
This brings the API closer to Python parity (no JS-only `toolsets`
parameter on Agent) and lets users compose tools and toolsets via the
same `tools` map without thinking about lifecycle hooks.
|
|
The Toolset constructor no longer mutates the tool objects it was given.
Instead, the toolCtx getter returns shallow clones with the back-reference
attached, so the same tool used directly via `new Agent({ tools: { tool } })`
stays unowned while `new Agent({ tools: { ...toolset.toolCtx } })` carries
the owning Toolset for lifecycle discovery.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds base
Toolsetsupport to the JS agents package. Users compose tools and toolsets through a singletoolsmap; toolset lifecycle is discovered implicitly from a symbol back-reference attached to each tool when accessed viaToolset.toolCtx.This includes:
llm.Toolsetwithid, atoolCtxgetter, and default no-opsetup()/aclose()hooks for subclasses to override.getOwningToolset(tool)andcollectToolsets(toolCtx)helpers for finding the Toolsets backing aToolContext.ToolCalledEventandToolCompletedEventpayload types.AgentActivitylifecycle setup/cleanup for agent-scoped toolsets — discovered by walkingagent.toolCtxand deduping by reference.examples/src/basic_toolsets.tsdemonstrating Toolset usage.How it works
Toolset.toolCtxreturns shallow clones of its tools with the owningToolsetattached viaSymbol.for("livekit.agents.Toolset"). Stamping is lazy and clone-based, so the original tool objects are never mutated: a tool used directly stays unowned, while the same tool spread fromsomeToolset.toolCtxcarries the back-reference for lifecycle discovery.AgentActivitycallscollectToolsets(agent.toolCtx)on init / resume to set up the active Toolsets, on close to tear them down, and diffs the discovered sets onupdateTools(tools)to setup added / close removed.Usage
Updating tools later follows the same pattern:
Test Plan
pnpm test agents/src/llm/tool_context.test.ts agents/src/voice/agent.test.ts agents/src/voice/agent_activity.test.tspnpm --filter @livekit/agents build:typespnpm --filter livekit-agents-examples build