diff --git a/langchain-core/src/messages/tests/base_message.test.ts b/langchain-core/src/messages/tests/base_message.test.ts index fb6f3797f31f..b2b6bd679bd9 100644 --- a/langchain-core/src/messages/tests/base_message.test.ts +++ b/langchain-core/src/messages/tests/base_message.test.ts @@ -133,43 +133,43 @@ test("Deserialisation and serialisation of messages with ID", async () => { expect(deserialized.id).toBe(messageId); }); -test("Can concat raw_output (string) of ToolMessageChunk", () => { +test("Can concat artifact (string) of ToolMessageChunk", () => { const rawOutputOne = "Hello"; const rawOutputTwo = " world"; const chunk1 = new ToolMessageChunk({ content: "Hello", tool_call_id: "1", - raw_output: rawOutputOne, + artifact: rawOutputOne, }); const chunk2 = new ToolMessageChunk({ content: " world", tool_call_id: "1", - raw_output: rawOutputTwo, + artifact: rawOutputTwo, }); const concated = chunk1.concat(chunk2); - expect(concated.raw_output).toBe(`${rawOutputOne}${rawOutputTwo}`); + expect(concated.artifact).toBe(`${rawOutputOne}${rawOutputTwo}`); }); -test("Can concat raw_output (array) of ToolMessageChunk", () => { +test("Can concat artifact (array) of ToolMessageChunk", () => { const rawOutputOne = ["Hello", " world"]; const rawOutputTwo = ["!!"]; const chunk1 = new ToolMessageChunk({ content: "Hello", tool_call_id: "1", - raw_output: rawOutputOne, + artifact: rawOutputOne, }); const chunk2 = new ToolMessageChunk({ content: " world", tool_call_id: "1", - raw_output: rawOutputTwo, + artifact: rawOutputTwo, }); const concated = chunk1.concat(chunk2); - expect(concated.raw_output).toEqual(["Hello", " world", "!!"]); + expect(concated.artifact).toEqual(["Hello", " world", "!!"]); }); -test("Can concat raw_output (object) of ToolMessageChunk", () => { +test("Can concat artifact (object) of ToolMessageChunk", () => { const rawOutputOne = { foo: "bar", }; @@ -179,16 +179,16 @@ test("Can concat raw_output (object) of ToolMessageChunk", () => { const chunk1 = new ToolMessageChunk({ content: "Hello", tool_call_id: "1", - raw_output: rawOutputOne, + artifact: rawOutputOne, }); const chunk2 = new ToolMessageChunk({ content: " world", tool_call_id: "1", - raw_output: rawOutputTwo, + artifact: rawOutputTwo, }); const concated = chunk1.concat(chunk2); - expect(concated.raw_output).toEqual({ + expect(concated.artifact).toEqual({ foo: "bar", bar: "baz", }); diff --git a/langchain-core/src/messages/tool.ts b/langchain-core/src/messages/tool.ts index 996e2cdba8cc..4567bd91e633 100644 --- a/langchain-core/src/messages/tool.ts +++ b/langchain-core/src/messages/tool.ts @@ -10,13 +10,14 @@ import { export interface ToolMessageFieldsWithToolCallId extends BaseMessageFields { /** - * The raw output of the tool. + * Artifact of the Tool execution which is not meant to be sent to the model. * - * **Not part of the payload sent to the model.** Should only be specified if it is - * different from the message content, i.e. if only a subset of the full tool output - * is being passed as message content. + * Should only be specified if it is different from the message content, e.g. if only + * a subset of the full tool output is being passed as message content but the full + * output is needed in other parts of the code. */ - raw_output?: unknown; + // eslint-disable-next-line @typescript-eslint/no-explicit-any + artifact?: any; tool_call_id: string; } @@ -36,13 +37,14 @@ export class ToolMessage extends BaseMessage { tool_call_id: string; /** - * The raw output of the tool. + * Artifact of the Tool execution which is not meant to be sent to the model. * - * **Not part of the payload sent to the model.** Should only be specified if it is - * different from the message content, i.e. if only a subset of the full tool output - * is being passed as message content. + * Should only be specified if it is different from the message content, e.g. if only + * a subset of the full tool output is being passed as message content but the full + * output is needed in other parts of the code. */ - raw_output?: unknown; + // eslint-disable-next-line @typescript-eslint/no-explicit-any + artifact?: any; constructor(fields: ToolMessageFieldsWithToolCallId); @@ -63,7 +65,7 @@ export class ToolMessage extends BaseMessage { } super(fields); this.tool_call_id = fields.tool_call_id; - this.raw_output = fields.raw_output; + this.artifact = fields.artifact; } _getType(): MessageType { @@ -83,18 +85,19 @@ export class ToolMessageChunk extends BaseMessageChunk { tool_call_id: string; /** - * The raw output of the tool. + * Artifact of the Tool execution which is not meant to be sent to the model. * - * **Not part of the payload sent to the model.** Should only be specified if it is - * different from the message content, i.e. if only a subset of the full tool output - * is being passed as message content. + * Should only be specified if it is different from the message content, e.g. if only + * a subset of the full tool output is being passed as message content but the full + * output is needed in other parts of the code. */ - raw_output?: unknown; + // eslint-disable-next-line @typescript-eslint/no-explicit-any + artifact?: any; constructor(fields: ToolMessageFieldsWithToolCallId) { super(fields); this.tool_call_id = fields.tool_call_id; - this.raw_output = fields.raw_output; + this.artifact = fields.artifact; } static lc_name() { @@ -116,7 +119,7 @@ export class ToolMessageChunk extends BaseMessageChunk { this.response_metadata, chunk.response_metadata ), - raw_output: _mergeObj(this.raw_output, chunk.raw_output), + artifact: _mergeObj(this.artifact, chunk.artifact), tool_call_id: this.tool_call_id, id: this.id ?? chunk.id, });