#!/usr/bin/env python3 """ Test script to verify the updated agent works with standard OpenAI tool calling """ import os import sys import json from _bootstrap import add_project_root add_project_root() from agent import KVCacheAgent, KVCacheMode def test_tool_calling(): """Test that the agent correctly uses OpenAI tool calling format""" # Get API key api_key = os.getenv("MOONSHOT_API_KEY") if not api_key: print("โŒ Please set MOONSHOT_API_KEY environment variable") sys.exit(1) print("๐Ÿงช Testing Standard OpenAI Tool Calling Format") print("="*60) # Simple task that requires tool calls task = "Find all Python files in the chapter1/context directory and tell me how many there are." print(f"๐Ÿ“ Task: {task}") print("-"*60) # Create agent with correct implementation agent = KVCacheAgent( api_key=api_key, mode=KVCacheMode.CORRECT, root_dir="../..", verbose=True # Enable verbose to see tool calls ) # Execute task result = agent.execute_task(task, max_iterations=5) # Check results print("\n" + "="*60) print("๐Ÿ“Š Results:") print(f"โœ“ Success: {result['success']}") print(f"โœ“ Iterations: {result['iterations']}") print(f"โœ“ Tool Calls Made: {len(result['tool_calls'])}") if result['tool_calls']: print("\n๐Ÿ”ง Tool Calls:") for tc in result['tool_calls']: print(f" โ€ข {tc.name}({tc.arguments})") if tc.result and tc.result.get('success'): if tc.name == 'find': print(f" โ†’ Found {tc.result.get('count', 0)} files") if result['final_answer']: print(f"\n๐Ÿ’ฌ Final Answer:") print(f" {result['final_answer'][:200]}...") # Test metrics metrics = result['metrics'] print(f"\n๐Ÿ“ˆ Performance Metrics:") print(f" โ€ข TTFT: {metrics.ttft:.3f}s") print(f" โ€ข Total Time: {metrics.total_time:.3f}s") print(f" โ€ข Cached Tokens: {metrics.cached_tokens}") print("\nโœ… Tool calling test completed successfully!") if __name__ == "__main__": test_tool_calling()