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.
Web search events stream through metadata['web_search']:
Copy
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']}'); } }}