Skip to content

Conversation

@jpvajda
Copy link
Contributor

@jpvajda jpvajda commented Jul 18, 2025

PR Summary: Add mip_opt_out Agent Setting

TL;DR

Added a new boolean agent setting mip_opt_out to allow users to opt out of the Deepgram Model Improvement Program. The field defaults to false (opted in) and is properly serialized in the agent configuration JSON.

What Changed

🆕 New Feature: mip_opt_out Agent Setting

  • Type: Optional[bool]
  • Default: false (users are opted in by default)
  • Purpose: Allows users to opt out of Deepgram's Model Improvement Program
  • API Spec Compliance: Matches the provided API specification exactly

📁 Files Modified

  1. deepgram/clients/agent/v1/websocket/options.py

    • Added mip_opt_out field to the Agent dataclass
    • Configured proper serialization with dataclass_config
  2. tests/unit_test/test_unit_agent_mip_opt_out.py (new file)

    • 12 comprehensive unit tests covering all scenarios
    • Tests default values, serialization, deserialization, and round-trip conversion
    • Validates integration with other agent settings

Usage Examples

# Basic usage - opt out of MIP
options = SettingsOptions()
options.agent.mip_opt_out = True

# In a complete agent configuration
options.agent.language = "en"
options.agent.mip_opt_out = True
options.agent.greeting = "Hello! I've opted out of MIP."
options.agent.listen.provider.type = "deepgram"
options.agent.think.provider.type = "open_ai"
options.agent.speak.provider.type = "deepgram"

JSON Output:

{
  "type": "Settings",
  "agent": {
    "language": "en",
    "mip_opt_out": true,
    "greeting": "Hello! I've opted out of MIP.",
    ...
  }
}

Testing

Schema Validation: Created and ran comprehensive demo app to validate schema acceptance
Unit Tests: 12 new unit tests covering all edge cases (100% pass rate)
Integration Tests: All existing tests continue to pass (105/105 ✅)
Backward Compatibility: Default behavior unchanged - users remain opted in

Implementation Details

Why This Approach?

  • Industry Best Practice: Follows existing SDK patterns for optional boolean fields
  • Backward Compatible: Default false maintains current user experience
  • Type Safe: Proper typing with Optional[bool] and dataclass configuration
  • Serialization Compliant: Uses standard dataclass patterns for JSON serialization

Schema Validation

The implementation was validated against the expected JSON schema:

{
  "mip_opt_out": {
    "type": "boolean",
    "default": false,
    "description": "To opt out of Deepgram Model Improvement Program"
  }
}

Types of changes

What types of changes does your code introduce to the community Python SDK?
Put an x in the boxes that apply

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update or tests (if none of the other choices apply)

Checklist

Put an x in 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.

  • I have read the CONTRIBUTING doc
  • I have lint'ed all of my code using repo standards
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)

Summary by CodeRabbit

  • New Features

    • Introduced a new optional setting for agents to control a specific opt-out preference.
  • Tests

    • Added comprehensive unit tests to verify default values, setting, serialization, deserialization, and type handling for the new agent opt-out setting.
  • Chores

    • Updated several test response files to reflect new metadata such as request IDs and timestamps, with no changes to core content.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 18, 2025

Walkthrough

A new optional boolean field mip_opt_out was added to the Agent dataclass with a default value of False and custom serialization behavior. Comprehensive unit tests were introduced to verify the correct handling, serialization, and deserialization of this field. Several JSON test fixtures were updated, mostly changing metadata such as request IDs and timestamps, with one fixture altering the recognized transcript text.

Changes

File(s) Change Summary
deepgram/clients/agent/v1/websocket/options.py Added optional boolean field mip_opt_out to Agent dataclass with default False and custom serialization.
tests/unit_test/test_unit_agent_mip_opt_out.py Added comprehensive unit tests for the mip_opt_out field in Agent and related serialization logic.
tests/response_data/listen/rest/a231370d439312b1a404bb6ad8de955e900ec8eae9a906329af8cc672e6ec7ba-*.json Updated JSON fixtures: changed only metadata fields (request_id, created); transcript and details unchanged.
tests/response_data/listen/rest/c4e1c0031174878d8f0e3dbd87916ee16d56f1c610ac525af5712ea37226a455-*.json Updated JSON fixtures: changed metadata and minor floating-point confidence values; transcript unchanged.
tests/response_data/listen/websocket/ed5bfd217988aa8cad492f63f79dc59f5f02fb9b85befe6f6ce404b8f19aaa0d-42fc... Updated JSON fixture: replaced transcript and word-level data, updated request ID; other metadata unchanged.
tests/response_data/listen/websocket/ed5bfd217988aa8cad492f63f79dc59f5f02fb9b85befe6f6ce404b8f19aaa0d-d733... Updated JSON fixture: changed only the request_id in metadata; all other content unchanged.
tests/response_data/read/rest/3917a1c81c08e360c0d4bba0ff9ebd645e610e4149483e5f2888a2c5df388b37-*.json Updated JSON fixture: changed request_id and created timestamp; other fields unchanged.
tests/response_data/speak/rest/1fe0ad339338a9d6cffbab2c7ace41ba5387b5fe7906854795702dce91034fd3-*.json Updated JSON fixture: changed request_id and date; other fields unchanged.

Sequence Diagram(s)

sequenceDiagram
    participant TestSuite as TestAgentMipOptOut
    participant Agent as Agent Dataclass
    participant Serializer as Serialization Logic

    TestSuite->>Agent: Instantiate Agent (default mip_opt_out)
    TestSuite->>Agent: Set mip_opt_out True/False
    TestSuite->>Serializer: Serialize Agent to dict/JSON
    Serializer-->>TestSuite: Serialized output (mip_opt_out included/excluded)
    TestSuite->>Serializer: Deserialize dict/JSON to Agent
    Serializer-->>TestSuite: Agent instance with correct mip_opt_out
Loading

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
tests/unit_test/test_unit_agent_mip_opt_out.py
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/agent-mip_opt_out

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai auto-generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@jpvajda jpvajda requested a review from lukeocodes July 18, 2025 23:04
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e9bedf2 and 67787d6.

⛔ Files ignored due to path filters (1)
  • tests/response_data/speak/rest/1fe0ad339338a9d6cffbab2c7ace41ba5387b5fe7906854795702dce91034fd3-f8c3bf62a9aa3e6fc1619c250e48abe7519373d3edf41be62eb5dc45199af2ef.wav is excluded by !**/*.wav
📒 Files selected for processing (10)
  • deepgram/clients/agent/v1/websocket/options.py (1 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)
  • tests/unit_test/test_unit_agent_mip_opt_out.py (1 hunks)
🧰 Additional context used
🧠 Learnings (4)
tests/response_data/speak/rest/1fe0ad339338a9d6cffbab2c7ace41ba5387b5fe7906854795702dce91034fd3-f8c3bf62a9aa3e6fc1619c250e48abe7519373d3edf41be62eb5dc45199af2ef-response.json (3)
Learnt from: dvonthenen
PR: deepgram/deepgram-python-sdk#472
File: examples/text-to-speech/websocket/output_to_wav/main.py:16-17
Timestamp: 2024-10-18T00:30:20.224Z
Learning: In `examples/text-to-speech/websocket/output_to_wav/main.py`, the hardcoded values for `AUDIO_FILE` and `TTS_TEXT` are intentional and should remain as is.
Learnt from: dvonthenen
PR: deepgram/deepgram-python-sdk#472
File: examples/text-to-speech/websocket/output_to_wav/main.py:52-56
Timestamp: 2024-10-18T00:30:04.220Z
Learning: In `examples/text-to-speech/websocket/output_to_wav/main.py`, the code is intended as an example demonstrating functionality, and refactoring suggestions may not be necessary.
Learnt from: dvonthenen
PR: deepgram/deepgram-python-sdk#472
File: examples/text-to-speech/websocket/output_to_wav/main.py:38-41
Timestamp: 2024-10-18T00:30:01.884Z
Learning: In the `examples/text-to-speech/websocket/output_to_wav/main.py` file, the code is intended as a simple example, and additional error handling for file operations is not required.
tests/response_data/listen/websocket/ed5bfd217988aa8cad492f63f79dc59f5f02fb9b85befe6f6ce404b8f19aaa0d-42fc5ed98cabc1fa1a2f276301c27c46dd15f6f5187cd93d944cc94fa81c8469-response.json (1)
Learnt from: dvonthenen
PR: deepgram/deepgram-python-sdk#472
File: examples/text-to-speech/websocket/output_to_wav/main.py:16-17
Timestamp: 2024-10-18T00:30:20.224Z
Learning: In `examples/text-to-speech/websocket/output_to_wav/main.py`, the hardcoded values for `AUDIO_FILE` and `TTS_TEXT` are intentional and should remain as is.
deepgram/clients/agent/v1/websocket/options.py (10)
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.
Learnt from: dvonthenen
PR: deepgram/deepgram-python-sdk#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: deepgram/deepgram-python-sdk#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: deepgram/deepgram-python-sdk#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: deepgram/deepgram-python-sdk#426
File: deepgram/clients/speak/v1/websocket/response.py:23-30
Timestamp: 2024-07-01T19:12:00.190Z
Learning: When using the `dataclasses.field` with default values in the `deepgram/clients/speak/v1/websocket/response.py`, avoid using mutable default arguments. Instead, use `field(default_factory=...)`.
Learnt from: dvonthenen
PR: deepgram/deepgram-python-sdk#426
File: deepgram/clients/speak/v1/websocket/response.py:23-30
Timestamp: 2024-10-09T02:19:48.728Z
Learning: When using the `dataclasses.field` with default values in the `deepgram/clients/speak/v1/websocket/response.py`, avoid using mutable default arguments. Instead, use `field(default_factory=...)`.
Learnt from: dvonthenen
PR: deepgram/deepgram-python-sdk#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: 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.
Learnt from: dvonthenen
PR: deepgram/deepgram-python-sdk#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: deepgram/deepgram-python-sdk#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.
tests/unit_test/test_unit_agent_mip_opt_out.py (2)
Learnt from: dvonthenen
PR: deepgram/deepgram-python-sdk#417
File: deepgram/clients/live/v1/client.py:14-14
Timestamp: 2024-06-12T18:02:10.651Z
Learning: Ignore suggestions to change import paths to local versions in test cases and examples as per user preference to use the actual `deepgram-sdk` package for testing.
Learnt from: dvonthenen
PR: deepgram/deepgram-python-sdk#417
File: deepgram/clients/live/v1/client.py:14-14
Timestamp: 2024-10-09T02:19:48.728Z
Learning: Ignore suggestions to change import paths to local versions in test cases and examples as per user preference to use the actual `deepgram-sdk` package for testing.
🔇 Additional comments (16)
tests/response_data/listen/websocket/ed5bfd217988aa8cad492f63f79dc59f5f02fb9b85befe6f6ce404b8f19aaa0d-d7334c26cf6468c191e05ff5e8151da9b67985c66ab177e9446fd14bbafd70df-response.json (1)

1-1: Test fixture metadata update looks good.

The request_id update in this JSON test fixture is consistent with routine test data maintenance and doesn't affect functionality.

tests/response_data/speak/rest/1fe0ad339338a9d6cffbab2c7ace41ba5387b5fe7906854795702dce91034fd3-f8c3bf62a9aa3e6fc1619c250e48abe7519373d3edf41be62eb5dc45199af2ef-response.json (1)

1-1: Test fixture metadata update is appropriate.

The updated request_id and date fields maintain test data freshness without affecting core functionality.

tests/response_data/read/rest/3917a1c81c08e360c0d4bba0ff9ebd645e610e4149483e5f2888a2c5df388b37-23e873efdfd4d680286fda14ff8f10864218311e79efc92ecc82bce3e574c366-response.json (1)

1-1: Test fixture metadata refresh is appropriate.

The request_id and timestamp updates maintain current test data without affecting the actual test content.

tests/response_data/listen/rest/a231370d439312b1a404bb6ad8de955e900ec8eae9a906329af8cc672e6ec7ba-a17f4880c5b4cf124ac54d06d77c9f0ab7f3fe1052ff1c7b090f7eaf8ede5b76-response.json (1)

1-1: Test fixture update preserves test integrity.

The metadata refresh maintains current request context while preserving the essential transcription content and confidence scores needed for testing.

tests/response_data/listen/rest/a231370d439312b1a404bb6ad8de955e900ec8eae9a906329af8cc672e6ec7ba-29e7c8100617f70da4ae9da1921cb5071a01219f4780ca70930b0a370ed2163a-response.json (1)

1-1: LGTM: Routine test data refresh

The metadata updates (request_id, timestamp) are appropriate for maintaining test data consistency while preserving the core transcription content.

tests/response_data/listen/rest/c4e1c0031174878d8f0e3dbd87916ee16d56f1c610ac525af5712ea37226a455-a17f4880c5b4cf124ac54d06d77c9f0ab7f3fe1052ff1c7b090f7eaf8ede5b76-response.json (1)

1-1: LGTM: Consistent test data maintenance

The metadata refresh follows the same pattern as other test fixtures, appropriately updating request identifiers while maintaining transcription accuracy.

tests/response_data/listen/websocket/ed5bfd217988aa8cad492f63f79dc59f5f02fb9b85befe6f6ce404b8f19aaa0d-42fc5ed98cabc1fa1a2f276301c27c46dd15f6f5187cd93d944cc94fa81c8469-response.json (1)

1-1: Verify the transcript content change is intentional

Unlike the other JSON response fixtures that only update metadata, this file changes the actual transcript from "Establish justice." to "Ensure domestic tranquility." Please confirm this content change is intentional and not an unintended side effect.

tests/response_data/listen/rest/c4e1c0031174878d8f0e3dbd87916ee16d56f1c610ac525af5712ea37226a455-29e7c8100617f70da4ae9da1921cb5071a01219f4780ca70930b0a370ed2163a-response.json (1)

1-1: LGTM: Standard test fixture maintenance

Consistent metadata refresh pattern maintaining transcription data integrity.

tests/unit_test/test_unit_agent_mip_opt_out.py (8)

1-11: LGTM: Proper file structure and imports

The copyright header, imports, and file structure follow the project conventions correctly.


13-26: LGTM: Comprehensive default value testing

Good test coverage for default behavior, testing both through SettingsOptions and direct Agent instantiation.


27-40: LGTM: Explicit value setting tests

Clear tests for both True and False explicit assignments with proper assertions.


41-79: LGTM: Thorough serialization testing

Excellent coverage of serialization behavior including:

  • Default value handling
  • Explicit True values
  • Explicit False values
  • Both dict and JSON serialization verification

The tests appropriately handle the potential exclusion of default/False values from serialization.


80-112: LGTM: Complete deserialization coverage

Comprehensive testing of deserialization scenarios:

  • Explicit True values
  • Explicit False values
  • Missing field (default behavior)

This ensures robust handling of various input data states.


113-132: LGTM: Essential round-trip testing

Critical tests that verify data integrity through serialization/deserialization cycles for both True and False values.


133-149: LGTM: Integration testing with other settings

Good verification that mip_opt_out works correctly alongside other agent configuration options like language and greeting.


150-171: LGTM: Type validation and direct instantiation coverage

Solid testing of:

  • Boolean type acceptance
  • Direct Agent class instantiation behavior
  • Serialization of directly created Agent instances

@jpvajda jpvajda merged commit 3e8a3dd into main Jul 21, 2025
5 checks passed
@jpvajda jpvajda deleted the feat/agent-mip_opt_out branch July 21, 2025 15:35
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.

3 participants