#!/usr/bin/env python3
"""
Test the proxy workaround: retry without tools on empty response.
"""

import os
import sys
sys.path.append(os.getcwd())

from health.utils.env_loader import load_env_with_extras
from slack_bot.llm.gemini import GeminiLLM
from slack_bot.tools.registry import TOOLS_SCHEMA

load_env_with_extras()

print("=" * 60)
print("Testing Proxy Workaround")
print("=" * 60)

llm = GeminiLLM()

print(f"\nUsing proxy: {llm.use_proxy}")
print(f"Model: {llm.get_model_name()}")

print("\nTest: '今天睡得怎么样？' with 21 tools")
print("(Should auto-retry without tools if empty)")
print("-" * 60)

response, tool_calls = llm.generate_response(
    message="今天睡得怎么样？",
    context=[],
    tools=TOOLS_SCHEMA,
    images=None
)

print(f"\nResult:")
print(f"  Response length: {len(response) if response else 0}")
print(f"  Tool calls: {tool_calls}")

if response and response.strip():
    print(f"\n✅ SUCCESS!")
    print(f"  Response preview:\n{response[:500]}")
else:
    print(f"\n❌ Still empty")
    print(f"  Check logs for retry attempt")
