Tools are classes that an Agent uses to interact with the world.
Each tool has a description. Agent uses the description to choose the righ tool for the job.
Import an attribute from a module located in a package.
This utility function is used in custom __getattr__ methods within __init__.py
files to dynamically import attributes.
Create a Pydantic schema from a function's signature.
Convert a Runnable into a BaseTool.
Convert Python functions and Runnables to LangChain tools.
Can be used as a decorator with or without arguments to create tools from functions.
Functions can have any signature - the tool will automatically infer input schemas unless disabled.
Runnable, a string name must be provided.Render the tool name and description in plain text.
Render the tool name, description, and args in plain text.
Create a tool to do retrieval of documents.
Base class for all LangChain tools.
This abstract class defines the interface that all LangChain tools must implement.
Tools are components that can be called by agents to perform specific actions.
Base class for toolkits containing related tools.
A toolkit is a collection of related tools that can be used together to accomplish a specific task or work with a particular system.
Annotation for tool arguments that are injected at runtime.
Tool arguments annotated with this class are not included in the tool schema sent to language models and are instead injected during execution.
Annotation for injecting the tool call ID.
This annotation is used to mark a tool parameter that should receive the tool call ID at runtime.
from typing import Annotated
from langchain_core.messages import ToolMessage
from langchain_core.tools import tool, InjectedToolCallId
@tool
def foo(
x: int, tool_call_id: Annotated[str, InjectedToolCallId]
) -> ToolMessage:
"""Return x."""
return ToolMessage(
str(x),
artifact=x,
name="foo",
tool_call_id=tool_call_id
)Raised when args_schema is missing or has an incorrect type annotation.
Exception thrown when a tool execution error occurs.
This exception allows tools to signal errors without stopping the agent.
The error is handled according to the tool's handle_tool_error setting, and the
result is returned as an observation to the agent.
Input to the retriever.
Tool that takes in function or coroutine directly.
Tool that can operate on any number of inputs.