Skip to content

feat(provider/anthropic): Anthropic web search #6237

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

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

axel-rock
Copy link
Contributor

@axel-rock axel-rock commented May 8, 2025

Background

Anthropic just announced the availability of web search in their API. This feature is really exciting to me.

Summary

Added support for what is presented in the documentation.

Verification

I currently just got it to work:

const gen = await generateText({
	model,
	prompt,
	tools: {
		web_search: anthropic.tools.webSearch_20250305({
			max_uses: 2,
		}),
	},
	maxSteps: 3
})

Tasks

  • Get the basic feature to work
  • Make sure the output from the server is correctly mapped in the SDK response
  • Check types and schema validations (some have been done very quickly to get it to work late at night)
  • Tests have been added / updated (for bug fixes / features)
  • Documentation has been added / updated (for bug fixes / features)
  • A patch changeset for relevant packages has been added (for bug fixes / features - run pnpm changeset in the project root)
  • Formatting issues have been fixed (run pnpm prettier-fix in the project root)

Disclaimer

I've only contributed to documentation before, I hope this will help. And I'd also understand if it doesn't, I really don't mind if this gets closed for any reason.

I don't know how to write tests my self, must admit these have been wrote by Gemini.

@axel-rock
Copy link
Contributor Author

I am not sure how to run the documentation website locally, and check how this table looks with an extra column added to it:

image

@axel-rock axel-rock marked this pull request as ready for review May 8, 2025 15:44
@samdenty
Copy link
Member

samdenty commented May 8, 2025

I am not sure how to run the documentation website locally, and check how this table looks with an extra column added to it:

I think we have another repo that we have to sync it to, I'm not too sure on the process here cc @lgrammel

// New type for web search tool result errors
export interface AnthropicWebSearchToolResultErrorContent {
type: 'web_search_tool_result_error';
error_code: string; // e.g., 'max_uses_exceeded', 'too_many_requests', etc.
Copy link
Member

Choose a reason for hiding this comment

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

@samdenty
Copy link
Member

samdenty commented May 8, 2025

also I know we like to add examples to make it easy to try out something (helps with future testing as well), maybe it would make sense to add one in examples/ai-core?

@axel-rock
Copy link
Contributor Author

also I know we like to add examples to make it easy to try out something (helps with future testing as well), maybe it would make sense to add one in examples/ai-core?

Thank you for your quick feedback, I'll look into into it tomorrow

@axel-rock
Copy link
Contributor Author

also I know we like to add examples to make it easy to try out something (helps with future testing as well), maybe it would make sense to add one in examples/ai-core?

I added that part, it works pnpm tsx src/tools/anthropic-web-search.ts from the examples folder

@axel-rock axel-rock requested a review from samdenty May 13, 2025 11:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants