tool
function from the langchain
package. You can use zod to define the tool’s input schema:
schema
property as a JSON schema object:
createReactAgent()
, offering advanced tool execution control, built in parallelism, and error handling.
ToolNode
accepts the following parameters:
@tool
decorated functionsboolean
((error: unknown, toolCall: ToolCall) => ToolMessage | undefined)
true
ToolNode
provides built-in error handling for tool execution through its handleToolErrors
property.
To customize the error handling behavior, you can configure handleToolErrors
to either be a boolean
or a custom error handler function:
true
: Catch all errors and return a ToolMessage
with the default error template containing the exception details. (default)false
: Disable error handling entirely, allowing exceptions to propagate.((error: unknown, toolCall: ToolCall) => ToolMessage | undefined)
: Catch all errors and return a ToolMessage
with the result of calling the function with the exception.createReactAgent()
createReactAgent()
ToolNode
directly to createReactAgent()
:
ToolNode
to createReactAgent()
, the agent uses your exact configuration including error handling, custom names, and tags. This is useful when you need fine-grained control over tool execution behavior.
runtime
: The execution environment of your agent, containing immutable configuration and contextual data that persists throughout the agent’s execution (e.g., user IDs, session details, or application-specific configuration).config
parameter:
store
: LangChain’s persistence layer. An agent’s long-term memory store, e.g. user-specific or application-specific data stored across conversations.InMemoryStore
to store long-term memory:
.put()
method of InMemoryStore
. A complete example of persistent memory across sessions: