-
Notifications
You must be signed in to change notification settings - Fork 114
feat: add support for agent context history #560
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughAdds history/context dataclasses and Flags, integrates them into agent websocket options and clients to parse/emit History events, expands public exports/aliases, introduces comprehensive unit tests and an example, and updates multiple test fixtures and response fixtures. Changes
Sequence Diagram(s)sequenceDiagram
participant Server
participant AgentWSClient
participant Parser
participant App
Server->>AgentWSClient: send text (event: History, payload)
AgentWSClient->>Parser: inspect payload
alt payload has role & content
Parser->>Parser: parse -> HistoryConversationMessage
else payload has function_calls
Parser->>Parser: parse -> HistoryFunctionCallsMessage (contains FunctionCallHistory items)
else
Parser->>Parser: keep raw payload
end
Parser-->>AgentWSClient: parsed history_result
AgentWSClient->>App: emit AgentWebSocketEvents.History(history=history_result, **kwargs)
Estimated code review effort🎯 4 (Complex) | ⏱️ ~40 minutes Possibly related PRs
Suggested reviewers
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 Pylint (3.3.7)deepgram/clients/agent/v1/websocket/options.py✨ 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 (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (2)
tests/unit_test/test_unit_agent_history_context.py (1)
133-198: Consider adding round-trip test for consistencyOther test classes include round-trip serialization tests. Consider adding one for
FunctionCallHistoryto maintain consistency and ensure complete coverage.Add this test method to the
TestFunctionCallHistoryclass:def test_function_call_history_round_trip(self): """Test serialization and deserialization round-trip""" original = FunctionCallHistory( id="fc_roundtrip", name="test_function", client_side=True, arguments='{"test": "value"}', response="Test response" ) serialized = original.to_dict() restored = FunctionCallHistory.from_dict(serialized) assert restored.id == original.id assert restored.name == original.name assert restored.client_side == original.client_side assert restored.arguments == original.arguments assert restored.response == original.responsedeepgram/clients/agent/v1/websocket/options.py (1)
323-324: Address pylint violation for too many instance attributes.The pipeline failure indicates that the
Agentclass now has 8 instance attributes, exceeding pylint's default limit of 7. Since the additionalcontextfield is legitimately needed for the Function Call Context/History feature, consider disabling this specific pylint rule for the class.Add a pylint disable comment above the class definition:
+# pylint: disable=too-many-instance-attributes @dataclass class Agent(BaseResponse):
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (6)
deepgram/clients/agent/__init__.py(2 hunks)deepgram/clients/agent/client.py(4 hunks)deepgram/clients/agent/v1/__init__.py(2 hunks)deepgram/clients/agent/v1/websocket/__init__.py(2 hunks)deepgram/clients/agent/v1/websocket/options.py(4 hunks)tests/unit_test/test_unit_agent_history_context.py(1 hunks)
🧰 Additional context used
🧠 Learnings (6)
📓 Common learnings
Learnt from: dvonthenen
PR: deepgram/deepgram-python-sdk#424
File: deepgram/clients/speak/v1/response.py:48-209
Timestamp: 2024-06-27T00:06:23.128Z
Learning: User dvonthenen prefers to defer certain suggestions, specifically regarding error handling and documentation enhancements in new data classes of `deepgram/clients/speak/v1/response.py`, and may revisit them later.
Learnt from: dvonthenen
PR: deepgram/deepgram-python-sdk#424
File: deepgram/clients/speak/v1/response.py:48-209
Timestamp: 2024-10-09T02:19:48.728Z
Learning: User dvonthenen prefers to defer certain suggestions, specifically regarding error handling and documentation enhancements in new data classes of `deepgram/clients/speak/v1/response.py`, and may revisit them later.
Learnt from: dvonthenen
PR: deepgram/deepgram-python-sdk#426
File: deepgram/clients/listen/v1/__init__.py:36-43
Timestamp: 2024-07-01T19:17:04.194Z
Learning: Unused imports in `deepgram/clients/listen/v1/__init__.py` are retained to maintain backward compatibility and should not be flagged for removal in reviews.
Learnt from: dvonthenen
PR: deepgram/deepgram-python-sdk#426
File: deepgram/clients/listen/v1/__init__.py:36-43
Timestamp: 2024-10-09T02:19:46.086Z
Learning: Unused imports in `deepgram/clients/listen/v1/__init__.py` are retained to maintain backward compatibility and should not be flagged for removal in reviews.
Learnt from: dvonthenen
PR: deepgram/deepgram-python-sdk#426
File: deepgram/clients/listen/__init__.py:37-38
Timestamp: 2024-07-01T19:13:29.909Z
Learning: Unused imports in `deepgram/clients/listen/__init__.py` are retained to maintain backward compatibility.
Learnt from: dvonthenen
PR: deepgram/deepgram-python-sdk#426
File: deepgram/clients/listen/__init__.py:37-38
Timestamp: 2024-10-09T02:19:46.087Z
Learning: Unused imports in `deepgram/clients/listen/__init__.py` are retained to maintain backward compatibility.
Learnt from: dvonthenen
PR: deepgram/deepgram-python-sdk#426
File: deepgram/clients/listen/__init__.py:54-55
Timestamp: 2024-10-09T02:19:46.086Z
Learning: Unused imports in `deepgram/clients/listen/__init__.py` are retained to maintain backward compatibility.
Learnt from: dvonthenen
PR: deepgram/deepgram-python-sdk#426
File: deepgram/clients/listen/__init__.py:54-55
Timestamp: 2024-07-01T19:13:11.612Z
Learning: Unused imports in `deepgram/clients/listen/__init__.py` are retained to maintain backward compatibility.
Learnt from: dvonthenen
PR: deepgram/deepgram-python-sdk#424
File: deepgram/client.py:81-81
Timestamp: 2024-06-27T00:06:01.811Z
Learning: Imports for SpeakStreamClient and AsyncSpeakStreamClient in `deepgram/client.py` are necessary for export purposes and should not be flagged as unused in reviews.
Learnt from: dvonthenen
PR: deepgram/deepgram-python-sdk#424
File: deepgram/client.py:81-81
Timestamp: 2024-10-09T02:19:46.087Z
Learning: Imports for SpeakStreamClient and AsyncSpeakStreamClient in `deepgram/client.py` are necessary for export purposes and should not be flagged as unused in reviews.
deepgram/clients/agent/v1/__init__.py (10)
Learnt from: dvonthenen
PR: #426
File: deepgram/clients/listen/v1/websocket/init.py:8-8
Timestamp: 2024-07-01T19:21:39.778Z
Learning: Unused imports in deepgram/clients/listen/v1/websocket/__init__.py are retained to maintain backward compatibility and should not be flagged for removal in reviews.
Learnt from: dvonthenen
PR: #426
File: deepgram/clients/listen/v1/websocket/init.py:8-8
Timestamp: 2024-10-09T02:19:46.086Z
Learning: Unused imports in deepgram/clients/listen/v1/websocket/__init__.py are retained to maintain backward compatibility and should not be flagged for removal in reviews.
Learnt from: dvonthenen
PR: #426
File: deepgram/clients/listen/v1/init.py:36-43
Timestamp: 2024-07-01T19:17:04.194Z
Learning: Unused imports in deepgram/clients/listen/v1/__init__.py are retained to maintain backward compatibility and should not be flagged for removal in reviews.
Learnt from: dvonthenen
PR: #426
File: deepgram/clients/listen/v1/init.py:36-43
Timestamp: 2024-10-09T02:19:46.086Z
Learning: Unused imports in deepgram/clients/listen/v1/__init__.py are retained to maintain backward compatibility and should not be flagged for removal in reviews.
Learnt from: dvonthenen
PR: #426
File: deepgram/clients/listen/init.py:42-50
Timestamp: 2024-07-01T19:13:28.504Z
Learning: Unused imports in deepgram/clients/listen/__init__.py are retained to maintain backward compatibility and should not be flagged for removal in reviews.
Learnt from: dvonthenen
PR: #426
File: deepgram/clients/listen/init.py:19-24
Timestamp: 2024-10-09T02:19:46.087Z
Learning: Unused imports in deepgram/clients/listen/__init__.py are retained to maintain backward compatibility and should not be flagged for removal in reviews.
Learnt from: dvonthenen
PR: #426
File: deepgram/clients/listen/init.py:42-50
Timestamp: 2024-10-09T02:19:46.086Z
Learning: Unused imports in deepgram/clients/listen/__init__.py are retained to maintain backward compatibility and should not be flagged for removal in reviews.
Learnt from: dvonthenen
PR: #426
File: deepgram/clients/listen/init.py:19-24
Timestamp: 2024-07-01T19:14:20.539Z
Learning: Unused imports in deepgram/clients/listen/__init__.py are retained to maintain backward compatibility and should not be flagged for removal in reviews.
Learnt from: dvonthenen
PR: #426
File: deepgram/clients/listen/init.py:10-13
Timestamp: 2024-10-09T02:19:46.086Z
Learning: Unused imports in deepgram/clients/listen/__init__.py are retained for backward compatibility and should not be flagged for removal in reviews.
Learnt from: dvonthenen
PR: #426
File: deepgram/clients/listen/init.py:10-13
Timestamp: 2024-07-01T19:14:11.334Z
Learning: Unused imports in deepgram/clients/listen/__init__.py are retained for backward compatibility and should not be flagged for removal in reviews.
deepgram/clients/agent/v1/websocket/__init__.py (10)
Learnt from: dvonthenen
PR: #426
File: deepgram/clients/listen/v1/websocket/init.py:8-8
Timestamp: 2024-07-01T19:21:39.778Z
Learning: Unused imports in deepgram/clients/listen/v1/websocket/__init__.py are retained to maintain backward compatibility and should not be flagged for removal in reviews.
Learnt from: dvonthenen
PR: #426
File: deepgram/clients/listen/v1/websocket/init.py:8-8
Timestamp: 2024-10-09T02:19:46.086Z
Learning: Unused imports in deepgram/clients/listen/v1/websocket/__init__.py are retained to maintain backward compatibility and should not be flagged for removal in reviews.
Learnt from: dvonthenen
PR: #431
File: deepgram/clients/listen/v1/websocket/client.py:30-30
Timestamp: 2024-07-11T14:10:17.231Z
Learning: The LiveOptions import in deepgram/clients/listen/v1/websocket/client.py is intentionally present for future use and should not be flagged for removal in reviews.
Learnt from: dvonthenen
PR: #431
File: deepgram/clients/listen/v1/websocket/client.py:30-30
Timestamp: 2024-10-09T02:19:46.087Z
Learning: The LiveOptions import in deepgram/clients/listen/v1/websocket/client.py is intentionally present for future use and should not be flagged for removal in reviews.
Learnt from: dvonthenen
PR: #426
File: deepgram/clients/listen/v1/init.py:36-43
Timestamp: 2024-07-01T19:17:04.194Z
Learning: Unused imports in deepgram/clients/listen/v1/__init__.py are retained to maintain backward compatibility and should not be flagged for removal in reviews.
Learnt from: dvonthenen
PR: #426
File: deepgram/clients/listen/v1/init.py:36-43
Timestamp: 2024-10-09T02:19:46.086Z
Learning: Unused imports in deepgram/clients/listen/v1/__init__.py are retained to maintain backward compatibility and should not be flagged for removal in reviews.
Learnt from: dvonthenen
PR: #426
File: deepgram/clients/listen/init.py:42-50
Timestamp: 2024-07-01T19:13:28.504Z
Learning: Unused imports in deepgram/clients/listen/__init__.py are retained to maintain backward compatibility and should not be flagged for removal in reviews.
Learnt from: dvonthenen
PR: #426
File: deepgram/clients/listen/init.py:42-50
Timestamp: 2024-10-09T02:19:46.086Z
Learning: Unused imports in deepgram/clients/listen/__init__.py are retained to maintain backward compatibility and should not be flagged for removal in reviews.
Learnt from: dvonthenen
PR: #426
File: deepgram/clients/listen/init.py:19-24
Timestamp: 2024-10-09T02:19:46.087Z
Learning: Unused imports in deepgram/clients/listen/__init__.py are retained to maintain backward compatibility and should not be flagged for removal in reviews.
Learnt from: dvonthenen
PR: #426
File: deepgram/clients/listen/init.py:19-24
Timestamp: 2024-07-01T19:14:20.539Z
Learning: Unused imports in deepgram/clients/listen/__init__.py are retained to maintain backward compatibility and should not be flagged for removal in reviews.
deepgram/clients/agent/client.py (10)
Learnt from: dvonthenen
PR: #426
File: deepgram/clients/listen/v1/init.py:36-43
Timestamp: 2024-10-09T02:19:46.086Z
Learning: Unused imports in deepgram/clients/listen/v1/__init__.py are retained to maintain backward compatibility and should not be flagged for removal in reviews.
Learnt from: dvonthenen
PR: #426
File: deepgram/clients/listen/v1/init.py:36-43
Timestamp: 2024-07-01T19:17:04.194Z
Learning: Unused imports in deepgram/clients/listen/v1/__init__.py are retained to maintain backward compatibility and should not be flagged for removal in reviews.
Learnt from: dvonthenen
PR: #426
File: deepgram/clients/speak/init.py:16-19
Timestamp: 2024-10-09T02:19:46.087Z
Learning: Unused imports in deepgram/clients/speak/__init__.py are retained for backward compatibility and should not be flagged for removal in reviews.
Learnt from: dvonthenen
PR: #426
File: deepgram/clients/speak/init.py:16-19
Timestamp: 2024-07-01T19:12:57.715Z
Learning: Unused imports in deepgram/clients/speak/__init__.py are retained for backward compatibility and should not be flagged for removal in reviews.
Learnt from: dvonthenen
PR: #426
File: deepgram/clients/listen/init.py:42-50
Timestamp: 2024-07-01T19:13:28.504Z
Learning: Unused imports in deepgram/clients/listen/__init__.py are retained to maintain backward compatibility and should not be flagged for removal in reviews.
Learnt from: dvonthenen
PR: #426
File: deepgram/clients/listen/init.py:42-50
Timestamp: 2024-10-09T02:19:46.086Z
Learning: Unused imports in deepgram/clients/listen/__init__.py are retained to maintain backward compatibility and should not be flagged for removal in reviews.
Learnt from: dvonthenen
PR: #426
File: deepgram/clients/listen/init.py:19-24
Timestamp: 2024-10-09T02:19:46.087Z
Learning: Unused imports in deepgram/clients/listen/__init__.py are retained to maintain backward compatibility and should not be flagged for removal in reviews.
Learnt from: dvonthenen
PR: #426
File: deepgram/clients/listen/init.py:19-24
Timestamp: 2024-07-01T19:14:20.539Z
Learning: Unused imports in deepgram/clients/listen/__init__.py are retained to maintain backward compatibility and should not be flagged for removal in reviews.
Learnt from: dvonthenen
PR: #426
File: deepgram/clients/listen/init.py:10-13
Timestamp: 2024-10-09T02:19:46.086Z
Learning: Unused imports in deepgram/clients/listen/__init__.py are retained for backward compatibility and should not be flagged for removal in reviews.
Learnt from: dvonthenen
PR: #426
File: deepgram/clients/listen/init.py:10-13
Timestamp: 2024-07-01T19:14:11.334Z
Learning: Unused imports in deepgram/clients/listen/__init__.py are retained for backward compatibility and should not be flagged for removal in reviews.
deepgram/clients/agent/__init__.py (10)
Learnt from: dvonthenen
PR: #426
File: deepgram/clients/speak/init.py:16-19
Timestamp: 2024-10-09T02:19:46.087Z
Learning: Unused imports in deepgram/clients/speak/__init__.py are retained for backward compatibility and should not be flagged for removal in reviews.
Learnt from: dvonthenen
PR: #426
File: deepgram/clients/speak/init.py:16-19
Timestamp: 2024-07-01T19:12:57.715Z
Learning: Unused imports in deepgram/clients/speak/__init__.py are retained for backward compatibility and should not be flagged for removal in reviews.
Learnt from: dvonthenen
PR: #426
File: deepgram/clients/listen/v1/init.py:36-43
Timestamp: 2024-07-01T19:17:04.194Z
Learning: Unused imports in deepgram/clients/listen/v1/__init__.py are retained to maintain backward compatibility and should not be flagged for removal in reviews.
Learnt from: dvonthenen
PR: #426
File: deepgram/clients/listen/v1/init.py:36-43
Timestamp: 2024-10-09T02:19:46.086Z
Learning: Unused imports in deepgram/clients/listen/v1/__init__.py are retained to maintain backward compatibility and should not be flagged for removal in reviews.
Learnt from: dvonthenen
PR: #426
File: deepgram/clients/listen/init.py:42-50
Timestamp: 2024-07-01T19:13:28.504Z
Learning: Unused imports in deepgram/clients/listen/__init__.py are retained to maintain backward compatibility and should not be flagged for removal in reviews.
Learnt from: dvonthenen
PR: #426
File: deepgram/clients/listen/init.py:19-24
Timestamp: 2024-10-09T02:19:46.087Z
Learning: Unused imports in deepgram/clients/listen/__init__.py are retained to maintain backward compatibility and should not be flagged for removal in reviews.
Learnt from: dvonthenen
PR: #426
File: deepgram/clients/listen/init.py:42-50
Timestamp: 2024-10-09T02:19:46.086Z
Learning: Unused imports in deepgram/clients/listen/__init__.py are retained to maintain backward compatibility and should not be flagged for removal in reviews.
Learnt from: dvonthenen
PR: #426
File: deepgram/clients/listen/init.py:19-24
Timestamp: 2024-07-01T19:14:20.539Z
Learning: Unused imports in deepgram/clients/listen/__init__.py are retained to maintain backward compatibility and should not be flagged for removal in reviews.
Learnt from: dvonthenen
PR: #426
File: deepgram/clients/listen/init.py:10-13
Timestamp: 2024-10-09T02:19:46.086Z
Learning: Unused imports in deepgram/clients/listen/__init__.py are retained for backward compatibility and should not be flagged for removal in reviews.
Learnt from: dvonthenen
PR: #426
File: deepgram/clients/listen/init.py:10-13
Timestamp: 2024-07-01T19:14:11.334Z
Learning: Unused imports in deepgram/clients/listen/__init__.py are retained for backward compatibility and should not be flagged for removal in reviews.
deepgram/clients/agent/v1/websocket/options.py (9)
Learnt from: dvonthenen
PR: #431
File: deepgram/clients/listen/v1/websocket/client.py:30-30
Timestamp: 2024-10-09T02:19:46.087Z
Learning: The LiveOptions import in deepgram/clients/listen/v1/websocket/client.py is intentionally present for future use and should not be flagged for removal in reviews.
Learnt from: dvonthenen
PR: #431
File: deepgram/clients/listen/v1/websocket/client.py:30-30
Timestamp: 2024-07-11T14:10:17.231Z
Learning: The LiveOptions import in deepgram/clients/listen/v1/websocket/client.py is intentionally present for future use and should not be flagged for removal in reviews.
Learnt from: dvonthenen
PR: #426
File: deepgram/clients/listen/v1/websocket/init.py:8-8
Timestamp: 2024-10-09T02:19:46.086Z
Learning: Unused imports in deepgram/clients/listen/v1/websocket/__init__.py are retained to maintain backward compatibility and should not be flagged for removal in reviews.
Learnt from: dvonthenen
PR: #426
File: deepgram/clients/listen/v1/websocket/init.py:8-8
Timestamp: 2024-07-01T19:21:39.778Z
Learning: Unused imports in deepgram/clients/listen/v1/websocket/__init__.py are retained to maintain backward compatibility and should not be flagged for removal in reviews.
Learnt from: dvonthenen
PR: #468
File: examples/text-to-speech/websocket/complete/main.py:26-30
Timestamp: 2024-09-27T15:21:34.197Z
Learning: In examples/text-to-speech/websocket/complete/main.py, commented-out options like auto_flush_speak_delta and verbose are intentional in examples and should not be flagged in reviews.
Learnt from: dvonthenen
PR: #431
File: deepgram/clients/listen/v1/websocket/async_client.py:30-30
Timestamp: 2024-07-11T14:10:24.647Z
Learning: The unused import LiveOptions in deepgram/clients/listen/v1/websocket/async_client.py is intentional and will be used in PR #432.
Learnt from: dvonthenen
PR: #431
File: deepgram/clients/listen/v1/websocket/async_client.py:30-30
Timestamp: 2024-10-09T02:19:46.087Z
Learning: The unused import LiveOptions in deepgram/clients/listen/v1/websocket/async_client.py is intentional and will be used in PR #432.
Learnt from: dvonthenen
PR: #426
File: deepgram/clients/listen/v1/rest/options.py:12-12
Timestamp: 2024-07-01T19:12:36.972Z
Learning: Unused imports in deepgram/clients/listen/v1/rest/options.py are retained to maintain backwards compatibility.
Learnt from: dvonthenen
PR: #426
File: deepgram/clients/listen/v1/rest/options.py:12-12
Timestamp: 2024-10-09T02:19:46.087Z
Learning: Unused imports in deepgram/clients/listen/v1/rest/options.py are retained to maintain backwards compatibility.
🧬 Code Graph Analysis (6)
deepgram/clients/agent/v1/__init__.py (1)
deepgram/clients/agent/v1/websocket/options.py (5)
Flags(250-255)Context(301-320)HistoryConversationMessage(259-266)HistoryFunctionCallsMessage(283-297)FunctionCallHistory(270-279)
deepgram/clients/agent/v1/websocket/__init__.py (1)
deepgram/clients/agent/v1/websocket/options.py (5)
Flags(250-255)Context(301-320)HistoryConversationMessage(259-266)HistoryFunctionCallsMessage(283-297)FunctionCallHistory(270-279)
deepgram/clients/agent/client.py (1)
deepgram/clients/agent/v1/websocket/options.py (5)
Flags(250-255)Context(301-320)HistoryConversationMessage(259-266)HistoryFunctionCallsMessage(283-297)FunctionCallHistory(270-279)
tests/unit_test/test_unit_agent_history_context.py (2)
deepgram/client.py (1)
agent(593-597)deepgram/clients/agent/v1/websocket/options.py (7)
SettingsOptions(430-466)Agent(324-384)Flags(250-255)Context(301-320)HistoryConversationMessage(259-266)HistoryFunctionCallsMessage(283-297)FunctionCallHistory(270-279)
deepgram/clients/agent/__init__.py (1)
deepgram/clients/agent/v1/websocket/options.py (5)
Flags(250-255)Context(301-320)HistoryConversationMessage(259-266)HistoryFunctionCallsMessage(283-297)FunctionCallHistory(270-279)
deepgram/clients/agent/v1/websocket/options.py (1)
deepgram/clients/common/v1/shared_response.py (1)
BaseResponse(16-44)
🪛 GitHub Actions: Check - lint
deepgram/clients/agent/v1/websocket/options.py
[error] 331-331: pylint: Too many instance attributes (8/7) (too-many-instance-attributes)
🔇 Additional comments (14)
deepgram/clients/agent/v1/__init__.py (1)
45-45: Import additions follow established patternsThe new imports are properly organized according to the existing structure -
Flagsin the top-level section and context-related classes in the sub-level section.Also applies to: 61-64
deepgram/clients/agent/__init__.py (1)
41-41: Consistent import structure maintainedThe new imports correctly mirror the v1 module structure and maintain consistency across the package hierarchy.
Also applies to: 57-60
deepgram/clients/agent/v1/websocket/__init__.py (1)
36-36: WebSocket module imports properly structuredThe new imports from
.optionsmodule follow the established pattern and correctly expose the new history context classes.Also applies to: 52-55
deepgram/clients/agent/client.py (1)
40-40: Versioning pattern correctly implementedThe new classes follow the SDK's established versioning pattern with
Latestprefixes for imports and clean re-exports for the current version.Also applies to: 56-59, 93-93, 109-112
tests/unit_test/test_unit_agent_history_context.py (1)
1-814: Comprehensive test coverageThe test suite provides excellent coverage of the new history context features including:
- Unit tests for each new class
- Integration tests with existing Agent and SettingsOptions
- Edge cases and error handling
- Serialization/deserialization round-trips
Well-structured and thorough testing approach.
deepgram/clients/agent/v1/websocket/options.py (9)
247-256: LGTM! Clean implementation of configuration flags.The
Flagsclass follows the established SDK patterns with proper inheritance, type hints, and default values. Thehistoryflag defaults toTrue, which is appropriate for enabling the feature by default.
258-267: LGTM! Well-structured conversation message class.The
HistoryConversationMessageclass properly represents text messages in conversation history with appropriate fields (rolefor "user"/"assistant" andcontentfor message text). The default values are sensible.
269-280: LGTM! Comprehensive function call history representation.The
FunctionCallHistoryclass captures all necessary details for function call tracking: id, name, client_side flag, arguments, and response. The field types and defaults are appropriate.
282-298: LGTM! Proper handling of nested object conversion.The class correctly implements the
__post_init__method to convert dictionary entries infunction_callstoFunctionCallHistoryinstances. This follows the established SDK pattern for handling nested data structures during deserialization.
300-321: LGTM! Excellent union type handling and message discrimination.The
Contextclass properly handles the union type for messages by using the presence of the"function_calls"key to discriminate betweenHistoryConversationMessageandHistoryFunctionCallsMessagetypes. The__post_init__method correctly converts dictionary messages to their appropriate typed objects.
356-358: LGTM! Proper integration of context field.The
contextfield is correctly added to theAgentclass with appropriate type hints, default value, and serialization metadata following the established SDK patterns.
382-383: LGTM! Consistent deserialization handling.The
__getitem__method correctly handles conversion of dictionary context data toContextinstances, maintaining consistency with other field conversions in the method.
439-441: LGTM! Proper flags field integration.The
flagsfield is correctly added to theSettingsOptionsclass with appropriate type hints, default value, and serialization metadata following the established SDK patterns.
449-451: LGTM! Consistent flags deserialization.The
__getitem__method correctly handles conversion of dictionary flags data toFlagsinstances, maintaining consistency with other field conversions.
|
Use this preview build URL: https://deepgram-preview-fffa92b2-f434-4c0a-80a0-98427d2dbc55.docs.buildwithfern.com/home the one above is wonky. |
|
I need to double checkout the approach after chatting with @lukeocodes |
|
I validated this approach is correct, but this PR will need a rebase once we merge in #562 which I can do when it's merged, else it's ready for review. |
c8bd52b to
e9d9f68
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🧹 Nitpick comments (4)
deepgram/clients/agent/v1/websocket/options.py (4)
258-267: Tighten typing for discriminators and role to prevent typosConsider using Literal types for the "type" discriminator and the "role" field to catch mistakes at type-check time.
-class HistoryConversationMessage(BaseResponse): +class HistoryConversationMessage(BaseResponse): @@ - type: str = field(default="History") - role: str = field(default="") # "user" or "assistant" + type: Literal["History"] = "History" + role: Literal["user", "assistant"] = "user" # adjust default if needed for BC content: str = field(default="")
269-280: Allow structured arguments/response for function callsIf the API can return JSON objects for arguments/response, widen the types beyond str. This improves fidelity and avoids unnecessary JSON stringify/parse churn.
-class FunctionCallHistory(BaseResponse): +class FunctionCallHistory(BaseResponse): @@ - arguments: str = field(default="") - response: str = field(default="") + arguments: Union[str, Dict[str, Any]] = field(default_factory=str) + response: Union[str, Dict[str, Any]] = field(default_factory=str)
288-290: Use a Literal for message type discriminatorMinor typing improvement to align with a discriminated-union pattern.
- type: str = field(default="History") + type: Literal["History"] = "History"
443-446: SettingsOptions.flags: consider symmetric post_init conversionFor consistency with Agent.context (and UpdateSpeakOptions.speak), convert flags dicts on init too; getitem already handles reads.
@dataclass class SettingsOptions(BaseResponse): @@ - flags: Optional[Flags] = field( - default=None, metadata=dataclass_config(exclude=lambda f: f is None) - ) + flags: Optional[Flags] = field( + default=None, metadata=dataclass_config(exclude=lambda f: f is None) + ) + + def __post_init__(self): + if isinstance(self.flags, dict): + self.flags = Flags.from_dict(self.flags)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (6)
deepgram/clients/agent/__init__.py(2 hunks)deepgram/clients/agent/client.py(4 hunks)deepgram/clients/agent/v1/__init__.py(2 hunks)deepgram/clients/agent/v1/websocket/__init__.py(2 hunks)deepgram/clients/agent/v1/websocket/options.py(5 hunks)tests/unit_test/test_unit_agent_history_context.py(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
- tests/unit_test/test_unit_agent_history_context.py
- deepgram/clients/agent/v1/init.py
- deepgram/clients/agent/init.py
🧰 Additional context used
🧠 Learnings (6)
📚 Learning: 2024-10-09T02:19:46.086Z
Learnt from: dvonthenen
PR: deepgram/deepgram-python-sdk#426
File: deepgram/clients/listen/v1/websocket/__init__.py:8-8
Timestamp: 2024-10-09T02:19:46.086Z
Learning: Unused imports in `deepgram/clients/listen/v1/websocket/__init__.py` are retained to maintain backward compatibility and should not be flagged for removal in reviews.
Applied to files:
deepgram/clients/agent/v1/websocket/__init__.py
📚 Learning: 2024-10-09T02:19:46.087Z
Learnt from: dvonthenen
PR: deepgram/deepgram-python-sdk#431
File: deepgram/clients/listen/v1/websocket/client.py:30-30
Timestamp: 2024-10-09T02:19:46.087Z
Learning: The `LiveOptions` import in `deepgram/clients/listen/v1/websocket/client.py` is intentionally present for future use and should not be flagged for removal in reviews.
Applied to files:
deepgram/clients/agent/v1/websocket/__init__.py
📚 Learning: 2024-07-01T19:17:04.194Z
Learnt from: dvonthenen
PR: deepgram/deepgram-python-sdk#426
File: deepgram/clients/listen/v1/__init__.py:36-43
Timestamp: 2024-07-01T19:17:04.194Z
Learning: Unused imports in `deepgram/clients/listen/v1/__init__.py` are retained to maintain backward compatibility and should not be flagged for removal in reviews.
Applied to files:
deepgram/clients/agent/v1/websocket/__init__.pydeepgram/clients/agent/client.py
📚 Learning: 2024-07-01T19:13:28.504Z
Learnt from: dvonthenen
PR: deepgram/deepgram-python-sdk#426
File: deepgram/clients/listen/__init__.py:42-50
Timestamp: 2024-07-01T19:13:28.504Z
Learning: Unused imports in `deepgram/clients/listen/__init__.py` are retained to maintain backward compatibility and should not be flagged for removal in reviews.
Applied to files:
deepgram/clients/agent/v1/websocket/__init__.pydeepgram/clients/agent/client.py
📚 Learning: 2024-07-01T19:12:57.715Z
Learnt from: dvonthenen
PR: deepgram/deepgram-python-sdk#426
File: deepgram/clients/speak/__init__.py:16-19
Timestamp: 2024-07-01T19:12:57.715Z
Learning: Unused imports in `deepgram/clients/speak/__init__.py` are retained for backward compatibility and should not be flagged for removal in reviews.
Applied to files:
deepgram/clients/agent/client.py
📚 Learning: 2024-10-09T02:19:46.086Z
Learnt from: dvonthenen
PR: deepgram/deepgram-python-sdk#426
File: deepgram/clients/listen/__init__.py:10-13
Timestamp: 2024-10-09T02:19:46.086Z
Learning: Unused imports in `deepgram/clients/listen/__init__.py` are retained for backward compatibility and should not be flagged for removal in reviews.
Applied to files:
deepgram/clients/agent/client.py
🧬 Code Graph Analysis (3)
deepgram/clients/agent/v1/websocket/__init__.py (1)
deepgram/clients/agent/v1/websocket/options.py (5)
Flags(250-255)Context(301-320)HistoryConversationMessage(259-266)HistoryFunctionCallsMessage(283-297)FunctionCallHistory(270-279)
deepgram/clients/agent/client.py (1)
deepgram/clients/agent/v1/websocket/options.py (5)
Flags(250-255)Context(301-320)HistoryConversationMessage(259-266)HistoryFunctionCallsMessage(283-297)FunctionCallHistory(270-279)
deepgram/clients/agent/v1/websocket/options.py (1)
deepgram/clients/common/v1/shared_response.py (1)
BaseResponse(16-44)
🔇 Additional comments (9)
deepgram/clients/agent/v1/websocket/options.py (6)
249-256: Flags model looks goodDefaulting history to True and keeping it optional on SettingsOptions is reasonable. No issues spotted.
350-352: Agent.context addition is consistent and non-breakingOptional Context with exclude-on-None matches existing patterns. Looks good.
355-355: Docstring update improves clarityNoting both Speak and Context conversions here is helpful. No action needed.
365-368: Agent post_init: context dict-to-object conversion LGTMCovers the common case where callers pass a dict. Nice.
380-382: Agent getitem: context conversion mirrors other fieldsConsistent with existing getitem behavior across the module. Good.
453-455: SettingsOptions getitem: flags conversion LGTMDeserialization path covered. No issues.
deepgram/clients/agent/v1/websocket/__init__.py (1)
36-56: Re-export of history/context types is correctImporting Flags, Context, HistoryConversationMessage, HistoryFunctionCallsMessage, and FunctionCallHistory from .options aligns the v1 websocket surface. This maintains expected import paths.
deepgram/clients/agent/client.py (2)
40-60: Added Latest imports for new types — consistent with versioning scheme*Flags, Context, and history message classes are properly wired through v1. Good.
93-113: Public re-exports of new types look goodAliases make the new types available at the stable surface without breaking existing imports.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (7)
deepgram/__init__.py(2 hunks)deepgram/client.py(2 hunks)deepgram/clients/__init__.py(2 hunks)deepgram/clients/agent/enums.py(1 hunks)deepgram/clients/agent/v1/websocket/async_client.py(2 hunks)deepgram/clients/agent/v1/websocket/client.py(2 hunks)examples/agent/context-history/main.py(1 hunks)
🧰 Additional context used
🧠 Learnings (6)
📚 Learning: 2024-07-01T19:12:57.715Z
Learnt from: dvonthenen
PR: deepgram/deepgram-python-sdk#426
File: deepgram/clients/speak/__init__.py:16-19
Timestamp: 2024-07-01T19:12:57.715Z
Learning: Unused imports in `deepgram/clients/speak/__init__.py` are retained for backward compatibility and should not be flagged for removal in reviews.
Applied to files:
deepgram/__init__.pydeepgram/clients/__init__.pydeepgram/client.py
📚 Learning: 2024-07-01T19:17:04.194Z
Learnt from: dvonthenen
PR: deepgram/deepgram-python-sdk#426
File: deepgram/clients/listen/v1/__init__.py:36-43
Timestamp: 2024-07-01T19:17:04.194Z
Learning: Unused imports in `deepgram/clients/listen/v1/__init__.py` are retained to maintain backward compatibility and should not be flagged for removal in reviews.
Applied to files:
deepgram/__init__.pydeepgram/clients/__init__.pydeepgram/client.py
📚 Learning: 2024-07-01T19:13:28.504Z
Learnt from: dvonthenen
PR: deepgram/deepgram-python-sdk#426
File: deepgram/clients/listen/__init__.py:42-50
Timestamp: 2024-07-01T19:13:28.504Z
Learning: Unused imports in `deepgram/clients/listen/__init__.py` are retained to maintain backward compatibility and should not be flagged for removal in reviews.
Applied to files:
deepgram/__init__.pydeepgram/clients/__init__.pydeepgram/client.py
📚 Learning: 2024-10-09T02:19:46.086Z
Learnt from: dvonthenen
PR: deepgram/deepgram-python-sdk#426
File: deepgram/clients/listen/__init__.py:10-13
Timestamp: 2024-10-09T02:19:46.086Z
Learning: Unused imports in `deepgram/clients/listen/__init__.py` are retained for backward compatibility and should not be flagged for removal in reviews.
Applied to files:
deepgram/__init__.pydeepgram/clients/__init__.py
📚 Learning: 2024-10-09T02:19:46.086Z
Learnt from: dvonthenen
PR: deepgram/deepgram-python-sdk#426
File: deepgram/clients/listen/v1/websocket/__init__.py:8-8
Timestamp: 2024-10-09T02:19:46.086Z
Learning: Unused imports in `deepgram/clients/listen/v1/websocket/__init__.py` are retained to maintain backward compatibility and should not be flagged for removal in reviews.
Applied to files:
deepgram/clients/agent/v1/websocket/async_client.py
📚 Learning: 2024-10-09T02:19:46.087Z
Learnt from: dvonthenen
PR: deepgram/deepgram-python-sdk#424
File: deepgram/client.py:81-81
Timestamp: 2024-10-09T02:19:46.087Z
Learning: Imports for SpeakStreamClient and AsyncSpeakStreamClient in `deepgram/client.py` are necessary for export purposes and should not be flagged as unused in reviews.
Applied to files:
deepgram/client.py
🪛 GitHub Actions: Check - static
deepgram/clients/agent/v1/websocket/async_client.py
[error] 489-495: mypy: Name 'history_result' already defined on line 495 [no-redef]. Previous definition at line 489. Command: mypy --config-file mypy.ini --python-version 3.10 --exclude tests --exclude examples .
deepgram/clients/agent/v1/websocket/client.py
[error] 484-490: mypy: Name 'history_result' already defined on line 490 [no-redef]. Previous definition at line 484. Command: mypy --config-file mypy.ini --python-version 3.10 --exclude tests --exclude examples .
🔇 Additional comments (6)
deepgram/clients/agent/enums.py (1)
27-27: Add History event — LGTMThe new AgentWebSocketEvents.History value is correctly added and aligns with downstream handling. No issues.
deepgram/clients/agent/v1/websocket/client.py (1)
32-35: New imports for history types — LGTMHistoryConversationMessage and HistoryFunctionCallsMessage are correctly imported for History parsing.
deepgram/clients/__init__.py (1)
366-386: Top-level re-exports for history/context — LGTMFlags, Context, HistoryConversationMessage, HistoryFunctionCallsMessage, and FunctionCallHistory are correctly exposed for public API usage.
deepgram/client.py (1)
357-377: Public API re-exports for history/context — LGTMFlags and the history/context models are properly re-exported. Consistent with clients/init.py.
deepgram/clients/agent/v1/websocket/async_client.py (1)
32-35: New imports for history types — LGTMRequired types imported for async History processing.
deepgram/__init__.py (1)
343-363: Top-level exports for history/context — LGTMThe added exports surface the new models at the package root, consistent with the SDK’s public API design.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 5
🧹 Nitpick comments (2)
tests/response_data/agent/websocket/agent_tags-e55ef69c-events.json (1)
51-57: AgentStartedSpeaking latency fields present; optional consistency nitLatencies look correct. Optional: include "type": "AgentStartedSpeaking" inside data for consistency with other events that duplicate type in data.
If you prefer uniformity, tweak like:
"data": { + "type": "AgentStartedSpeaking", "total_latency": 0.751554899, "tts_latency": 0.368593096, "ttt_latency": 0.382961593 }Also applies to: 102-108
tests/response_data/agent/websocket/basic_conversation-a40b2785-events.json (1)
51-57: AgentStartedSpeaking latency updates; optional data.type consistencyLatencies are fine. Optional: add data.type for consistency across events (fixtures only).
Example:
"data": { + "type": "AgentStartedSpeaking", "total_latency": 0.834087238, "tts_latency": 0.305673514, "ttt_latency": 0.528413404 }Also applies to: 111-116
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
tests/response_data/speak/rest/1fe0ad339338a9d6cffbab2c7ace41ba5387b5fe7906854795702dce91034fd3-f8c3bf62a9aa3e6fc1619c250e48abe7519373d3edf41be62eb5dc45199af2ef.wavis excluded by!**/*.wav
📒 Files selected for processing (17)
deepgram/clients/agent/v1/websocket/async_client.py(2 hunks)deepgram/clients/agent/v1/websocket/client.py(2 hunks)deepgram/clients/agent/v1/websocket/options.py(5 hunks)tests/response_data/agent/websocket/agent_tags-e55ef69c-events.json(3 hunks)tests/response_data/agent/websocket/basic_conversation-a40b2785-events.json(4 hunks)tests/response_data/agent/websocket/fallback_providers-e16542b1-events.json(3 hunks)tests/response_data/agent/websocket/function_call_conversation-ac8ed698-events.json(3 hunks)tests/response_data/agent/websocket/function_call_conversation-ac8ed698-function_calls.json(3 hunks)tests/response_data/agent/websocket/inject_agent_message-3c5004a4-events.json(2 hunks)tests/response_data/listen/rest/a231370d439312b1a404bb6ad8de955e900ec8eae9a906329af8cc672e6ec7ba-29e7c8100617f70da4ae9da1921cb5071a01219f4780ca70930b0a370ed2163a-response.json(1 hunks)tests/response_data/listen/rest/a231370d439312b1a404bb6ad8de955e900ec8eae9a906329af8cc672e6ec7ba-a17f4880c5b4cf124ac54d06d77c9f0ab7f3fe1052ff1c7b090f7eaf8ede5b76-response.json(1 hunks)tests/response_data/listen/rest/c4e1c0031174878d8f0e3dbd87916ee16d56f1c610ac525af5712ea37226a455-29e7c8100617f70da4ae9da1921cb5071a01219f4780ca70930b0a370ed2163a-response.json(1 hunks)tests/response_data/listen/rest/c4e1c0031174878d8f0e3dbd87916ee16d56f1c610ac525af5712ea37226a455-a17f4880c5b4cf124ac54d06d77c9f0ab7f3fe1052ff1c7b090f7eaf8ede5b76-response.json(1 hunks)tests/response_data/listen/websocket/ed5bfd217988aa8cad492f63f79dc59f5f02fb9b85befe6f6ce404b8f19aaa0d-42fc5ed98cabc1fa1a2f276301c27c46dd15f6f5187cd93d944cc94fa81c8469-response.json(1 hunks)tests/response_data/listen/websocket/ed5bfd217988aa8cad492f63f79dc59f5f02fb9b85befe6f6ce404b8f19aaa0d-d7334c26cf6468c191e05ff5e8151da9b67985c66ab177e9446fd14bbafd70df-response.json(1 hunks)tests/response_data/read/rest/3917a1c81c08e360c0d4bba0ff9ebd645e610e4149483e5f2888a2c5df388b37-23e873efdfd4d680286fda14ff8f10864218311e79efc92ecc82bce3e574c366-response.json(1 hunks)tests/response_data/speak/rest/1fe0ad339338a9d6cffbab2c7ace41ba5387b5fe7906854795702dce91034fd3-f8c3bf62a9aa3e6fc1619c250e48abe7519373d3edf41be62eb5dc45199af2ef-response.json(1 hunks)
✅ Files skipped from review due to trivial changes (5)
- tests/response_data/read/rest/3917a1c81c08e360c0d4bba0ff9ebd645e610e4149483e5f2888a2c5df388b37-23e873efdfd4d680286fda14ff8f10864218311e79efc92ecc82bce3e574c366-response.json
- tests/response_data/agent/websocket/function_call_conversation-ac8ed698-function_calls.json
- tests/response_data/listen/websocket/ed5bfd217988aa8cad492f63f79dc59f5f02fb9b85befe6f6ce404b8f19aaa0d-d7334c26cf6468c191e05ff5e8151da9b67985c66ab177e9446fd14bbafd70df-response.json
- tests/response_data/listen/websocket/ed5bfd217988aa8cad492f63f79dc59f5f02fb9b85befe6f6ce404b8f19aaa0d-42fc5ed98cabc1fa1a2f276301c27c46dd15f6f5187cd93d944cc94fa81c8469-response.json
- tests/response_data/listen/rest/c4e1c0031174878d8f0e3dbd87916ee16d56f1c610ac525af5712ea37226a455-29e7c8100617f70da4ae9da1921cb5071a01219f4780ca70930b0a370ed2163a-response.json
🚧 Files skipped from review as they are similar to previous changes (3)
- deepgram/clients/agent/v1/websocket/client.py
- deepgram/clients/agent/v1/websocket/options.py
- deepgram/clients/agent/v1/websocket/async_client.py
🔇 Additional comments (24)
tests/response_data/speak/rest/1fe0ad339338a9d6cffbab2c7ace41ba5387b5fe7906854795702dce91034fd3-f8c3bf62a9aa3e6fc1619c250e48abe7519373d3edf41be62eb5dc45199af2ef-response.json (1)
1-1: Approve fixture refresh – no stale references foundThe updated speak REST fixture is self-contained and no tests rely on the previous
request_idor exactdatevalue:
- No occurrences of the old UUID or date remain in any test files.
- Hard-coded UUIDs in
test_unit_listen_websocket.py/test_unit_async_listen_websocket.pyare part of independent input strings and unaffected by this change.Optional nit: consider using stable placeholders for
request_idanddatein fixtures (or loosening assertions to check format rather than exact values) to reduce future diff noise.tests/response_data/agent/websocket/fallback_providers-e16542b1-events.json (3)
77-82: LGTM: Event sequencing is consistentAgentAudioDone events follow corresponding AgentStartedSpeaking/ConversationText sequences with increasing timestamps. Looks coherent for playback completion.
Also applies to: 111-116
4-4: No direct test references to fallback_providers-e16542b1-events.json
A repo-wide search didn’t find any tests loading or asserting against this particular fixture. You can safely ignore the previous warning about brittle timestamp/request_id checks for this file.Likely an incorrect or invalid review comment.
34-39: Confirmed EndOfThought as Unhandled in fallback_providers fixtureThe
fallback_providers-e16542b1-events.jsonfixture now emits only Unhandled entries with raw{"type":"EndOfThought"}at lines 34–39 and 69–74, and no tests for this file reference “History”. The daily websocket tests (test_daily_agent_websocket.py) explicitly document that EndOfThought appears as Unhandled, so our client/deserializer logic and test expectations are aligned—no further changes needed.tests/response_data/listen/rest/a231370d439312b1a404bb6ad8de955e900ec8eae9a906329af8cc672e6ec7ba-a17f4880c5b4cf124ac54d06d77c9f0ab7f3fe1052ff1c7b090f7eaf8ede5b76-response.json (2)
1-1: Model metadata update looks consistent.
modelscontains a single UUID that matches the key inmodel_info, and the version/name align with the nova-3 lineage. No schema issues observed.
1-1: Leading newline is intentional and consistent across all fixtures
All scannedresponse.jsonfiles undertests/response_data/listen/restinclude the leading\ninparagraphs.transcript. Since every fixture exhibits this behavior, no change to strip or replace the newline is required.tests/response_data/listen/rest/a231370d439312b1a404bb6ad8de955e900ec8eae9a906329af8cc672e6ec7ba-29e7c8100617f70da4ae9da1921cb5071a01219f4780ca70930b0a370ed2163a-response.json (1)
1-1: LGTM: fixture structure and model_info mapping are consistent.The updated model id/version align with model_info key, and the results structure (alternatives/words/paragraphs/summary) remains valid. Minor confidence deltas are acceptable for fixture refresh.
tests/response_data/listen/rest/c4e1c0031174878d8f0e3dbd87916ee16d56f1c610ac525af5712ea37226a455-a17f4880c5b4cf124ac54d06d77c9f0ab7f3fe1052ff1c7b090f7eaf8ede5b76-response.json (2)
1-1: LGTM: updated model metadata and payload integrity look correct.models and model_info keys match, timestamps/ids refreshed, and transcript content is unchanged aside from expected minor confidence drift.
1-1: Uniform migration confirmed
- No fixtures reference the old model UUID
3b3aabe4-608a-46ac-9585-7960a25daf1aor version2024-12-20.0.- Tests contain no direct assertions on
request_idorcreatedfields; static metadata in fixtures isn’t used in assertions.tests/response_data/agent/websocket/agent_tags-e55ef69c-events.json (3)
4-8: Welcome event: new request_id and rebased timestamp look goodThe added request_id in data and timestamp shifts are fine and match the updated fixture baseline.
60-66: Assistant text updates align with the revised phrasingUpdated assistant content and sequencing read well and match the EndOfThought-delimited flow.
Also applies to: 93-99, 111-117
35-39: Confirm client parsing of EndOfThought markerI searched the entire repo and found no references to “EndOfThought” in the client code (only in test fixtures and tests), so it looks like this event is currently treated purely as an unhandled payload. Please verify that:
- The WebSocket event parser in deepgram/clients correctly accepts
Unhandled.rawcontaining{"type":"EndOfThought"}- No remaining logic is expecting a “History” block at this point
- If special handling is needed for EndOfThought in future, the client code is updated accordingly
tests/response_data/agent/websocket/inject_agent_message-3c5004a4-events.json (4)
4-8: Welcome/Open/SettingsApplied baseline shifts acceptedRebased timestamps and the new Welcome.request_id are fine.
Also applies to: 12-20
52-57: Latency values updated for AgentStartedSpeakingMetrics updated and plausible; no schema concerns.
35-39: Confirm EndOfThought handling in Unhandled.rawI ran:
rg -n "Unhandled" -A4 -B2 deepgram/clients | rg -n "EndOfThought" -A2 -B2and found no matches. Please verify (or implement) that the client code in deepgram/clients correctly detects and handles the
EndOfThoughtmarker in theUnhandled.rawpayload instead of falling back to History blocks.
60-66: No inline assertions to update—JSON fixtures cover the changes
I ran searches across all non-JSON test files and didn’t find any hard-coded checks for the old or new assistant messages. Since tests consume the updated JSON fixtures (which have already been updated), no further test changes are required.tests/response_data/agent/websocket/basic_conversation-a40b2785-events.json (2)
4-8: Header events updated (timestamps/request_id) — looks goodNo issues with the rebased timing and added request_id.
Also applies to: 12-20
102-107: Approve updated assistant text and verify test stringsThe assistant’s closing message has been updated to “2 + 2 is 4!” across the JSON fixtures. I confirmed with ripgrep that all occurrences in tests/response_data/agent/websocket/basic_conversation-a40b2785-events.json now use this exact phrasing. No further changes are needed.
tests/response_data/agent/websocket/function_call_conversation-ac8ed698-events.json (6)
50-50: Function arguments string format: matches expected JSON-string payloadArguments remain a JSON-encoded string, which aligns with prior behavior and typical FunctionCallRequest payloads. LGTM.
Also applies to: 82-82, 97-97
26-26: Confirm duplicated EndOfThought Unhandled events
We’ve verified that there are 2 instances of{ "type":"Unhandled", "data":{ "raw":"{\"type\":\"EndOfThought\"}" } }in
tests/response_data/agent/websocket/function_call_conversation-ac8ed698-events.json. Please confirm whether this duplication is intentional (e.g., to mirror turn boundaries). If not, update the test to remove or consolidate the extra event.Locations to check:
- Line 26
- Line 67
48-48: Cross-fixture FunctionCallRequest IDs Are ConsistentVerified that the three
call_…IDs in
• tests/response_data/agent/websocket/function_call_conversation-ac8ed698-events.json
• tests/response_data/agent/websocket/function_call_conversation-ac8ed698-function_calls.json
match exactly. No discrepancies found—no updates needed.
4-19: Verified monotonic timestamps and singleton events
- tests/response_data/agent/websocket/function_call_conversation-ac8ed698-events.json
• Timestamps are strictly non-decreasing
• Exactly one Welcome, Open, and SettingsApplied event
• Welcome request_id “c808d204-8bea-4d20-8514-9c69710aaaff” is present and consistentAll checks pass—no further changes required.
26-40: Verify parser support for Unhandled raw JSON payloadsPlease confirm that our websocket message parser correctly handles
Unhandledevents whosedata.rawfield contains a serialized JSON string (e.g.{"type":"EndOfThought"}) and deserializes it into an object. I wasn’t able to find any codepaths in the source that explicitly parse or dispatch onUnhandled.raw.• tests/response_data/agent/websocket/function_call_conversation-ac8ed698-events.json (lines 26–40): contains
{ "type": "Unhandled", "timestamp": 1754948246.4373288, "data": { "type": "Unhandled", "raw": "{\"type\":\"EndOfThought\"}" } }– Ensure this string payload is fed through
JSON.parse(or equivalent) and handled by the conversation state machine.• Codebase: no references to
Unhandledparsing were found—please verify or implement support in the websocket handler.
114-118: Latency Assertion Suggestion Not NeededThe
*-events.jsonfiles undertests/response_dataare nightly snapshots produced by the daily websocket tests—they aren’t consumed by any unit tests that assert exact floating values. We confirmed:
- All
AgentStartedSpeakingevents satisfytotal_latency ≈ tts_latency + ttt_latency.- No tests load these fixtures to perform brittle equality checks on latency fields.
You can safely ignore this comment.
Likely an incorrect or invalid review comment.
tests/response_data/agent/websocket/basic_conversation-a40b2785-events.json
Show resolved
Hide resolved
tests/response_data/agent/websocket/fallback_providers-e16542b1-events.json
Show resolved
Hide resolved
tests/response_data/agent/websocket/function_call_conversation-ac8ed698-events.json
Show resolved
Hide resolved
...8cc672e6ec7ba-29e7c8100617f70da4ae9da1921cb5071a01219f4780ca70930b0a370ed2163a-response.json
Show resolved
Hide resolved
...8cc672e6ec7ba-a17f4880c5b4cf124ac54d06d77c9f0ab7f3fe1052ff1c7b090f7eaf8ede5b76-response.json
Show resolved
Hide resolved
Co-authored-by: Naomi <accounts+github@nhcarrigan.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
♻️ Duplicate comments (2)
deepgram/clients/agent/v1/websocket/options.py (2)
291-304: Robust normalization of function_calls in post_init (matches prior feedback)Normalizing None/falsey to [] and converting dicts → FunctionCallHistory is correct and resilient.
314-333: Good normalization of Context.messages in post_init (matches prior feedback)Handling None/[] and mixed dict/object inputs is solid. This should prevent surprises from callers passing messages=None or raw dicts.
🧹 Nitpick comments (4)
deepgram/clients/agent/v1/websocket/options.py (4)
283-304: Return typed FunctionCallHistory in getitem for consistencyMost container models in this file convert nested dicts/lists back to typed objects in getitem (e.g., Think.functions, Audio.input/output). HistoryFunctionCallsMessage currently does not. Add getitem to keep behavior consistent.
class HistoryFunctionCallsMessage(BaseResponse): @@ function_calls: List[FunctionCallHistory] = field(default_factory=list) def __post_init__(self): @@ self.function_calls = [call for call in converted_calls if call is not None] + + def __getitem__(self, key): + _dict = self.to_dict() + if "function_calls" in _dict and isinstance(_dict["function_calls"], list): + _dict["function_calls"] = [ + FunctionCallHistory.from_dict(call) if isinstance(call, dict) else call + for call in _dict["function_calls"] + ] + return _dict[key]
306-333: Return typed messages in Context.getitem for consistencyAccess via context["messages"] currently returns dicts. Mirror the pattern used elsewhere to return typed HistoryConversationMessage/HistoryFunctionCallsMessage instances.
class Context(BaseResponse): @@ def __post_init__(self): @@ self.messages = converted_messages + + def __getitem__(self, key): + _dict = self.to_dict() + if "messages" in _dict and isinstance(_dict["messages"], list): + typed = [] + for message in _dict["messages"]: + if isinstance(message, dict): + if "function_calls" in message: + typed.append(HistoryFunctionCallsMessage.from_dict(message)) + else: + typed.append(HistoryConversationMessage.from_dict(message)) + else: + typed.append(message) + _dict["messages"] = typed + return _dict[key]
264-264: Prefer enum for type="History" to align with other messagesElsewhere (e.g., Settings/UpdateSpeak/UpdatePrompt) the type uses AgentWebSocketEvents. Using the enum here improves consistency and reduces string drift.
- type: str = field(default="History") + type: str = str(AgentWebSocketEvents.History)Apply for both HistoryConversationMessage and HistoryFunctionCallsMessage.
Also applies to: 288-288
259-267: Constrain role values or validate at constructionrole is documented as "user" or "assistant". Consider enforcing this to catch bad inputs early.
Options:
- Type as Literal["user", "assistant"] (requires choosing a sensible default).
- Or add a lightweight post_init that warns on unexpected roles:
def __post_init__(self): if self.role not in ("user", "assistant"): logging.getLogger(__name__).warning( "Unknown role '%s' in HistoryConversationMessage; expected 'user' or 'assistant'", self.role )
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
deepgram/clients/agent/v1/websocket/options.py(5 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
deepgram/clients/agent/v1/websocket/options.py (1)
deepgram/clients/common/v1/shared_response.py (1)
BaseResponse(16-44)
🔇 Additional comments (3)
deepgram/clients/agent/v1/websocket/options.py (3)
362-364: Agent.context integration looks correctOptional field with dict→Context conversion in both post_init and getitem matches existing patterns. No issues.
Also applies to: 377-380, 392-394
455-457: SettingsOptions.flags integration LGTMOptional Flags with dict→Flags conversion in getitem is consistent. Default history=True matches the spec.
Also applies to: 465-467
275-280: arguments/response correctly typed asstrAll fixtures and unit tests treat both
argumentsandresponseas string values (with JSON-encoded payloads when appropriate). No object-shaped usage was found in tests or response data, so the existingstrtyping is accurate and no change is needed.
|
@lukeocodes This now includes a working example of Context History with Agent. |
|
closing as the auto generated v5 SDK now contains this. Context History Features Available:
Key Components Found:From class AgentV1HistoryMessage(UniversalBaseModel):
"""Conversation text as part of the conversation history"""
type: typing.Literal["History"] = "History"
"""Message type identifier for conversation text"""
role: typing.Literal["user", "assistant"]
"""Identifies who spoke the statement"""
content: str
"""The actual statement that was spoken"""From class AgentV1Flags(UniversalBaseModel):
"""Agent flags configuration"""
history: bool = True
"""Enable or disable history message reporting"""From class AgentV1Context(UniversalBaseModel):
"""Conversation context including the history of messages and function calls"""
messages: typing.Optional[typing.List[typing.Union[AgentV1HistoryMessage, AgentV1HistoryFunctionCalls]]] = None
"""Conversation history as a list of messages and function calls"""The new SDK supports:
|
PR Summary: Function Call Context / History Feature
TL;DR
Successfully implemented the Function Call Context / History feature for the Deepgram Python SDK, enabling agents to maintain conversation context and function call history across sessions. The implementation is fully API specification compliant and includes comprehensive testing.
What Changed
New Classes Added:
Flags: Configuration flags withhistoryboolean (defaults totrue)Context: Container for conversation history messagesHistoryConversationMessage: Conversation text messages in history formatHistoryFunctionCallsMessage: Function call messages in history formatFunctionCallHistory: Individual function call records with id, name, arguments, response, and client_side flagEnhanced Existing Classes:
Agent: Added optionalcontextfield for conversation historySettingsOptions: Added optionalflagsfield for feature flagsPylint Config
Key Features:
Testing
Unit Tests (41 new tests):
TestFlags: 6 tests for flags functionalityTestHistoryConversationMessage: 5 tests for conversation messagesTestFunctionCallHistory: 4 tests for function call recordsTestHistoryFunctionCallsMessage: 6 tests for function call messagesTestContext: 6 tests for context containerTestAgentIntegration: 3 tests for agent integrationTestSettingsOptionsIntegration: 5 tests for settings integrationTestErrorHandling: 6 tests for edge casesDemo Application:
Regression Testing:
API Specification Compliance
Flags Structure:
{ "flags": { "history": true } }Agent Context Structure:
{ "agent": { "context": { "messages": [ { "type": "History", "role": "user", "content": "What's the weather?" }, { "type": "History", "function_calls": [ { "id": "fc_12345", "name": "get_weather", "client_side": true, "arguments": "{\"location\": \"NYC\"}", "response": "Sunny, 72°F" } ] } ] } } }Usage Example
Files Modified
Core Implementation:
deepgram/clients/agent/v1/websocket/options.py- Added new classes and enhanced existing onesExport Updates:
deepgram/clients/agent/v1/websocket/__init__.pydeepgram/clients/agent/v1/__init__.pydeepgram/clients/agent/client.pydeepgram/clients/agent/__init__.pyTesting:
tests/unit_test/test_unit_agent_history_context.py- Comprehensive test suiteDemo (temporary):
temp-test/demo_history_context.py- Schema validation demo (cleaned up)Quality Assurance
Code Quality:
Architecture:
dataclasses-jsonpatterns__post_init__discriminationTesting Coverage:
Documentation:
🚀 Ready for Production: The Function Call Context / History feature is fully implemented, tested, and ready for release!
Types of changes
What types of changes does your code introduce to the community Python 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
New Features
Bug Fixes
Tests
Examples
Chores