← Back to examples

Agent Loop Execution New

This demo shows agent execution mode with multi-turn loops and tool calling. The agent uses Exa web search to build a travel itinerary across staged iterations.

How it works

Set config.agent with a model, system prompt, and loop config. The widget sends this to the dispatch API and handles agent-specific SSE events: agent_start, agent_turn_delta, tool_* (with optional agentContext), agent_iteration_*, and agent_complete.

// Agent execution configuration { agent: { name: 'Travel Planner Assistant', model: 'mercury-2', systemPrompt: 'You are a travel planning assistant...', tools: { toolIds: ['builtin:exa'] }, loopConfig: { maxTurns: 3 } }, agentOptions: { streamResponse: true, recordMode: 'virtual' } }

Iteration Display

Control how multiple iterations appear in the chat with iterationDisplay:
separate: Each iteration creates its own message bubble.
merged: All iterations stream into a single message.

iterationDisplay: 'separate'

Agent Events

The widget handles these agent-specific SSE events:

agent_start → agent_iteration_start → agent_turn_start → agent_turn_delta (text/thinking) → agent_turn_complete → tool_start/tool_delta/tool_complete (with agentContext) → agent_iteration_complete → agent_complete

Thinking Content

When contentType: 'thinking' is received in agent_turn_delta, it appears as a reasoning bubble (same as extended thinking in flow mode).

Backward Compatible

Agent mode is opt-in. Without config.agent, the widget uses flow dispatch as before. Both modes share the same SSE streaming infrastructure.