Message for passing the result of executing a tool back to a model.
public class ToolMessageMessage for passing the result of executing a tool back to a model.
ToolMessage objects contain the result of a tool invocation. Typically, the result is
encoded inside the content field.
Example: A ToolMessage representing a result of 42 from a tool call with id
from langchain_core.messages import ToolMessage
ToolMessage(content="42", tool_call_id="call_Jja7J89XsjrOLA5r!MEOW!SL")
Example: A ToolMessage where only part of the tool output is sent to the model and the
full output is passed in to artifact.
from langchain_core.messages import ToolMessage
tool_output = {
"stdout": "From the graph we can see that the correlation between "
"x and y is ...",
"stderr": None,
"artifacts": {"type": "image", "base64_data": "/9j/4gIcSU..."},
}
ToolMessage(
content=tool_output["stdout"],
artifact=tool_output,
tool_call_id="call_Jja7J89XsjrOLA5r!MEOW!SL",
)
The tool_call_id field is used to associate the tool call request with the tool call
response. Useful in situations where a chat model is able to request multiple tool calls
in parallel.
unexpectedly missing or null (e.g.
unexpectedly missing or null (e.g.
if the server responded with an unexpected value)..
if the server responded with an unexpected value)..
if the server responded with an unexpected value)..
if the server responded with an unexpected value)..
Returns the raw JSON value of [content].
Returns the raw JSON value of [toolCallId].
Returns the raw JSON value of [id].
Returns the raw JSON value of [name].
Returns the raw JSON value of [status].
Returns the raw JSON value of [type].
Returns a mutable builder for constructing an instance of [ToolMessage].
unexpectedly missing or null (e.g.
unexpectedly missing or null (e.g.
unexpectedly missing or null (e.g.
Alias for calling [content] with
Content.ofUnnamedSchemaWithArrayParent5s(unnamedSchemaWithArrayParent5s)..
unexpectedly missing or null (e.g.
unexpectedly missing or null (e.g.
if the server responded with an unexpected value)..
if the server responded with an unexpected value)..
if the server responded with an unexpected value)..
if the server responded with an unexpected value)..
if the server responded with an unexpected value)..
if the server responded with an unexpected value)..
if the server responded with an unexpected value)..
if the server responded with an unexpected value)..
if the server responded with an unexpected value)..
if the server responded with an unexpected value)..
Returns an immutable instance of [ToolMessage].