Skip to content

Conversation

@voxmenthe
Copy link
Owner

@voxmenthe voxmenthe commented Jun 20, 2025

Refactor: Enhance modularity, maintainability, and async handling

This major refactoring separates the CLI LLM agent into distinct components:

  1. LLMAgentCore (src/llm_agent_core.py):

    • Encapsulates core LLM interaction logic: Gemini client management, chat session handling, conversation history, token counting.
    • Manages tool registration and execution, supporting both synchronous and asynchronous tools (using AsyncTaskManager for async tools).
    • Handles GenerationConfig.
  2. CodeAgent (src/main.py):

    • Acts as the CLI interaction layer using prompt-toolkit.
    • Delegates LLM operations to LLMAgentCore.
    • Delegates background task management to AsyncTaskManager.
    • Manages CLI-specific state.
  3. AsyncTaskManager (src/async_task_manager.py):

    • Centralizes asyncio event loop management (runs in a separate thread).
    • Handles submission, tracking, and cancellation of background tasks (e.g., PDF processing, script execution).
    • Provides callbacks for task results.
  4. Slash Commands (src/slashcommands.py):

    • Handlers updated to interact with LLMAgentCore for relevant backend operations and state modifications.
  5. Tools (src/tools.py):

    • Browser-based tools (google_search, open_url) converted to async def.
    • Standardized google.generativeai imports.

Key Improvements & Fixes:

  • Resolved critical ImportError for google.genai by standardizing import style.
  • Fixed AttributeError by migrating from ThinkingConfig to GenerationConfig.
  • Addressed ImportError for BrowserContext in agent_browser_utils.py.
  • Improved separation of concerns for state management.
  • Ensured clean configuration loading and component initialization.
  • Validated structural integrity through iterative application startup checks.

Outstanding Considerations (for future work):

  • Runtime testing of browser-based tools due to a potential underlying dependency conflict with browser-use.
  • Full functional validation of all commands and LLM interactions in a live environment.
  • Further investigation into mapping the /thinking_budget command's intent to GenerationConfig capabilities.

… done so far and provide feedback for Jules to continue.
This major refactoring separates the CLI LLM agent into distinct components:

1.  **LLMAgentCore (`src/llm_agent_core.py`):**
    *   Encapsulates core LLM interaction logic: Gemini client management, chat session handling, conversation history, token counting.
    *   Manages tool registration and execution, supporting both synchronous and asynchronous tools (using AsyncTaskManager for async tools).
    *   Handles `GenerationConfig`.

2.  **CodeAgent (`src/main.py`):**
    *   Acts as the CLI interaction layer using `prompt-toolkit`.
    *   Delegates LLM operations to `LLMAgentCore`.
    *   Delegates background task management to `AsyncTaskManager`.
    *   Manages CLI-specific state.

3.  **AsyncTaskManager (`src/async_task_manager.py`):**
    *   Centralizes `asyncio` event loop management (runs in a separate thread).
    *   Handles submission, tracking, and cancellation of background tasks (e.g., PDF processing, script execution).
    *   Provides callbacks for task results.

4.  **Slash Commands (`src/slashcommands.py`):**
    *   Handlers updated to interact with `LLMAgentCore` for relevant backend operations and state modifications.

5.  **Tools (`src/tools.py`):**
    *   Browser-based tools (`google_search`, `open_url`) converted to `async def`.
    *   Standardized `google.generativeai` imports.

**Key Improvements & Fixes:**
*   Resolved critical `ImportError` for `google.genai` by standardizing import style.
*   Fixed `AttributeError` by migrating from `ThinkingConfig` to `GenerationConfig`.
*   Addressed `ImportError` for `BrowserContext` in `agent_browser_utils.py`.
*   Improved separation of concerns for state management.
*   Ensured clean configuration loading and component initialization.
*   Validated structural integrity through iterative application startup checks.

**Outstanding Considerations (for future work):**
*   Runtime testing of browser-based tools due to a potential underlying dependency conflict with `browser-use`.
*   Full functional validation of all commands and LLM interactions in a live environment.
*   Further investigation into mapping the `/thinking_budget` command's intent to `GenerationConfig` capabilities.
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