Build agents and workflows
Use ParticleDB for an agent’s records, retrieved context and execution state. The examples here describe application-managed workflows. They do not require a built-in agent scheduler.
Prepare context
Section titled “Prepare context”Retrieve relevant records with search and memory. Scope data access to the authenticated user or account, and pass only the context required by the next step.
Store execution state
Section titled “Store execution state”CREATE TABLE agent_runs ( id BIGINT PRIMARY KEY, status TEXT NOT NULL, attempts BIGINT NOT NULL, result TEXT);INSERT INTO agent_runs VALUES (1, 'pending', 0, NULL);Record a completed step
Section titled “Record a completed step”After your worker finishes the work, record its result in a transaction:
BEGIN;UPDATE agent_runsSET status = 'completed', attempts = attempts + 1, result = 'reviewed'WHERE id = 1;COMMIT;SELECT status, attempts, result FROM agent_runs WHERE id = 1;The result is completed, one attempt and reviewed.
Handle retries
Section titled “Handle retries”Give each logical action a stable identifier. Retry database transactions after a retryable conflict. For external actions, use the external system’s idempotency support or record enough information to reconcile the result before trying again.
Database recovery does not guarantee exactly-once delivery of a payment, message or model request. Workers must handle the gap between an external response and a database commit.
Put reusable logic in Particles
Section titled “Put reusable logic in Particles”Use Particles for supported scoring, transformation and computation. The availability page explains which execution models are supported.