Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fast-buttons-sip.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"langchain": patch
---

fix(langchain): set name on todoListMiddleware ToolMessages
10 changes: 10 additions & 0 deletions libs/langchain/src/agents/middleware/tests/todoList.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,13 @@ describe("todoListMiddleware", () => {
expect(result.todos).toEqual([
{ content: "Complete the requested task", status: "in_progress" },
]);

const writeTodosToolMessage = result.messages.find(
(msg): msg is ToolMessage =>
ToolMessage.isInstance(msg) && msg.tool_call_id === "call_test123"
);
expect(writeTodosToolMessage).toBeDefined();
expect(writeTodosToolMessage!.name).toBe("write_todos");
});

describe("parallel write_todos detection", () => {
Expand Down Expand Up @@ -224,6 +231,9 @@ describe("todoListMiddleware", () => {
expect(msg2.content).toContain(
"Error: The `write_todos` tool should never be called multiple times in parallel"
);

expect(msg1.name).toBe("write_todos");
expect(msg2.name).toBe("write_todos");
});

it("should reject parallel write_todos calls even when mixed with other tools", async () => {
Expand Down
2 changes: 2 additions & 0 deletions libs/langchain/src/agents/middleware/todoListMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ export function todoListMiddleware(options?: TodoListMiddlewareOptions) {
new ToolMessage({
content: `Updated todo list to ${JSON.stringify(todos)}`,
tool_call_id: config.toolCall?.id as string,
name: "write_todos",
}),
],
},
Expand Down Expand Up @@ -385,6 +386,7 @@ export function todoListMiddleware(options?: TodoListMiddlewareOptions) {
"in parallel. Please call it only once per model invocation to update " +
"the todo list.",
tool_call_id: tc.id as string,
name: "write_todos",
status: "error",
})
);
Expand Down
Loading