Skip to main content
Anthropic’s web search tool allows Claude to search the web and incorporate real-time information into responses.
final agent = Agent(
  'anthropic',
  chatModelOptions: const AnthropicChatOptions(
    serverSideTools: {AnthropicServerSideTool.webSearch},
  ),
);

Usage

await for (final chunk in agent.sendStream(
  'Search the web for the three most recent announcements '
  'about the Dart programming language and summarize them.',
)) {
  stdout.write(chunk.output);
}
The model automatically decides when to search based on the query. Search results are incorporated directly into the response with citations.

Streaming Metadata

Web search events stream through metadata['web_search']:
await for (final chunk in agent.sendStream(prompt)) {
  stdout.write(chunk.output);

  final events = chunk.metadata['web_search'] as List?;
  if (events != null) {
    for (final event in events) {
      stdout.writeln('[search] ${event['type']}');
    }
  }
}

Example