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.
BaseTool(
self,
**kwargs: Any = {},
)RunnableSerializable[str | dict | ToolCall, Any]The unique name of the tool that clearly communicates its purpose.
Used to tell the model how/when/why to use the tool.
You can provide few-shot examples as a part of the description.
Pydantic model class to validate and parse the tool's input arguments.
Args schema should be either:
pydantic.BaseModel.pydantic.v1.BaseModel if accessing v1 namespace in pydantic 2Whether to return the tool's output directly.
Setting this to True means that after the tool is called, the AgentExecutor will
stop looping.
Whether to log the tool's progress.
Callbacks to be called during tool execution.
Optional list of tags associated with the tool.
These tags will be associated with each call to this tool,
and passed as arguments to the handlers defined in callbacks.
You can use these to, e.g., identify a specific instance of a tool with its use case.
Optional metadata associated with the tool.
This metadata will be associated with each call to this tool,
and passed as arguments to the handlers defined in callbacks.
You can use these to, e.g., identify a specific instance of a tool with its usecase.
Handle the content of the ToolException thrown.
Handle the content of the ValidationError thrown.
The tool response format.
If 'content' then the output of the tool is interpreted as the contents of a
ToolMessage. If 'content_and_artifact' then the output is expected to be a
two-tuple corresponding to the (content, artifact) of a ToolMessage.
Optional provider-specific extra fields for the tool.
This is used to pass provider-specific configuration that doesn't fit into standard tool fields.
Check if the tool accepts only a single input argument.
Get the tool's input arguments schema.
Get the schema for tool calls, excluding injected arguments.
Return True as this class is serializable.
Get the namespace of the LangChain object.
Return a unique identifier for this class for serialization purposes.
Convert the graph to a JSON-serializable format.
Serialize a "not implemented" object.
Get a JSON schema that represents the input to the Runnable.
Get a JSON schema that represents the output of the Runnable.
The type of config this Runnable accepts specified as a Pydantic model.
Get a JSON schema that represents the config of the Runnable.
Return a list of prompts used by this Runnable.
Pipe Runnable objects.
Pick keys from the output dict of this Runnable.
Merge the Dict input with the output produced by the mapping argument.
Run invoke in parallel on a list of inputs.
Run ainvoke in parallel on a list of inputs.
Stream all output from a Runnable, as reported to the callback system.
Generate a stream of events.
Bind arguments to a Runnable, returning a new Runnable.
Bind lifecycle listeners to a Runnable, returning a new Runnable.
Bind async lifecycle listeners to a Runnable.
Bind input and output types to a Runnable, returning a new Runnable.
Create a new Runnable that retries the original Runnable on exceptions.
Map a function to multiple iterables.
Add fallbacks to a Runnable, returning a new Runnable.
Create a BaseTool from a Runnable.