feat: add support for agent context history#424
Conversation
WalkthroughAdds two history message types and exports; extends AgentLiveSchema with optional Changes
Sequence Diagram(s)sequenceDiagram
participant Client as AgentLiveClient
participant WS as WebSocket
Client->>WS: sendHistoryConversationText(historyMessage)
Client->>WS: sendHistoryFunctionCall(historyMessage)
Client->>WS: sendHistoryMessages([historyMessage...])
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
✨ Finishing Touches🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #424 +/- ##
==========================================
+ Coverage 75.17% 75.34% +0.17%
==========================================
Files 26 26
Lines 1152 1160 +8
Branches 292 292
==========================================
+ Hits 866 874 +8
Misses 286 286 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
I need to double checkout the approach after chatting with @lukeocodes |
ab6a2f3 to
9557a5e
Compare
|
@lukeocodes I double checked the approach and it's good, this is ready for review. |
|
@lukeocodes I moved the imports, back to you. |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (3)
src/lib/enums/AgentEvents.ts (1)
70-75: Doc: Expand History event payload to include function_calls variantCurrent JSDoc only documents the conversation text shape. Update to document both the conversation and function call history payloads for clarity.
/** - * Triggered when history events are received from the agent. - * { type: "History", role: string, content: string } + * Triggered when history events are received from the agent. + * Payload can be one of: + * - { type: "History", role: "user" | "assistant", content: string } + * - { type: "History", function_calls: { id: string; name: string; client_side: boolean; arguments: string; response?: string }[] } + * See: HistoryConversationText and HistoryFunctionCall types. */ History = "History",examples/node-agent-live-history/index.js (2)
8-8: Fix misleading API key log placement"API Key loaded successfully" is logged before the presence check, which can mislead. Move the success log to after the env var validation.
-console.log("🔑 API Key loaded successfully"); +// API key success log moved to after validation @@ if (!process.env.DEEPGRAM_API_KEY) { console.error("❌ Error: DEEPGRAM_API_KEY environment variable is required"); console.log("💡 Run with: DEEPGRAM_API_KEY=your_api_key_here npm start"); process.exit(1); } + console.log("🔑 API Key loaded successfully");Also applies to: 35-41
193-206: Guard: handle only client-side function callsProcess only client-side function requests to avoid executing unintended server-side calls.
// Process each function call in the request for (const func of data.functions) { console.log(`🔄 Processing function: ${func.name} with args: ${func.arguments}`); + if (!func.client_side) { + console.warn(`⏭️ Skipping non client-side function: ${func.name}`); + continue; + }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
examples/node-agent-live-history/index.js(1 hunks)examples/node-agent-live-history/package.json(1 hunks)src/lib/enums/AgentEvents.ts(1 hunks)src/packages/AbstractLiveClient.ts(3 hunks)
✅ Files skipped from review due to trivial changes (1)
- src/packages/AbstractLiveClient.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Test Browser Builds
🔇 Additional comments (1)
examples/node-agent-live-history/index.js (1)
110-113: Verify and align the audio encoding with the BBC stream sourceThe snippet in examples/node-agent-live-history/index.js (around lines 110–113) currently declares:
input: { encoding: "linear16", sample_rate: 16000 }However, the BBC World Service stream is typically served as MP3 (
audio/mpeg), so sending raw PCM may result in errors or garbled audio.Please verify:
- The actual Content-Type returned by your BBC stream endpoint, for example:
curl -sI "<STREAM_URL>" | grep -i Content-Type- Which input encodings the Agent Live service supports (see your Agent Live docs).
Then apply one of the following:
Option A: If MP3 is supported, update to:
audio: { input: { - encoding: "linear16", - sample_rate: 16000 + encoding: "mp3" } },Option B: If you must use PCM (linear16), switch your source to a 16 kHz PCM stream or insert a decode/transcode step before sending.
|
@lukeocodes This now includes a working example of Context History with Agent. |
|
Closing as we'll opt to generate this feature from the API Spec in the next major release of this SDK. |
🎉 PR Summary: Agent Function Call Context / History Feature
TL;DR
Successfully implemented the new Agent Function Call Context / History feature for the Deepgram JS SDK. This feature allows developers to provide conversation context and function call history to agents, enabling more contextual and intelligent conversations. The implementation includes schema updates, new client methods, comprehensive testing, and maintains full backward compatibility.
What Changed
Core Schema Updates
flags.history: Added optional boolean flag toAgentLiveSchemato enable/disable history message reporting (default: true)agent.context.messages: Added optional array property to accept conversation history during agent configurationHistoryConversationTextandHistoryFunctionCallinterfaces matching the API specificationEnhanced Client Functionality
sendHistoryConversationText(message): Send individual conversation history messagessendHistoryFunctionCall(message): Send function call history messagessendHistoryMessages(messages): Send multiple history messages at once (bulk operation)API Specification Compliance
Full adherence to the provided API specification:
type,role,contentpropertiestype,function_callsarray containingid,name,client_side,arguments,responseTesting
Unit Tests (New)
tests/unit/agent-history.test.ts: Comprehensive test suite with 11 test cases covering:Integration Testing
Regression Testing
API Specification Compliance
flags.historypropertyAgentLiveSchemawith boolean type and default documentationagent.context.messagesHistoryConversationText | HistoryFunctionCalltype: "History",role: "user" | "assistant",content: stringtype: "History",function_callsarray with all required propertiesid,name,client_side,arguments,responseall implementedUsage Example
Files Modified
New Files
src/lib/types/HistoryConversationText.ts- Conversation history message typesrc/lib/types/HistoryFunctionCall.ts- Function call history message typetests/unit/agent-history.test.ts- Comprehensive test suiteModified Files
src/lib/types/AgentLiveSchema.ts- Addedflagsandagent.contextpropertiessrc/lib/types/index.ts- Exported new history typessrc/packages/AgentLiveClient.ts- Added three new history methodsQuality Assurance
Code Quality
Testing Coverage
Performance & Compatibility
Types of changes
What types of changes does your code introduce to the community JavaScript SDK?
Put an
xin the boxes that applyChecklist
Put an
xin the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.Further comments
Summary by CodeRabbit