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

Using AnthropicAgent : Input should be a valid dictionary #1582

Open
1 of 14 tasks
uncomplexity opened this issue Dec 31, 2024 · 3 comments
Open
1 of 14 tasks

Using AnthropicAgent : Input should be a valid dictionary #1582

uncomplexity opened this issue Dec 31, 2024 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@uncomplexity
Copy link

Describe the bug
A clear and concise description of what the bug is.

BadRequestError: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.3.content.1.tool_use.input: Input should be a valid dictionary"}}
    at APIError.generate (file:///home/user/Documents/v5/server/node_modules/@anthropic-ai/sdk/error.mjs:37:20)
    at Anthropic.makeStatusError (file:///home/user/Documents/v5/server/node_modules/@anthropic-ai/sdk/core.mjs:275:25)
    at Anthropic.makeRequest (file:///home/user/Documents/v5/server/node_modules/@anthropic-ai/sdk/core.mjs:319:30)
    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
    at async Anthropic.chat (file:///home/user/Documents/v5/server/node_modules/@llamaindex/anthropic/dist/index.js:671:30)
    at async Anthropic.withLLMEvent (file:///home/user/Documents/v5/server/node_modules/@llamaindex/core/decorator/dist/index.js:73:26)
    at async defaultTaskHandler (file:///home/user/Documents/v5/server/node_modules/@llamaindex/core/agent/dist/index.js:736:34)
    at async Object.pull (file:///home/user/Documents/v5/server/node_modules/@llamaindex/core/agent/dist/index.js:632:13) {
  status: 400,
  headers: {
    'cf-cache-status': 'DYNAMIC',
    'cf-ray': '8faa38e3589f7be7-HKG',
    connection: 'keep-alive',
    'content-length': '141',
    'content-type': 'application/json',
    date: 'Tue, 31 Dec 2024 12:20:11 GMT',
    'request-id': 'req_01Ec22FucqzGa5zEw2t8BNGg',
    server: 'cloudflare',
    via: '1.1 google',
    'x-robots-tag': 'none',
    'x-should-retry': 'false'
  },
  request_id: 'req_01Ec22FucqzGa5zEw2t8BNGg',
  error: {
    type: 'error',
    error: {
      type: 'invalid_request_error',
      message: 'messages.3.content.1.tool_use.input: Input should be a valid dictionary'
    }
  }
}

To Reproduce
Code to reproduce the behavior:

	const agent = new AnthropicAgent({
		tools,
		llm,
		systemPrompt,
		chatHistory: options.chatHistory || [],
	});

	console.log("Agent processing request:", options.message);
	const response = await agent.chat({
		message: options.message || "",
	});

	console.log("Agent response:", response.message.content);

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: [e.g. macOS, Linux]
  • JS Runtime / Framework / Bundler (select all applicable)
  • Node.js
  • Deno
  • Bun
  • Next.js
  • ESBuild
  • Rollup
  • Webpack
  • Turbopack
  • Vite
  • Waku
  • Edge Runtime
  • AWS Lambda
  • Cloudflare Worker
  • Others (please elaborate on this)
  • Version [e.g. 22]

Additional context
Add any other context about the problem here.

Any idea what's causing this?

Upstream: anthropics/anthropic-sdk-typescript#648

@uncomplexity uncomplexity added the bug Something isn't working label Dec 31, 2024
@uncomplexity
Copy link
Author

When I replace my code with OpenAI and OpenAIAgent gpt-4o it works.

But with Anthropic AnthropicAgent claude-3-5-haiku-latest it doesn't work.

@marcusschiesser marcusschiesser moved this to In Progress in Framework Jan 3, 2025
@marcusschiesser marcusschiesser changed the title Input should be a valid dictionary Using AnthropicAgent : Input should be a valid dictionary Jan 3, 2025
@marcusschiesser marcusschiesser mentioned this issue Jan 3, 2025
18 tasks
@thucpn
Copy link
Collaborator

thucpn commented Jan 3, 2025

Hi @uncomplexity , could you log and share with me the chatHistory and tools used when constructing the AnthropicAgent?

@marcusschiesser marcusschiesser moved this from In Progress to Blocked in Framework Jan 6, 2025
@alexchao
Copy link

alexchao commented Jan 14, 2025

Posted the following in the anthropic-sdk-typescript issue, where they mention this probably being a llamaindex issue.


I'm also seeing this, using Llamaindex's AnthropicAgent. Reproduced with claude-3-5-sonnet-20241022.

Also seeing that it works if I just replace AnthropicAgent with OpenAIAgent.

/project-path/node_modules/@llamaindex/anthropic/node_modules/@anthropic-ai/sdk/error.js:41
            return new BadRequestError(status, error, message, headers);
                   ^

BadRequestError: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.1.content.1.tool_use.input: Input should be a valid dictionary"}}
    at APIError.generate (/project-path/node_modules/@llamaindex/anthropic/node_modules/@anthropic-ai/sdk/error.js:41:20)
    at Anthropic.makeStatusError (/project-path/node_modules/@llamaindex/anthropic/node_modules/@anthropic-ai/sdk/core.js:282:33)
    at Anthropic.makeRequest (/project-path/node_modules/@llamaindex/anthropic/node_modules/@anthropic-ai/sdk/core.js:326:30)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Anthropic.chat (/project-path/node_modules/@llamaindex/anthropic/dist/index.cjs:673:30)
    at async Anthropic.withLLMEvent (/project-path/node_modules/@llamaindex/core/decorator/dist/index.cjs:75:26)
    at async defaultTaskHandler (/project-path/node_modules/@llamaindex/core/agent/dist/index.cjs:738:34)
    at async Object.pull (/project-path/node_modules/@llamaindex/core/agent/dist/index.cjs:634:13) {
  status: 400,
  headers: {
    'cf-cache-status': 'DYNAMIC',
    'cf-ray': '8fb78117fc388f07-TPE',
    connection: 'keep-alive',
    'content-length': '141',
    'content-type': 'application/json',
    date: 'Thu, 02 Jan 2025 03:01:24 GMT',
    'request-id': 'req_014n7yresVz5u9X4Rj8fk77c',
    server: 'cloudflare',
    via: '1.1 google',
    'x-robots-tag': 'none',
    'x-should-retry': 'false'
  },
  request_id: 'req_014n7yresVz5u9X4Rj8fk77c',
  error: {
    type: 'error',
    error: {
      type: 'invalid_request_error',
      message: 'messages.1.content.1.tool_use.input: Input should be a valid dictionary'
    }
  }
}

I set DEBUG=true to enable Anthropic's debug logging. The message object in question looks like the following:

      {
        role: 'assistant',
        content: [
          {
            type: 'text',
            text: "I'll search for scheduled events for January 1st, 2025."
          },
          {
            type: 'tool_use',
            id: 'toolu_01SSC2QZvCKuunqzR6idgb9n',
            name: 'web_search',
            input: `{"query":"scheduled events January 1 2025 New Year's Day"}`
          }
        ]
      }

@marcusschiesser marcusschiesser moved this from Blocked to In Progress in Framework Jan 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: In Progress
Development

No branches or pull requests

3 participants