Diamond Machining - diamond machining
Create toolreview
The Tool and ToolMessage interfaces make it possible to distinguish between the parts of the tool output meant for the model (this is the ToolMessage.content) and those parts which are meant for use outside the model (ToolMessage.artifact).
Please note that only raising a ToolException won't be effective. You need to first set the handle_tool_error of the tool because its default value is False.
A simple strategy is to throw a ToolException from inside the tool and specify an error handler using handle_tool_error.
Create toolMultifix
When the error handler is specified, the exception will be caught and the error handler will decide which output to return from the tool.
Create toolqctp toolpost
So even if you only provide an sync implementation of a tool, you could still use the ainvoke interface, but there are some important things to know:
Creating tools from functions may be sufficient for most use cases, and can be done via a simple @tool decorator. If more configuration is needed-- e.g., specification of both sync and async implementations-- one can also use the StructuredTool.from_function class method.
By default, @tool(parse_docstring=True) will raise ValueError if the docstring does not parse correctly. See API Reference for detail and examples.
You can define a custom tool by sub-classing from BaseTool. This provides maximal control over the tool definition, but requires writing more code.
Sometimes there are artifacts of a tool's execution that we want to make accessible to downstream components in our chain or agent, but that we don't want to expose to the model itself. For example if a tool returns custom objects like Documents, we may want to pass some view or metadata about this output to the model without passing the raw output to the model. At the same time, we may want to be able to access this full output elsewhere, for example in downstream tools.
ToolCrate
Create toolholder
If you're using tools with agents, you will likely need an error handling strategy, so the agent can recover from the error and continue execution.
Multifixtoolpost size A
This @tool decorator is the simplest way to define a custom tool. The decorator uses the function name as the tool name by default, but this can be overridden by passing a string as the first argument. Additionally, the decorator will use the function's docstring as the tool's description - so a docstring MUST be provided.
LangChain Runnables that accept string or dict input can be converted to tools using the as_tool method, which allows for the specification of names, descriptions, and additional schema information for arguments.
If we want our tool to distinguish between message content and other artifacts, we need to specify response_format="content_and_artifact" when defining our tool and make sure that we return a tuple of (content, artifact):
Create toolqctp
When constructing an agent, you will need to provide it with a list of Tools that it can use. Besides the actual function that is called, the Tool consists of several components:
@tool can optionally parse Google Style docstrings and associate the docstring components (such as arg descriptions) to the relevant parts of the tool schema. To toggle this behavior, specify parse_docstring:
Create toolapp
You can set handle_tool_error to True, a string value, or a function. If it's a function, the function should take a ToolException as a parameter and return a value.
The StructuredTool.from_function class method provides a bit more configurability than the @tool decorator, without requiring much additional code.
If we invoke our tool with a ToolCall (like the ones generated by tool-calling models), we'll get back a ToolMessage that contains both the content and artifact generated by the Tool: