Google’s server-side search tool uses Google Search to ground responses in
real-time web data. Results are automatically woven into the model’s response.
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.
Google Search results include grounding metadata in the response. Access it via
the message metadata to show citations or sources:
Copy
final history = <ChatMessage>[];await for (final chunk in agent.sendStream(prompt)) { stdout.write(chunk.output); history.addAll(chunk.messages);}// Check for grounding metadata in the final messagefor (final msg in history) { final grounding = msg.metadata['grounding']; if (grounding != null) { print('Sources: $grounding'); }}