refactor: consolidate debug logging across tools with shared DebugSession class

- Introduced a new DebugSession class in tools/debug_helpers.py to centralize debug logging functionality, replacing duplicated code across various tool modules.
- Updated image_generation_tool.py, mixture_of_agents_tool.py, vision_tools.py, web_tools.py, and others to utilize the new DebugSession for logging tool calls and saving debug logs.
- Enhanced maintainability and consistency in debug logging practices across the codebase.
This commit is contained in:
teknium1
2026-02-21 03:53:24 -08:00
parent 748fd3db88
commit 7ee7221af1
7 changed files with 193 additions and 441 deletions

View File

@@ -22,29 +22,12 @@ import os
import logging
from typing import Dict, Any, List, Optional
from openai import AsyncOpenAI
from hermes_constants import OPENROUTER_BASE_URL
from tools.openrouter_client import get_async_client as _get_client
SUMMARIZER_MODEL = "google/gemini-3-flash-preview"
MAX_SESSION_CHARS = 100_000
MAX_SUMMARY_TOKENS = 2000
_summarizer_client = None
def _get_client() -> AsyncOpenAI:
"""Lazy-init the summarizer client (shared with web_tools pattern)."""
global _summarizer_client
if _summarizer_client is None:
api_key = os.getenv("OPENROUTER_API_KEY")
if not api_key:
raise ValueError("OPENROUTER_API_KEY not set")
_summarizer_client = AsyncOpenAI(
api_key=api_key,
base_url=OPENROUTER_BASE_URL,
)
return _summarizer_client
def _format_conversation(messages: List[Dict[str, Any]]) -> str:
"""Format session messages into a readable transcript for summarization."""