Skip to content

Comments

Refine realtime conversation memory usage#375

Merged
KaQuMiQ merged 1 commit intomainfrom
feature/realtime_memory
Jul 23, 2025
Merged

Refine realtime conversation memory usage#375
KaQuMiQ merged 1 commit intomainfrom
feature/realtime_memory

Conversation

@KaQuMiQ
Copy link
Collaborator

@KaQuMiQ KaQuMiQ commented Jul 23, 2025

No description provided.

@coderabbitai
Copy link

coderabbitai bot commented Jul 23, 2025

Walkthrough

The changes in lmm_session.py introduce enhancements to session management and event handling. A mutable set current_items is added to track conversation item IDs during a session. The read coroutine is updated to process new event types "conversation.item.created" and "conversation.item.retrieved", updating memory and triggering retrievals or context updates based on the event and content type. The handling of "response.output_item.done" is simplified to process only assistant messages. Metadata in event responses is standardized to include specific identifiers and timestamps. The write coroutine now processes a new "memory.update" event category, invoking a newly added _reset_context function, which deletes tracked items and resends context. Logging levels for unsupported input types are adjusted, and content processing is enhanced to append transcript metadata when present.

Estimated code review effort

4 (~90 minutes)


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 162be31 and 4cfd113.

📒 Files selected for processing (1)
  • src/draive/openai/lmm_session.py (14 hunks)
📓 Path-based instructions (1)
**/*.py

📄 CodeRabbit Inference Engine (CLAUDE.md)

**/*.py: Use absolute imports from draive package
Follow Ruff import ordering (standard library, third party, local)
Use Python 3.12+ type features (type unions with |, generic syntax)
Use base and abstract types like Sequence or Iterable instead of concrete types
Use custom exceptions for specific errors
Use NumPy docstring convention for all functions, classes, and methods
Skip module-level docstrings unless explicitly requested
Include sections: Parameters, Returns, Raises, Notes (if needed) in docstrings
ALWAYS use Sequence[T] instead of list[T], Mapping[K,V] instead of dict[K,V], and Set[T] instead of set[T] for collections in State, Config and DataModel classes
Immutable updates to State, Config, and DataModel classes should be performed through the .updated() method

Files:

  • src/draive/openai/lmm_session.py
🧬 Code Graph Analysis (1)
src/draive/openai/lmm_session.py (7)
src/draive/conversation/realtime/default.py (1)
  • read (106-148)
src/draive/lmm/types.py (14)
  • read (413-414)
  • LMMCompletion (151-168)
  • of (84-107)
  • of (133-142)
  • of (153-162)
  • of (184-200)
  • of (211-220)
  • of (260-274)
  • of (284-295)
  • of (309-320)
  • of (375-385)
  • LMMSessionEvent (373-388)
  • LMMStreamChunk (307-327)
  • LMMToolResponse (182-206)
src/draive/multimodal/content.py (2)
  • meta (151-164)
  • of (28-50)
src/draive/utils/memory.py (5)
  • remember (75-83)
  • remember (106-117)
  • recall (51-54)
  • recall (69-73)
  • recall (100-104)
src/draive/multimodal/media.py (2)
  • of (48-60)
  • of (79-91)
src/draive/multimodal/meta.py (1)
  • MetaContent (12-30)
src/draive/multimodal/text.py (1)
  • TextContent (10-27)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.py

📄 CodeRabbit Inference Engine (CLAUDE.md)

**/*.py: Use absolute imports from draive package
Follow Ruff import ordering (standard library, third party, local)
Use Python 3.12+ type features (type unions with |, generic syntax)
Use base and abstract types like Sequence or Iterable instead of concrete types
Use custom exceptions for specific errors
Use NumPy docstring convention for all functions, classes, and methods
Skip module-level docstrings unless explicitly requested
Include sections: Parameters, Returns, Raises, Notes (if needed) in docstrings
ALWAYS use Sequence[T] instead of list[T], Mapping[K,V] instead of dict[K,V], and Set[T] instead of set[T] for collections in State, Config and DataModel classes
Immutable updates to State, Config, and DataModel classes should be performed through the .updated() method

Files:

  • src/draive/openai/lmm_session.py
🧬 Code Graph Analysis (1)
src/draive/openai/lmm_session.py (7)
src/draive/conversation/realtime/default.py (1)
  • read (106-148)
src/draive/lmm/types.py (14)
  • read (413-414)
  • LMMCompletion (151-168)
  • of (84-107)
  • of (133-142)
  • of (153-162)
  • of (184-200)
  • of (211-220)
  • of (260-274)
  • of (284-295)
  • of (309-320)
  • of (375-385)
  • LMMSessionEvent (373-388)
  • LMMStreamChunk (307-327)
  • LMMToolResponse (182-206)
src/draive/multimodal/content.py (2)
  • meta (151-164)
  • of (28-50)
src/draive/utils/memory.py (5)
  • remember (75-83)
  • remember (106-117)
  • recall (51-54)
  • recall (69-73)
  • recall (100-104)
src/draive/multimodal/media.py (2)
  • of (48-60)
  • of (79-91)
src/draive/multimodal/meta.py (1)
  • MetaContent (12-30)
src/draive/multimodal/text.py (1)
  • TextContent (10-27)
🔇 Additional comments (7)
src/draive/openai/lmm_session.py (7)

3-3: LGTM!

The import addition follows proper ordering and uses the appropriate abstract type from collections.abc.


121-121: LGTM!

Proper initialization of the mutable set to track conversation item IDs.


126-340: Well-structured event handling improvements

The changes effectively implement conversation item tracking and memory synchronization:

  • Proper nonlocal declaration for accessing current_items
  • Consistent metadata structure across all events
  • Clean separation of concerns between created and retrieved items
  • Simplified assistant message handling

354-379: Proper implementation of memory update handling

The changes correctly handle the new "memory.update" event:

  • Appropriate nonlocal declaration
  • Clean integration with the new _reset_context function
  • Proper cleanup of tracked items after reset

502-509: Good error handling implementation

The error handling for item deletion is well-implemented, logging failures without breaking the flow.


555-555: Appropriate log level adjustment

Changing from error to warning better reflects that unsupported MetaContent is skipped without breaking functionality.


714-716: Proper transcript metadata handling

The implementation correctly wraps transcript content as MetaContent with the "transcript" category, maintaining proper content structure.

✨ Finishing Touches
  • 📝 Generate Docstrings

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 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.

Copy link

@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: 6

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 709959e and 162be31.

📒 Files selected for processing (1)
  • src/draive/openai/lmm_session.py (14 hunks)
📓 Path-based instructions (1)
**/*.py

📄 CodeRabbit Inference Engine (CLAUDE.md)

**/*.py: Use absolute imports from draive package
Follow Ruff import ordering (standard library, third party, local)
Use Python 3.12+ type features (type unions with |, generic syntax)
Use base and abstract types like Sequence or Iterable instead of concrete types
Use custom exceptions for specific errors
Use NumPy docstring convention for all functions, classes, and methods
Skip module-level docstrings unless explicitly requested
Include sections: Parameters, Returns, Raises, Notes (if needed) in docstrings
ALWAYS use Sequence[T] instead of list[T], Mapping[K,V] instead of dict[K,V], and Set[T] instead of set[T] for collections in State, Config and DataModel classes
Immutable updates to State, Config, and DataModel classes should be performed through the .updated() method

Files:

  • src/draive/openai/lmm_session.py
🧰 Additional context used
📓 Path-based instructions (1)
**/*.py

📄 CodeRabbit Inference Engine (CLAUDE.md)

**/*.py: Use absolute imports from draive package
Follow Ruff import ordering (standard library, third party, local)
Use Python 3.12+ type features (type unions with |, generic syntax)
Use base and abstract types like Sequence or Iterable instead of concrete types
Use custom exceptions for specific errors
Use NumPy docstring convention for all functions, classes, and methods
Skip module-level docstrings unless explicitly requested
Include sections: Parameters, Returns, Raises, Notes (if needed) in docstrings
ALWAYS use Sequence[T] instead of list[T], Mapping[K,V] instead of dict[K,V], and Set[T] instead of set[T] for collections in State, Config and DataModel classes
Immutable updates to State, Config, and DataModel classes should be performed through the .updated() method

Files:

  • src/draive/openai/lmm_session.py

@KaQuMiQ KaQuMiQ force-pushed the feature/realtime_memory branch from 162be31 to 4cfd113 Compare July 23, 2025 14:32
@KaQuMiQ KaQuMiQ merged commit 08c2848 into main Jul 23, 2025
5 checks passed
@KaQuMiQ KaQuMiQ deleted the feature/realtime_memory branch July 23, 2025 14:41
@coderabbitai coderabbitai bot mentioned this pull request Jul 31, 2025
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.

1 participant