Skip to content

Commit

Permalink
core[patch]: Rename raw_output to artifact (#6055)
Browse files Browse the repository at this point in the history
  • Loading branch information
bracesproul authored Jul 13, 2024
1 parent 2eb699d commit da9b1d9
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 30 deletions.
24 changes: 12 additions & 12 deletions langchain-core/src/messages/tests/base_message.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
};
Expand All @@ -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",
});
Expand Down
39 changes: 21 additions & 18 deletions langchain-core/src/messages/tool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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);

Expand All @@ -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 {
Expand All @@ -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() {
Expand All @@ -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,
});
Expand Down

0 comments on commit da9b1d9

Please sign in to comment.