Skip to content

feat(voice): add session-scoped mockTools for testing#1980

Open
toubatbrian wants to merge 2 commits into
mainfrom
brian/session-mock-tools
Open

feat(voice): add session-scoped mockTools for testing#1980
toubatbrian wants to merge 2 commits into
mainfrom
brian/session-mock-tools

Conversation

@toubatbrian

@toubatbrian toubatbrian commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Summary

Follow-up to #1978, porting the half of livekit/agents#6080 that PR skipped: the session-scoped mock_tools API.

  • Add mockTools(AgentType, mocks, session) to voice.testing: assigns the mock set for an Agent type on a specific session, effective immediately and for the session's lifetime (stored in a WeakMap keyed by session, so it never outlives it)
  • Re-registering replaces the Agent type's mock set; passing an empty record removes it
  • getMockTool now also consults session-scoped mocks during tool execution, with context-scoped withMockTools mocks taking precedence — matching the precedence documented in the Python original
  • Changeset included

Note on the Python original

In current Python upstream, _SessionMockTools is written by mock_tools(..., session=session) but never read — generation.py only consults the context-var mocks, so the session form appears to be a no-op there. This port wires up the read side (getMockToolperformToolExecutions), which is the documented intent of the upstream API. Filing this discrepancy upstream separately.

Testing

  • pnpm vitest run agents/src/voice/testing/run_result.test.ts — 11 tests pass, including 5 new ones: session registry resolution, per-session isolation, replace/remove semantics, context-over-session precedence, and end-to-end routing through performToolExecutions
  • pnpm vitest run agents/src/voice/ — no regressions (only the pre-existing amd.test.ts failures, which fail identically on main)
  • pnpm build:agents, Prettier clean

Ported from livekit/agents#6080

Ports the session form of mock_tools from livekit/agents#6080:
mockTools(AgentType, mocks, session) assigns a mock set for an Agent type
on a specific session, effective immediately and for the session's
lifetime. Re-registering replaces the set; an empty record removes it.
Context-scoped withMockTools mocks take precedence when both are active.

Unlike the Python original (where the session store is currently written
but never consulted), getMockTool resolves session mocks during tool
execution.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@toubatbrian toubatbrian requested a review from a team as a code owner July 7, 2026 08:42
@changeset-bot

changeset-bot Bot commented Jul 7, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 9d04644

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 36 packages
Name Type
@livekit/agents Patch
@livekit/agents-plugin-anam Patch
@livekit/agents-plugin-anthropic Patch
@livekit/agents-plugin-assemblyai Patch
@livekit/agents-plugin-baseten Patch
@livekit/agents-plugin-bey Patch
@livekit/agents-plugin-cartesia Patch
@livekit/agents-plugin-cerebras Patch
@livekit/agents-plugin-deepgram Patch
@livekit/agents-plugin-did Patch
@livekit/agents-plugin-elevenlabs Patch
@livekit/agents-plugin-fishaudio Patch
@livekit/agents-plugin-google Patch
@livekit/agents-plugin-hedra Patch
@livekit/agents-plugin-hume Patch
@livekit/agents-plugin-inworld Patch
@livekit/agents-plugin-lemonslice Patch
@livekit/agents-plugin-liveavatar Patch
@livekit/agents-plugin-livekit Patch
@livekit/agents-plugin-minimax Patch
@livekit/agents-plugin-mistral Patch
@livekit/agents-plugin-mistralai Patch
@livekit/agents-plugin-neuphonic Patch
@livekit/agents-plugin-openai Patch
@livekit/agents-plugin-perplexity Patch
@livekit/agents-plugin-phonic Patch
@livekit/agents-plugin-resemble Patch
@livekit/agents-plugin-rime Patch
@livekit/agents-plugin-runway Patch
@livekit/agents-plugin-sarvam Patch
@livekit/agents-plugin-silero Patch
@livekit/agents-plugin-soniox Patch
@livekit/agents-plugin-tavus Patch
@livekit/agents-plugins-test Patch
@livekit/agents-plugin-trugen Patch
@livekit/agents-plugin-xai Patch

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

devin-ai-integration[bot]

This comment was marked as resolved.

A context-scoped mock set for one tool no longer disables session-scoped
mocks for the agent's other tools: a scope whose set lacks the tool falls
through to the next scope instead of unmocking it.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant