Skip to main content
Anthropic’s web fetch tool retrieves and processes content from specific URLs. Unlike web search, this tool fetches a known URL directly.

Enable Web Fetch

final agent = Agent(
  'anthropic',
  chatModelOptions: const AnthropicChatOptions(
    serverSideTools: {AnthropicServerSideTool.webFetch},
  ),
);

Usage

await for (final chunk in agent.sendStream(
  'Retrieve https://dart.dev and summarize the main features.',
)) {
  stdout.write(chunk.output);
}

Fetched Documents

Fetched content is attached as DataPart instances on the message history:
final history = <ChatMessage>[];
await for (final chunk in agent.sendStream(prompt)) {
  stdout.write(chunk.output);
  history.addAll(chunk.messages);
}

// Access fetched documents
for (final msg in history) {
  for (final part in msg.parts) {
    if (part is DataPart) {
      print('Fetched: ${part.name} (${part.mimeType})');
      File('output/${part.name}').writeAsBytesSync(part.bytes);
    }
  }
}

Combined Tools

Combine web fetch with other tools for research workflows:
final agent = Agent(
  'anthropic',
  chatModelOptions: const AnthropicChatOptions(
    serverSideTools: {
      AnthropicServerSideTool.webSearch,
      AnthropicServerSideTool.webFetch,
    },
  ),
);

Example