From 0c04018bb34e642cfc54a2f052315e38d4a8e338 Mon Sep 17 00:00:00 2001 From: Danny Avila Date: Tue, 3 Sep 2024 22:52:08 -0400 Subject: [PATCH] fix(Anthropic): messages.X.content.Y.tool_use.input: Input should be a valid dictionary --- api/app/clients/prompts/formatMessages.js | 10 +++++++++- api/server/controllers/agents/client.js | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/api/app/clients/prompts/formatMessages.js b/api/app/clients/prompts/formatMessages.js index 87d5ba7a15..a5ed05c645 100644 --- a/api/app/clients/prompts/formatMessages.js +++ b/api/app/clients/prompts/formatMessages.js @@ -170,7 +170,15 @@ const formatAgentMessages = (payload) => { } // Note: `tool_calls` list is defined when constructed by `AIMessage` class, and outputs should be excluded from it - const { output, ...tool_call } = part.tool_call; + const { output, args: _args, ...tool_call } = part.tool_call; + // TODO: investigate; args as dictionary may need to be provider-or-tool-specific + let args = _args; + try { + args = JSON.parse(args); + } catch (e) { + // failed to parse, leave as is + } + tool_call.args = args; lastAIMessage.tool_calls.push(tool_call); // Add the corresponding ToolMessage diff --git a/api/server/controllers/agents/client.js b/api/server/controllers/agents/client.js index fd091ead20..c88dadd9e1 100644 --- a/api/server/controllers/agents/client.js +++ b/api/server/controllers/agents/client.js @@ -464,7 +464,7 @@ class AgentClient extends BaseClient { ); }, }); - logger.info(this.contentParts, { depth: null }); + logger.debug(this.contentParts, { depth: null }); } catch (err) { if (!abortController.signal.aborted) { logger.error(