-
Notifications
You must be signed in to change notification settings - Fork 0
Session management #23
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
Refactors debug capture to be managed on a per-session basis, allowing independent debugging contexts for each agent session. Removes the singleton pattern for DebugCapture and introduces session-based management using a dictionary. Adds functions to manage debug capture instances, retrieve all events, and clear events, either globally or for a specific session. Removes the `persist_session` decorator since session management is now handled directly. Updates the agent and API routes to use the new session-based debug capture.
Ensures debug capture is enabled by default for each new session and properly cleaned up when a session is deleted. Also, updates LLM clients to use the session ID when capturing debug information, allowing for session-specific debugging. Adds integration test to verify debug capture functionality with session IDs.
Addresses an issue where the debug panel's open state and debug enabled status were not correctly saved and restored on a per-session basis. The previous implementation used class-level variables to track the debug panel state, causing the state to be shared across all sessions. This commit modifies the code to manage the debug panel state and debug enabled status within each chat session. This ensures that each session maintains its own independent debug settings, and that these settings are correctly persisted and restored, including across browser reloads.
Adds loading indicators to the "New Chat" button and tools configuration, providing visual feedback during session creation and tool initialization. This improves the user experience by indicating that the application is processing the request and prevents multiple clicks on the "New Chat" button during session creation.
Enhances the chat application by implementing an empty state when no sessions exist. This change addresses several issues: - It ensures the UI displays a clear message when all chat sessions are deleted. - Disables input and send button when no active session exists, preventing errors. - Re-enables input upon loading or creating a new session for a smoother user experience. - Implements showing the tools configuration and debug events only for active sessions.
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.
Pull Request Overview
This PR refactors session and debug management to be session-specific, removes the persist_session decorator, and updates both the backend API and frontend UI to support per-session debugging and improved loading states.
- Replace singleton debug capture with per-session instances (
_debug_sessionsAPIs). - Update
ChatandAgentto passsession_idthroughout LLM and tool calls. - Revamp UI (
chat.ts,index.html,styles.css) for loading indicators and session-based debug panels. - Adjust API routes to use
/api/{session_id}/...for debugging and session management. - Extend and update tests to cover session-based behaviors and loading states.
Reviewed Changes
Copilot reviewed 26 out of 26 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/core/debug_capture.py | Introduced session‐specific debug capture instances |
| src/api/routes.py | Updated debug and session routes to accept session_id |
| src/ui/chat.ts | Added per‐session loading & debug state management |
| tests/test_loading_states.py | New tests for frontend loading state logic |
| tests/test_color_scheme.py | Tests for color annotation in debug serialization |
Comments suppressed due to low confidence (2)
tests/test_debug_api.py:30
- Missing an assertion to verify that debug mode is disabled by default. Consider adding
assert data['enabled'] is Falseafter parsing the response.
data = response.json()
tests/test_color_scheme.py:66
- The variable
eventsis not defined in this test. You need to callevents = debug_capture.get_events()before asserting on it.
assert len(events) >= 3
| @@ -0,0 +1,80 @@ | |||
| import pytest | |||
| from src.core.debug_capture import get_debug_capture_instance, _debug_sessions | |||
Copilot
AI
Jun 24, 2025
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.
Import path for debug_capture is inconsistent with other tests (core.debug_capture vs src.core.debug_capture). Consider standardizing to a single import style.
| from src.core.debug_capture import get_debug_capture_instance, _debug_sessions | |
| from core.debug_capture import get_debug_capture_instance, _debug_sessions |
Updates tests to dynamically determine the project root, allowing them to correctly locate the CSS and HTML files regardless of the execution environment. This prevents hardcoded paths and ensures that tests run reliably.
Adds a detailed README file to provide comprehensive documentation for the AI Agent project, including features, architecture, setup, usage, configuration, available tools, and contribution guidelines. Includes a screenshot of the chat UI.
Changes the default behavior for debug capture to be disabled upon session creation. Updates tests to reflect this change and explicitly enable debug capture when needed for testing purposes. This aligns with the intended functionality and provides better control over debug data collection.
This pull request introduces significant changes to the
Agentand debugging infrastructure, improving session management and enabling per-session debugging. The most important changes include the removal of thepersist_sessiondecorator, the introduction of session-specific debugging instances, and updates to theChatandDebugCaptureclasses to support session-based functionality.Session Management Enhancements:
persist_sessiondecorator and its associated functionality fromsrc/agent.py, simplifying session handling and reducing redundancy. [1] [2] [3]Chatclass to accept asession_idparameter, ensuring session-specific operations for tools and chat interactions. [1] [2] [3]delete_agent_instanceto clean up debugging instances when an agent session is deleted.Debugging Improvements:
DebugCaptureclass to support multiple sessions, replacing the singleton pattern with per-session instances managed by_debug_sessions. [1] [2]get_debug_capture_instance,delete_debug_capture_instance, andclear_all_debug_eventsfor managing session-specific debugging data.src/api/routes.pyto utilize session-specific debug capture instances, ensuring isolated debugging for each session. [1] [2] [3]Refactoring for Clarity:
DebugEventclass to require asession_idduring initialization, ensuring events are tied to specific sessions.src/core/llm/chat.pyandsrc/core/llm/client.pyto pass thesession_id, enabling session-specific logging for tool calls and LLM requests. [1] [2] [3]These changes collectively enhance session isolation, simplify debugging workflows, and improve the maintainability of the codebase.