mini007_event: Streaming Events

mini007_eventR Documentation

Streaming Events

Description

'Agent$invoke()', 'Workflow$run()' / '$resume()', 'WorkflowAgent$invoke()', 'LeadAgent$invoke()' / '$resume()' and 'RouterAgent$invoke()' accept stream = TRUE and an optional on_event callback. While streaming, every unit of progress is delivered to the callback as a 'mini007_event' - a list with a 'type' discriminator - as soon as it happens, instead of only returning the final result at the end. The return value of the call is unchanged: the same final response you get without streaming.

Events from nested components are forwarded to the outermost callback, so a single 'on_event' passed to a 'LeadAgent' also receives the token deltas of every 'Agent' it delegates to, including Agents running inside a 'Workflow' wrapped with $as_agent().

Event fields

'type'

'[character(1)]' The event type (see below).

'source'

'[character(1)]' Name of the Agent, Workflow or LeadAgent that emitted the event.

'text'

'[character(1) | NULL]' Text payload: a text delta for '"text_delta"' (see below), the full response or output for the '*_completed' and '*_output' events.

'data'

'[list]' Type-specific details (e.g. 'tool_name', 'arguments', 'from_cache', 'pending'). Events are tagged with where they happened: 'station' and 'step' inside a Workflow, 'task' (the plan index) and 'agent' inside a LeadAgent. Tags from an inner component are kept, so a delta from an Agent in a Workflow wrapped as a LeadAgent sub-agent carries all four.

'timestamp'

'[POSIXct]' When the event was emitted.

Text deltas

An LLM produces its answer a few characters at a time. While streaming, each new fragment is delivered as soon as it is generated, in a '"text_delta"' event: a delta is the text that is new since the previous event, never the whole answer. Pasting the 'text' of all deltas together, in order, gives the full response. '"thinking_delta"' events work the same way for the reasoning of reasoning models.

Event types

Agent

'"agent_started"', '"text_delta"', '"thinking_delta"', '"tool_call"', '"tool_result"', '"agent_completed"'.

Agent$plan_and_execute()

'"plan_created"', then for each step ‘"step_started"', the step’s Agent events (tagged with 'step') and ‘"step_completed"', then '"answer_started"', the answer’s Agent events and '"plan_completed"'.

Workflow

'"workflow_started"', '"station_started"', '"station_retry"', '"station_fallback"', '"station_completed"', '"hitl_request"', '"workflow_output"', '"workflow_failed"'.

LeadAgent

'"plan_created"', '"task_started"', '"task_completed"', '"task_validated"' and '"task_reassigned"' (with $set_validation()), '"hitl_request"', '"lead_output"'.

RouterAgent

‘"route_selected"', then the chosen agent’s events (tagged with 'agent'), then '"router_output"'.

Cancellation

Raising an error from inside 'on_event' (e.g. stop("cancelled")) stops the run immediately. It is re-raised as a condition of class 'mini007_stream_cancelled', which Workflow retries and fallbacks never swallow, and the Agent's message history is kept in sync with whatever the LLM produced before the cancellation.

Parallel execution

Stations in a parallel group run in separate 'mirai' daemon processes, so their token deltas cannot be streamed back. They still emit '"station_started"' and '"station_completed"' events from the main process.

Examples

## Not run: 
agent <- Agent$new(
  name = "poet",
  instruction = "You write short poems.",
  llm_object = ellmer::chat("openai/gpt-4.1-mini", echo = "none")
)

# Print tokens to the console as they arrive
agent$invoke("A haiku about R", stream = TRUE)

# Handle events yourself
agent$invoke("A haiku about R", on_event = function(event) {
  if (event$type == "text_delta") cat(event$text)
})

## End(Not run)


mini007 documentation built on Dec. 3, 2026, 5:10 p.m.