|
"""This module provides tools for the agent supervisor.
|
|
|
|
It includes:
|
|
- Web Search: For general web results using Tavily.
|
|
- Python REPL: For executing Python code (Use with caution!).
|
|
"""
|
|
|
|
from typing import Annotated, List, Any, Callable, Optional, cast
|
|
|
|
|
|
from langchain_core.tools import tool
|
|
|
|
|
|
from langchain_experimental.utilities import PythonREPL
|
|
|
|
|
|
from langchain_community.tools.tavily_search import TavilySearchResults
|
|
from react_agent.configuration import Configuration
|
|
|
|
|
|
|
|
def create_tavily_tool():
|
|
"""Create the Tavily search tool with configuration from context.
|
|
|
|
Returns:
|
|
Configured TavilySearchResults tool
|
|
"""
|
|
configuration = Configuration.from_context()
|
|
return TavilySearchResults(max_results=configuration.max_search_results)
|
|
|
|
|
|
tavily_tool = create_tavily_tool()
|
|
|
|
|
|
|
|
|
|
|
|
repl = PythonREPL()
|
|
|
|
@tool
|
|
def python_repl_tool(
|
|
code: Annotated[str, "The python code to execute. Use print(...) to see output."],
|
|
):
|
|
"""Use this to execute python code. If you want to see the output of a value,
|
|
you should print it out with `print(...)`. This is visible to the user."""
|
|
try:
|
|
result = repl.run(code)
|
|
except BaseException as e:
|
|
return f"Failed to execute. Error: {repr(e)}"
|
|
|
|
result_str = f"Successfully executed:\n\`\`\`python\n{code}\n\`\`\`\nStdout: {result}"
|
|
return result_str
|
|
|
|
|
|
|
|
|
|
|
|
TOOLS: List[Callable[..., Any]] = [tavily_tool, python_repl_tool]
|
|
|