|
| 1 | +#!/usr/bin/env python3 |
| 2 | +""" |
| 3 | +Test script to verify the custom tools fix in chatbot integration. |
| 4 | +This demonstrates that agents can now use multiple custom tools when integrated into the chatbot. |
| 5 | +""" |
| 6 | + |
| 7 | +import yaml |
| 8 | +import os |
| 9 | + |
| 10 | +# Create a sample agents.yaml file |
| 11 | +agents_yaml_content = """ |
| 12 | +roles: |
| 13 | + researcher: |
| 14 | + name: "Research Agent" |
| 15 | + role: "Information Researcher" |
| 16 | + goal: "Find and analyze information using multiple tools" |
| 17 | + backstory: "You are an expert researcher with access to multiple information sources" |
| 18 | + llm: "gpt-4o-mini" |
| 19 | + tools: |
| 20 | + - search_web |
| 21 | + - get_weather |
| 22 | + - calculate |
| 23 | + tasks: |
| 24 | + test_task: |
| 25 | + description: "Use all available tools to gather information about {topic}" |
| 26 | + expected_output: "A comprehensive report using data from all tools" |
| 27 | +""" |
| 28 | + |
| 29 | +# Create a sample tools.py file |
| 30 | +tools_py_content = ''' |
| 31 | +def search_web(query: str) -> str: |
| 32 | + """Search the web for information. |
| 33 | + |
| 34 | + Args: |
| 35 | + query: The search query |
| 36 | + |
| 37 | + Returns: |
| 38 | + Search results |
| 39 | + """ |
| 40 | + return f"Web search results for: {query}" |
| 41 | +
|
| 42 | +def get_weather(location: str) -> str: |
| 43 | + """Get weather information for a location. |
| 44 | + |
| 45 | + Args: |
| 46 | + location: The location to get weather for |
| 47 | + |
| 48 | + Returns: |
| 49 | + Weather information |
| 50 | + """ |
| 51 | + return f"Weather in {location}: Sunny, 25°C" |
| 52 | +
|
| 53 | +def calculate(expression: str) -> str: |
| 54 | + """Perform a calculation. |
| 55 | + |
| 56 | + Args: |
| 57 | + expression: Mathematical expression to evaluate |
| 58 | + |
| 59 | + Returns: |
| 60 | + Calculation result |
| 61 | + """ |
| 62 | + try: |
| 63 | + result = eval(expression) |
| 64 | + return f"Result: {result}" |
| 65 | + except: |
| 66 | + return "Invalid expression" |
| 67 | +''' |
| 68 | + |
| 69 | +# Write the test files |
| 70 | +with open("test_agents.yaml", "w") as f: |
| 71 | + f.write(agents_yaml_content) |
| 72 | + |
| 73 | +with open("test_tools.py", "w") as f: |
| 74 | + f.write(tools_py_content) |
| 75 | + |
| 76 | +print("Test files created successfully!") |
| 77 | +print("\nTo test the fix:") |
| 78 | +print("1. Copy test_agents.yaml to agents.yaml") |
| 79 | +print("2. Copy test_tools.py to tools.py") |
| 80 | +print("3. Run the chatbot UI") |
| 81 | +print("4. Ask the agent to use multiple tools") |
| 82 | +print("\nThe agent should now be able to use all three tools (search_web, get_weather, calculate)") |
| 83 | +print("instead of just the last one.") |
0 commit comments