Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: No tools_call in message in langgraph with anthropic #7284

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
77 changes: 39 additions & 38 deletions langchain/src/output_parsers/openai_tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,47 +54,48 @@ export class JsonOutputToolsParser extends BaseLLMOutputParser<
* @param generations The output of the LLM to parse.
* @returns A JSON object representation of the function call or its arguments.
*/
async parseResult(generations: ChatGeneration[]): Promise<ParsedToolCall[]> {
const toolCalls = generations[0].message.additional_kwargs.tool_calls;
if (!toolCalls) {
throw new Error(
`No tools_call in message ${JSON.stringify(generations)}`
);
}
const clonedToolCalls = JSON.parse(JSON.stringify(toolCalls));
const parsedToolCalls = [];
for (const toolCall of clonedToolCalls) {
if (toolCall.function !== undefined) {
// @ts-expect-error name and arguemnts are defined by Object.defineProperty
const parsedToolCall: ParsedToolCall = {
type: toolCall.function.name,
args: JSON.parse(toolCall.function.arguments),
};

if (this.returnId) {
parsedToolCall.id = toolCall.id;
async parseResult(generations) {
const toolCalls = generations[0].message.additional_kwargs.tool_calls || generations[0].message.tool_calls
if (!toolCalls) {
throw new Error(`No tools_call in message ${JSON.stringify(generations)}`);
}
const clonedToolCalls = JSON.parse(JSON.stringify(toolCalls));
const parsedToolCalls = [];
for (const toolCall of clonedToolCalls) {
let parsedToolCall = null
if (toolCall.function !== undefined) {
// @ts-expect-error name and arguemnts are defined by Object.defineProperty
parsedToolCall = {
type: toolCall.function.name,
args: JSON.parse(toolCall.function.arguments),
};
if (this.returnId) {
parsedToolCall.id = toolCall.id;
}
}else {
parsedToolCall = {
type: toolCall.name,
args: toolCall.args,
id: toolCall.id
};
}
// backward-compatibility with previous
// versions of Langchain JS, which uses `name` and `arguments`
Object.defineProperty(parsedToolCall, "name", {
get() {
return this.type;
},
});
Object.defineProperty(parsedToolCall, "arguments", {
get() {
return this.args;
},
});
parsedToolCalls.push(parsedToolCall);
}

// backward-compatibility with previous
// versions of Langchain JS, which uses `name` and `arguments`
Object.defineProperty(parsedToolCall, "name", {
get() {
return this.type;
},
});

Object.defineProperty(parsedToolCall, "arguments", {
get() {
return this.args;
},
});

parsedToolCalls.push(parsedToolCall);
}
return parsedToolCalls;
}
return parsedToolCalls;
}
}

export type JsonOutputKeyToolsParserParams = {
keyName: string;
Expand Down