Skip to content

Conversation

@nullchimp
Copy link
Owner

This pull request introduces significant changes to the Agent and debugging infrastructure, improving session management and enabling per-session debugging. The most important changes include the removal of the persist_session decorator, the introduction of session-specific debugging instances, and updates to the Chat and DebugCapture classes to support session-based functionality.

Session Management Enhancements:

  • Removed the persist_session decorator and its associated functionality from src/agent.py, simplifying session handling and reducing redundancy. [1] [2] [3]
  • Updated the Chat class to accept a session_id parameter, ensuring session-specific operations for tools and chat interactions. [1] [2] [3]
  • Added session-specific handling in delete_agent_instance to clean up debugging instances when an agent session is deleted.

Debugging Improvements:

  • Refactored the DebugCapture class to support multiple sessions, replacing the singleton pattern with per-session instances managed by _debug_sessions. [1] [2]
  • Introduced helper functions such as get_debug_capture_instance, delete_debug_capture_instance, and clear_all_debug_events for managing session-specific debugging data.
  • Updated debugging-related API routes in src/api/routes.py to utilize session-specific debug capture instances, ensuring isolated debugging for each session. [1] [2] [3]

Refactoring for Clarity:

  • Modified the DebugEvent class to require a session_id during initialization, ensuring events are tied to specific sessions.
  • Updated debug capture calls in src/core/llm/chat.py and src/core/llm/client.py to pass the session_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.

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.
Copilot AI review requested due to automatic review settings June 24, 2025 14:40
Copy link

Copilot AI left a 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_sessions APIs).
  • Update Chat and Agent to pass session_id throughout 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 False after parsing the response.
        data = response.json()

tests/test_color_scheme.py:66

  • The variable events is not defined in this test. You need to call events = 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
Copy link

Copilot AI Jun 24, 2025

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.

Suggested change
from src.core.debug_capture import get_debug_capture_instance, _debug_sessions
from core.debug_capture import get_debug_capture_instance, _debug_sessions

Copilot uses AI. Check for mistakes.
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.
@nullchimp nullchimp merged commit 4027bd0 into main Jun 24, 2025
4 checks passed
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.

2 participants