Skip to content

fix: add required parameter to getJobContext, matching Python SDK#1253

Merged
u9g merged 2 commits intomainfrom
jl/silence-jobcontext-warning
Apr 14, 2026
Merged

fix: add required parameter to getJobContext, matching Python SDK#1253
u9g merged 2 commits intomainfrom
jl/silence-jobcontext-warning

Conversation

@u9g
Copy link
Copy Markdown
Contributor

@u9g u9g commented Apr 14, 2026

Description

Adds an optional required parameter to getJobContext(), matching the Python SDK's get_job_context(required=False) pattern. When false, returns undefined instead of throwing. This eliminates the noisy warn-level "JobContext is not available" log that fired on every AgentSession.start() call during evals/tests.

Changes Made

  • Added overloaded signatures to getJobContext() with a required parameter (true by default for backwards compatibility)
  • Replaced try/catch blocks in AgentSession with getJobContext(false) + conditional
  • Applied the same pattern in inference/utils.ts (buildMetadataHeaders)
  • Removed unused JobContext type import from agent_session.ts

Pre-Review Checklist

  • Build passes: All builds (lint, typecheck, tests) pass locally
  • AI-generated code reviewed: Removed unnecessary comments and ensured code quality
  • Changes explained: All changes are properly documented and justified above
  • Scope appropriate: All changes relate to the PR title

Testing

  • Ran agent test suite and confirmed the JobContext is not available warnings no longer appear
  • All tests pass
  • Build succeeds

Additional Notes

The Python SDK uses get_job_context(required=False) which returns None instead of throwing:
https://github.com/livekit/agents/blob/4930264e21a58c36e0802c39120480352bb27e09/livekit-agents/livekit/agents/voice/agent_session.py#L624


Note to reviewers: Please ensure the pre-review checklist is completed before starting your review.

Add an optional `required` parameter to `getJobContext()`. When false,
returns undefined instead of throwing — matching the Python SDK's
`get_job_context(required=False)` pattern.

Replace try/catch blocks in AgentSession and inference utils with
`getJobContext(false)`, removing the noisy warn-level log that fired
on every eval run.
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 14, 2026

🦋 Changeset detected

Latest commit: d4c7779

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

This PR includes changesets to release 24 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-deepgram Patch
@livekit/agents-plugin-elevenlabs Patch
@livekit/agents-plugin-google Patch
@livekit/agents-plugin-hedra Patch
@livekit/agents-plugin-inworld Patch
@livekit/agents-plugin-lemonslice Patch
@livekit/agents-plugin-livekit Patch
@livekit/agents-plugin-mistral Patch
@livekit/agents-plugin-neuphonic Patch
@livekit/agents-plugin-openai Patch
@livekit/agents-plugin-phonic Patch
@livekit/agents-plugin-resemble Patch
@livekit/agents-plugin-rime Patch
@livekit/agents-plugin-sarvam Patch
@livekit/agents-plugin-silero 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 found 1 potential issue.

View 3 additional findings in Devin Review.

Open in Devin Review

Comment thread agents/src/job.ts
Comment on lines +33 to +35
export function getJobContext(required?: true): JobContext;
export function getJobContext(required: false): JobContext | undefined;
export function getJobContext(required = true): JobContext | undefined {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Missing // Ref: comments for Python-ported getJobContext(required) pattern

The changeset explicitly states this feature is "matching Python SDK's get_job_context(required=False) pattern." Per CLAUDE.md's porting rules (CLAUDE.md:147-169), every JS change that corresponds to a Python change must carry an inline // Ref: python <relative-file-path> - <line-range> lines comment directly above the relevant lines. The new overloaded getJobContext function definition at agents/src/job.ts:33-40 and its call sites at agents/src/inference/utils.ts:60, agents/src/voice/agent_session.ts:449, and agents/src/voice/agent_session.ts:522 are all missing these required reference comments.

Prompt for agents
The CLAUDE.md porting rules require a // Ref: python comment above every JS change that corresponds to a Python change. The changeset for this PR explicitly references matching Python SDK's get_job_context(required=False) pattern, which triggers this rule.

Add // Ref: python comments with the relevant Python file path and line range above:
1. The getJobContext overload definitions in agents/src/job.ts (lines 33-35)
2. The getJobContext(false) call in agents/src/inference/utils.ts (line 60)
3. The getJobContext(false) calls in agents/src/voice/agent_session.ts (lines 449 and 522)

The Python reference would be something like:
// Ref: python livekit-agents/livekit/agents/job.py - <line-range> lines
where the line range corresponds to the get_job_context function in the Python SDK.
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

@u9g u9g merged commit b678ee9 into main Apr 14, 2026
9 checks passed
@u9g u9g deleted the jl/silence-jobcontext-warning branch April 14, 2026 18:56
@github-actions github-actions Bot mentioned this pull request Apr 14, 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