feat(inference): add agent ID header to inference requests#1687
Merged
Conversation
Include the agent participant SID as X-LiveKit-Agent-Id in buildMetadataHeaders, alongside the existing room and job ID headers, when running inside a job context. This lets the inference gateway attribute requests to the specific running agent instance, not just the room and job. Ported from livekit/agents#5937. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: 6a4ffb7 The changes in this PR will be included in the next version bump. This PR includes changesets to release 34 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 |
toubatbrian
approved these changes
Jun 2, 2026
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
Ports livekit/agents#5937 to the JS/TS repo.
Adds the agent's participant SID as a new
X-LiveKit-Agent-Idheader inbuildMetadataHeaders(the JS equivalent of Python'sget_inference_headers), alongside the existingX-LiveKit-Room-IdandX-LiveKit-Job-Idheaders. The header is only emitted when running inside a job context and when the SID is set, so console mode and tests are unaffected.This lets the inference gateway attribute requests to the specific running agent instance, not just the room and job. Because the headers are built in
buildMetadataHeaders, the agent ID automatically flows to every call site the room/job headers already reach —connectWs,inference/llm.ts, and the interruption HTTP/WS transports.Changes
agents/src/inference/utils.tsX-LiveKit-Agent-Idfromctx.agent?.sidwhen presentbuildMetadataHeadersJSDoc to mention the agent IDPorting notes
-Id(not Python's-ID) to match this repo's existingX-LiveKit-Room-Id/X-LiveKit-Job-Id. HTTP header names are case-insensitive, and the existing headers already work against the same gateway.ctx.agent?.sidis the JS equivalent of Python'sctx.agent.sid. The JSJobContext.agentgetter returnsLocalParticipant | undefined, so the optional chain is load-bearing; theif (agentSid)guard mirrors Python's walrus assignment (omits the header when the SID is empty/unset).ruffformatting fix inrecorder_io.py) is Python-tooling-specific and has no JS counterpart, so it was not ported.Testing
pnpm build:agents— succeeds (type-check + bundle)prettier --checkandeslint— pass (no new issues)buildMetadataHeaders()returns onlyUser-Agentoutside a job context and omits the room/job/agent headers without throwingNo unit test was added: the upstream PR ships none, and there is no job-context mock harness in the inference test files. A changeset (
@livekit/agents: patch) is included.🤖 Generated with Claude Code