fix: add required parameter to getJobContext, matching Python SDK#1253
fix: add required parameter to getJobContext, matching Python SDK#1253
Conversation
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 detectedLatest commit: d4c7779 The changes in this PR will be included in the next version bump. This PR includes changesets to release 24 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 |
| export function getJobContext(required?: true): JobContext; | ||
| export function getJobContext(required: false): JobContext | undefined; | ||
| export function getJobContext(required = true): JobContext | undefined { |
There was a problem hiding this comment.
🟡 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.
Was this helpful? React with 👍 or 👎 to provide feedback.
Description
Adds an optional
requiredparameter togetJobContext(), matching the Python SDK'sget_job_context(required=False)pattern. Whenfalse, returnsundefinedinstead of throwing. This eliminates the noisy warn-level"JobContext is not available"log that fired on everyAgentSession.start()call during evals/tests.Changes Made
getJobContext()with arequiredparameter (trueby default for backwards compatibility)AgentSessionwithgetJobContext(false)+ conditionalinference/utils.ts(buildMetadataHeaders)JobContexttype import fromagent_session.tsPre-Review Checklist
Testing
JobContext is not availablewarnings no longer appearAdditional Notes
The Python SDK uses
get_job_context(required=False)which returnsNoneinstead 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.