Skip to content

feat(inference): add agent ID header to inference requests#1687

Merged
toubatbrian merged 1 commit into
mainfrom
ac/sweet-rosalind-d334bd
Jun 2, 2026
Merged

feat(inference): add agent ID header to inference requests#1687
toubatbrian merged 1 commit into
mainfrom
ac/sweet-rosalind-d334bd

Conversation

@adrian-cowham
Copy link
Copy Markdown
Contributor

Summary

Ports livekit/agents#5937 to the JS/TS repo.

Adds the agent's participant SID as a new X-LiveKit-Agent-Id header in buildMetadataHeaders (the JS equivalent of Python's get_inference_headers), alongside the existing X-LiveKit-Room-Id and X-LiveKit-Job-Id headers. 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.ts
    • Emit X-LiveKit-Agent-Id from ctx.agent?.sid when present
    • Update the buildMetadataHeaders JSDoc to mention the agent ID

Porting notes

  • Header casing uses -Id (not Python's -ID) to match this repo's existing X-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?.sid is the JS equivalent of Python's ctx.agent.sid. The JS JobContext.agent getter returns LocalParticipant | undefined, so the optional chain is load-bearing; the if (agentSid) guard mirrors Python's walrus assignment (omits the header when the SID is empty/unset).
  • The PR's second change (a Python ruff formatting fix in recorder_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 --check and eslint — pass (no new issues)
  • Runtime check: buildMetadataHeaders() returns only User-Agent outside a job context and omits the room/job/agent headers without throwing

No 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.

Note: pnpm api:check fails locally, but this is pre-existing and environmental — it reproduces identically on a clean main tree (api-extractor's bundled TS 5.4.2 vs the project's 5.9.3, on export * as in index.d.ts:10). This change is API-surface-neutral.

🤖 Generated with Claude Code

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-bot
Copy link
Copy Markdown

changeset-bot Bot commented Jun 2, 2026

🦋 Changeset detected

Latest commit: 6a4ffb7

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

This PR includes changesets to release 34 packages
Name Type
@livekit/agents Patch
@livekit/agents-plugin-anam 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-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

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: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 1 additional finding.

Open in Devin Review

@toubatbrian toubatbrian merged commit 2eeccad into main Jun 2, 2026
9 checks passed
@toubatbrian toubatbrian deleted the ac/sweet-rosalind-d334bd branch June 2, 2026 19:19
@github-actions github-actions Bot mentioned this pull request Jun 2, 2026
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.

2 participants