Skip to content

Interaction Layer and Active Tasks Playbook

Languages: English · 中文

When an agent task takes time, users do not only need the final answer. They need to know what is happening, why the system is waiting, and what they can do next. When the system starts work proactively, the trigger also needs its own owner.

Separate Three Event Types

Event typeUsed byShould contain
Product eventUI, IM, customer-facing serviceStable business status, stage, summary, artifact refs
TriggerFlow signalWorkflow controlInternal event names and payloads that affect flow
RuntimeEventObservability / DevTools / logsDiagnostic facts about request, action, environment, flow

Do not make frontend code depend on raw parser paths, chunk names, or RuntimeEvent payloads. Map runtime facts into product events first.

Minimal Output Layer

text
AgentExecution / TriggerFlow
  -> runtime stream item
  -> service projection
  -> product event
  -> SSE / WebSocket / IM / notification

The service projection is where internal fields become stable UI contracts.

Product Event Shape

FieldPurpose
event_typeFrontend or IM gateway chooses rendering
task_idBusiness task ownership
execution_idCurrent run ownership for recovery and debugging
stageUser-readable stage
statusrunning, waiting, ready, failed, etc.
summaryShort text the user can understand
artifact_refWorkspace report, screenshot, form, or log reference

Channel Selection

ChannelFitsNotes
HTTP POSTShort task, final result onlyReturn structured data or close snapshot
SSEOne-way process stream, report generation, ticket progress, long responseServer owns stream close; clients ignore unknown events
WebSocketMulti-turn chat or repeated inputs in one connectionNeeds session ownership and disconnect recovery
IM gatewayEnterprise chat, email, notification systemsIM is interaction layer, not workflow owner
Worker / QueueProactive tasks, batch jobs, async long workApplication persists task, idempotency, and scheduling state

Active Task Boundary

A proactive trigger belongs outside the HTTP request lifecycle:

text
scheduler / webhook / queue
  -> create business task record
  -> start Agently execution
  -> stream product events
  -> persist final state

The scheduler should not hide prompt logic, and the Agently execution should not own the timer.

Scheduled Daily Report Example

  1. Scheduler creates a daily_report task with topic, tenant, and due time.
  2. Worker starts a TriggerFlow execution.
  3. Flow emits product events: outline_ready, source_selected, section_ready, report_ready.
  4. Search/browse/source summaries are stored as Workspace records.
  5. Final Markdown/PDF artifact ref is persisted to the business task.
  6. IM or email sends a link to the artifact.

Waiting and Resume

When human approval is required:

  • TriggerFlow uses pause_for(...).
  • Product event exposes approval_required.
  • UI/IM shows artifact summary and approval actions.
  • Resume endpoint validates user permission and idempotency.
  • Execution continues with the resume payload.

Avoid

MisuseBetter shape
Long tasks only show the final resultEmit stage-level product events through runtime stream
Frontend binds to instant parser paths as a long-term protocolMap them into stable service/product events
Event Center drives product UIEvent Center is observation; UI consumes product events
Scheduler lives inside HTTP request handlerScheduler / queue / worker owns proactive triggers
No task_id / execution_id / trace_idThe task cannot be recovered or debugged
IM bot decides workflow path by itselfIM is interaction layer; workflow is driven by Agently execution and app state

Launch Check

CheckPassing standard
Process eventsUsers can see key stages, waits, and failures
Final stateDurable state comes from data / snapshot / Workspace artifact, not temporary patches
Channel separationUI stream, TriggerFlow signal, and Event Center are not mixed
Proactive triggerScheduler / webhook / queue is separate from API request handling
Resume entryInterrupt id, execution id, resume payload, and idempotency key are traceable
Notification strategyThe task can recover after IM/WebSocket/SSE disconnect
ObservabilityRuntimeEvent / DevTools / trace can locate model, Action, flow, or environment problems

Continue Reading