Skip to content

Tools

web_search_tool

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

Return the configured web search tool.

With SEARCH_BACKEND=mcp, max_results and search_depth do not apply: the MCP server decides how much it returns.

Raises:

Type Description
RuntimeError

Tavily is selected and TAVILY_API_KEY is not set. Searching nothing quietly would let an agent answer from memory while looking like it searched.

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 the configured web search tool.

    With SEARCH_BACKEND=mcp, ``max_results`` and ``search_depth`` do not apply: the MCP
    server decides how much it returns.

    Raises:
        RuntimeError: Tavily is selected and TAVILY_API_KEY is not set. Searching nothing
            quietly would let an agent answer from memory while looking like it searched.
    """
    if settings.search_backend == "mcp":
        from agentic_architectures.tools.mcp import mcp_tools

        key = settings.search_mcp_api_key
        headers = {"Authorization": f"Bearer {key.get_secret_value()}"} if key is not None else None
        tools = mcp_tools(settings.search_mcp_url, headers=headers)
        return next((t for t in tools if "search" in t.name.lower()), tools[0])

    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, "
            "or set SEARCH_BACKEND=mcp to search through a free, keyless MCP server "
            "(pip install agentic-architectures[mcp])."
        )

    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