Skip to content

Commit

Permalink
core[patch]: Populate tool name in ToolMessage return value (#6066)
Browse files Browse the repository at this point in the history
* core[patch]: Populate tool name in ToolMessage return value

* cr
  • Loading branch information
bracesproul authored Jul 15, 2024
1 parent 4644dd3 commit 7e47915
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
4 changes: 4 additions & 0 deletions langchain-core/src/tools/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ export abstract class StructuredTool<
content,
artifact,
toolCallId,
name: this.name,
});
await runManager?.handleToolEnd(formattedOutput);
return formattedOutput;
Expand Down Expand Up @@ -528,6 +529,7 @@ function _isToolCall(toolCall?: unknown): toolCall is ToolCall {

function _formatToolOutput(params: {
content: unknown;
name: string;
artifact?: unknown;
toolCallId?: string;
}): ToolReturnType {
Expand All @@ -542,12 +544,14 @@ function _formatToolOutput(params: {
content,
artifact,
tool_call_id: toolCallId,
name: params.name,
});
} else {
return new ToolMessage({
content: _stringify(content),
artifact,
tool_call_id: toolCallId,
name: params.name,
});
}
} else {
Expand Down
1 change: 1 addition & 0 deletions langchain-core/src/tools/tests/tools.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,5 @@ test("Returns tool message if responseFormat is content_and_artifact and returns
expect(toolResult).toBeInstanceOf(ToolMessage);
expect(toolResult.content).toBe("msg_content");
expect(toolResult.artifact).toEqual({ location: "San Francisco" });
expect(toolResult.name).toBe("weather");
});

0 comments on commit 7e47915

Please sign in to comment.