refactor: reorganize session management into dedicated components#631
Closed
refactor: reorganize session management into dedicated components#631
Conversation
Split session logic into dedicated components for better separation of concerns and maintainability: - Move session code to dedicated session/ module - Split Session class into: - Session: Data container with minimal public API - SessionManager: Handles lifecycle and state management - SessionApi: Handles API communication - SessionTelemetry: Manages event recording and OTEL integration Key fixes: - Proper UUID and timestamp serialization in events - Consistent API key header handling - Correct token cost formatting in analytics - Proper session ID inheritance - Tags conversion and validation - Event counts type handling This refactor improves code organization while maintaining backward compatibility through the session/__init__.py module. Signed-off-by: Teo <teocns@gmail.com>
6a8e7af to
eb072db
Compare
Contributor
Author
|
@the-praxs can you please review and run manual (integration) tests? 🙏 |
Member
dot-agi
requested changes
Jan 9, 2025
Member
dot-agi
left a comment
There was a problem hiding this comment.
Left comments on the failing tests for CrewAI and Autogen.
We need to fix the issue with CrewAI failing in this PR. Then we have to fix Autogen in a new PR since it's occurring on main too.
After these I think the PR is ready to be tested and merged, should the tests pass!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
This PR refactors the session management code to improve maintainability, testability, and separation of concerns, historically proposed in #486. The main changes include:
Sessionclass into smaller, focused componentsKey Changes
1. New Module Structure
Created a dedicated
sessionpackage with clear component separation:session.py- Core session data container and public APImanager.py- Session lifecycle and state managementapi.py- API communication layertelemetry.py- OpenTelemetry integrationregistry.py- Active sessions tracking2. Improved Error Event Handling
ErrorEventproperly inherit fromEventbase class (booyah! @areibman)3. Client Simplification
Implementation Details
Session Components
Each component has a single responsibility:
sequenceDiagram participant C as Client participant S as Session participant M as SessionManager participant A as SessionApi participant T as SessionTelemetry participant E as SessionExporter C->>S: start_session() S->>M: create() M->>A: create_session() A-->>M: jwt M->>T: setup() T->>E: init() C->>S: record(event) S->>M: record_event() M->>T: record_event() T->>E: export() E->>A: create_events()