Skip to content

Tools

web_search_tool

web_search_tool(max_results: int = 5, search_depth: str = 'advanced', **kwargs: Any) -> BaseTool

Return a configured Tavily search tool.

Source code in src/agentic_architectures/tools/search.py
def web_search_tool(
    max_results: int = 5,
    search_depth: str = "advanced",
    **kwargs: Any,
) -> BaseTool:
    """Return a configured Tavily search tool."""
    try:
        from langchain_tavily import TavilySearch
    except ImportError as e:
        raise ImportError("pip install agentic-architectures[tavily]") from e

    key = settings.tavily_api_key
    if key is None:
        raise RuntimeError(
            "TAVILY_API_KEY not set. Sign up free at https://app.tavily.com and add the key to your .env file."
        )

    return TavilySearch(
        max_results=max_results,
        search_depth=search_depth,
        tavily_api_key=key.get_secret_value(),
        **kwargs,
    )

python_repl_tool

python_repl_tool(code: str) -> str

Execute a snippet of Python code and return stdout (or the error).

Use this when you need to compute something deterministic — math, string manipulation, parsing, simple data transformation.

Source code in src/agentic_architectures/tools/code_exec.py
@tool
def python_repl_tool(code: str) -> str:
    """Execute a snippet of Python code and return stdout (or the error).

    Use this when you need to compute something deterministic — math,
    string manipulation, parsing, simple data transformation.
    """
    try:
        from langchain_experimental.utilities import PythonREPL
    except ImportError:
        # Fallback to a built-in minimal exec for environments without langchain-experimental.
        import contextlib
        import io

        buf = io.StringIO()
        local_vars: dict[str, object] = {}
        try:
            with contextlib.redirect_stdout(buf):
                exec(code, {"__builtins__": __builtins__}, local_vars)  # noqa: S102
            out = buf.getvalue()
            return out if out else repr(local_vars)
        except Exception as e:  # pragma: no cover  (deterministic enough)
            return f"ERROR: {type(e).__name__}: {e}"

    repl = PythonREPL()
    return repl.run(code)

SimulatorTool

SimulatorTool(simulate: Callable[[str], str], name: str = 'simulate_action', description: str = 'Simulate an action and return the predicted outcome WITHOUT executing it in the real world. Use this to weigh options before committing.')

Wrap a domain-specific simulator function in a LangChain tool.

Source code in src/agentic_architectures/tools/simulator.py
def __init__(
    self,
    simulate: Callable[[str], str],
    name: str = "simulate_action",
    description: str = (
        "Simulate an action and return the predicted outcome WITHOUT executing it "
        "in the real world. Use this to weigh options before committing."
    ),
) -> None:
    self._simulate = simulate
    self.name = name
    self.description = description