304: Ideator/Watcher
- Requires:
Watcher: A stateful "source"
Ideator
that subscribes to changes in aStorage
service. When a change occurs (e.g., a newIdea
version is saved), it initiates a new transaction, typically by invoking aPlan
to process the new data.— Glossary
1. Introduction
This document defines the Watcher Protocol, a critical component for building asynchronous, event-driven workflows within the ecosystem. A Watcher
(also referred to as a Subscriber) is a persistent service that observes a Storage
provider for changes and triggers new processes in response.
It is the primary mechanism for bridging the gap between stateful and stateless services and for handling long-running tasks that cannot be managed in a simple request-response cycle.
2. The Watcher as a "Source" Ideator
In contrast to the Storage
service, which acts as a transactional "sink," a Watcher
is a "source." Its role is not to terminate a transaction, but to initiate a new one.
The typical workflow is as follows:
- An
Idea
is committed toStorage
, completing the initial transaction. - The
Storage
service emits an event notifying subscribers of the change. - A
Watcher
, subscribed to these events, receives the notification. - The
Watcher
initiates a new, independent transaction. This usually involves invoking a 013: Agent/Plan and passing the newIdea
as context, kicking off a new workflow.
3. Handling Asynchronicity and Long-Running Processes
The Watcher
is the key to managing long-running, asynchronous operations gracefully.
Consider a Plan
that involves a step that may take hours or days to complete (e.g., waiting for human input, processing a large dataset). A synchronous Plan
cannot simply await
this result.
Instead, the Plan
can delegate the long-running task to an external service and then terminate. That external service, upon completion, writes its result back to Storage
. A Watcher
, configured to listen for this specific result, can then trigger a new Plan
to continue the workflow.
This pattern allows for highly resilient and scalable processes that are not constrained by the memory or lifespan of any single runtime. It enables true asynchronicity by breaking down a long process into a series of smaller, event-triggered transactions.