danny-avila / LibreChat

Enhanced ChatGPT Clone: Features Anthropic, AWS, OpenAI, Assistants API, Azure, Groq, o1, GPT-4o, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, langchain, DALL-E-3, ChatGPT Plugins, OpenAI Functions, Secure Multi-User System, Presets, completely open-source for self-hosting. Actively in public development.
https://librechat.ai/
MIT License
19.44k stars 3.24k forks source link

[Bug]: Tool input parsing error with Claude via AWS Bedrock in Agents endpoint #4636

Closed ogipogi closed 3 weeks ago

ogipogi commented 3 weeks ago

What happened?

When using the Agents endpoint with Claude via AWS Bedrock and a custom RAG tool, the tool input parsing fails. The error occurs because the input is a plain string, not a JSON object as expected.

Root Cause: The JSON.parse(args) is failing because the string "How to write a unit test in XY? Include best practices and examples." is not a valid JSON string.

https://github.com/danny-avila/LibreChat/blob/main/api/app/clients/prompts/formatMessages.js#L191-L195

Possible Fix: Modify the code to handle different input types:

let args = _args;
if (typeof _args === 'string') {
  args = { input: _args };
} else {
  try {
    args = JSON.parse(_args);
  } catch (e) {
    args = { input: _args };
  }
}

If you want, I can create a PR?

Thanks for checking.

Steps to Reproduce

  1. Set up LibreChat with Agents endpoint using Claude via AWS Bedrock
  2. Attach a custom RAG tool to the agent
  3. Use the RAG tool during a conversation a) How implement a unit test in [PRODUCT-NAME] b) And how write a unit test for a resolver in [PRODUCT-NAME]?
  4. Observe the error in the logs

What browsers are you seeing the problem on?

Chrome

Relevant log output

SyntaxError: Unexpected token H in JSON at position 0
at JSON.parse (<anonymous>)
at formatAgentMessages (api/app/clients/prompts/formatMessages.js:192:23)
at AgentClient.chatCompletion (api/server/controllers/agents/client.js:482:24)

Screenshots

No response

Code of Conduct