feat: Implement Trillium notes executor for searching and creating notes via ETAPI
- Added `trillium.py` for searching and creating notes with Trillium's ETAPI. - Implemented `search_notes` and `create_note` functions with appropriate error handling and validation. feat: Add web search functionality using DuckDuckGo - Introduced `web_search.py` for performing web searches without API keys. - Implemented `search_web` function with result handling and validation. feat: Create provider-agnostic function caller for iterative tool calling - Developed `function_caller.py` to manage LLM interactions with tools. - Implemented iterative calling logic with error handling and tool execution. feat: Establish a tool registry for managing available tools - Created `registry.py` to define and manage tool availability and execution. - Integrated feature flags for enabling/disabling tools based on environment variables. feat: Implement event streaming for tool calling processes - Added `stream_events.py` to manage Server-Sent Events (SSE) for tool calling. - Enabled real-time updates during tool execution for enhanced user experience. test: Add tests for tool calling system components - Created `test_tools.py` to validate functionality of code execution, web search, and tool registry. - Implemented asynchronous tests to ensure proper execution and result handling. chore: Add Dockerfile for sandbox environment setup - Created `Dockerfile` to set up a Python environment with necessary dependencies for code execution. chore: Add debug regex script for testing XML parsing - Introduced `debug_regex.py` to validate regex patterns against XML tool calls. chore: Add HTML template for displaying thinking stream events - Created `test_thinking_stream.html` for visualizing tool calling events in a user-friendly format. test: Add tests for OllamaAdapter XML parsing - Developed `test_ollama_parser.py` to validate XML parsing with various test cases, including malformed XML.
This commit is contained in:
91
test_tools.py
Normal file
91
test_tools.py
Normal file
@@ -0,0 +1,91 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Quick test script for tool calling system.
|
||||
Tests the components before full endpoint integration.
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
import sys
|
||||
import os
|
||||
|
||||
# Add cortex to path
|
||||
sys.path.insert(0, '/home/serversdown/project-lyra/cortex')
|
||||
|
||||
# Set required env vars
|
||||
os.environ['ENABLE_CODE_EXECUTION'] = 'true'
|
||||
os.environ['ENABLE_WEB_SEARCH'] = 'true'
|
||||
os.environ['CODE_SANDBOX_CONTAINER'] = 'lyra-code-sandbox'
|
||||
|
||||
from autonomy.tools.registry import get_registry
|
||||
from autonomy.tools.executors.code_executor import execute_code
|
||||
from autonomy.tools.executors.web_search import search_web
|
||||
|
||||
|
||||
async def test_code_executor():
|
||||
"""Test code execution in sandbox."""
|
||||
print("\n=== Testing Code Executor ===")
|
||||
|
||||
result = await execute_code({
|
||||
"language": "python",
|
||||
"code": "print('Hello from sandbox!')\nprint(2 + 2)",
|
||||
"reason": "Testing sandbox execution"
|
||||
})
|
||||
|
||||
print(f"Result: {result}")
|
||||
return result.get("stdout") == "Hello from sandbox!\n4\n"
|
||||
|
||||
|
||||
async def test_web_search():
|
||||
"""Test web search."""
|
||||
print("\n=== Testing Web Search ===")
|
||||
|
||||
result = await search_web({
|
||||
"query": "Python programming",
|
||||
"max_results": 3
|
||||
})
|
||||
|
||||
print(f"Found {result.get('count', 0)} results")
|
||||
if result.get('results'):
|
||||
print(f"First result: {result['results'][0]['title']}")
|
||||
return result.get("count", 0) > 0
|
||||
|
||||
|
||||
async def test_registry():
|
||||
"""Test tool registry."""
|
||||
print("\n=== Testing Tool Registry ===")
|
||||
|
||||
registry = get_registry()
|
||||
tools = registry.get_tool_definitions()
|
||||
|
||||
print(f"Registered tools: {registry.get_tool_names()}")
|
||||
print(f"Total tools: {len(tools) if tools else 0}")
|
||||
|
||||
return len(tools or []) > 0
|
||||
|
||||
|
||||
async def main():
|
||||
print("🧪 Tool System Component Tests\n")
|
||||
|
||||
tests = [
|
||||
("Tool Registry", test_registry),
|
||||
("Code Executor", test_code_executor),
|
||||
("Web Search", test_web_search),
|
||||
]
|
||||
|
||||
results = {}
|
||||
for name, test_func in tests:
|
||||
try:
|
||||
passed = await test_func()
|
||||
results[name] = "✅ PASS" if passed else "❌ FAIL"
|
||||
except Exception as e:
|
||||
results[name] = f"❌ ERROR: {str(e)}"
|
||||
|
||||
print("\n" + "="*50)
|
||||
print("Test Results:")
|
||||
for name, result in results.items():
|
||||
print(f" {name}: {result}")
|
||||
print("="*50)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
Reference in New Issue
Block a user