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

feat: add tool support for antropic streaming #14758

Merged
merged 5 commits into from
Jan 30, 2025

Conversation

eneufeld
Copy link
Contributor

What it does

This adds tool support to anthropic models when using streaming.

How to test

  • Switch the Universal Agent to use one of anthropics models.
  • Send a prompt but provide it with a tool

Follow-ups

Breaking changes

  • This PR introduces breaking changes and requires careful review. If yes, the breaking changes section in the changelog has been updated.

Attribution

Review checklist

Reminder for reviewers

@JonasHelming
Copy link
Contributor

Tested with 'Coder' and 'claude-3-5-sonnet-latest' on your branch with the following prompt:

'@coder Implement the interface MCPServerManager in the same file (packages/ai-mcp/src/common/mcp-server-manager.ts). Don't ask me anything, jut do it.'

got:
Error in Anthropic streaming: Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"tools.0.input_schema: Field required"}}
at APIError.generate

@eneufeld
Copy link
Contributor Author

hmm, the tool parameters were not extracted. I will debug.

@eneufeld
Copy link
Contributor Author

one tool had no schema defined as it doesn't need parameters, openai accepts undefined in that case, but anthropic doesn't.
Thanks for finding this.

@eneufeld eneufeld force-pushed the pr/anthropic-tools branch 2 times, most recently from b1da705 to 0ebd8be Compare January 24, 2025 14:13
Copy link
Contributor

@JonasHelming JonasHelming left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works very well for me, great work. I have only one comment/question

@@ -75,7 +75,11 @@ export class ToolCallPartRenderer implements ChatResponsePartRenderer<ToolCallCh
let responseContent = response.result;
try {
if (response.result) {
responseContent = JSON.stringify(JSON.parse(response.result), undefined, 2);
let resultObject = response.result;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we do this conversion in the model implementation? Is this a corner case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I found out, MCP tools behave differently to our tools.
Our tools return the result usually as a string. But MCP returns it in the format that Anthropics API expect, which is an object with a content field which can be a string or an array of objects with content.
So the rendering completely exploded for me.
I can move the logic to the backend and make sure that the result written to the tool result object is a string.

@JonasHelming JonasHelming merged commit 08bf866 into eclipse-theia:master Jan 30, 2025
11 checks passed
@github-actions github-actions bot added this to the 1.58.0 milestone Jan 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants