Work that moves between agents and waits for days
A journey is a state machine with one id from request to outcome. Each step can start an agent, limit its tools, wait for an event from your systems and time out, so a refill that needs a visit can wait two weeks and pick up where it stopped.
{"name": "Refill that needs a visit","definition": {"initial": "REFILL_REQUESTED","states": {"REFILL_REQUESTED": {"agentId": "agt_01J9Z8Q4M3T5V7X9B1C3D5PHRM","prompt": "Refill the member's prescription.","tools": ["check_refill","submit_refill"],"on": {"appointment.required": "VISIT_BOOKING","refill.submitted": "COMPLETED"}},"VISIT_BOOKING": {"agentId": "agt_01J9Z8Q4M3T5V7X9B1C3D5CARE","prompt": "The prescriber needs to see the member. Book the visit and a ride.","tools": ["book_visit"],"on": {"visit.booked": "WAITING_FOR_VISIT"}},"WAITING_FOR_VISIT": {"on": {"visit.completed": "REFILL_RESUMED","timeout": "NO_VISIT"},"timeoutHours": 336},"REFILL_RESUMED": {"agentId": "agt_01J9Z8Q4M3T5V7X9B1C3D5PHRM","prompt": "The visit is done. Resume the refill.","tools": ["check_refill","submit_refill"],"on": {"refill.submitted": "COMPLETED"}},"COMPLETED": {"terminal": true},"NO_VISIT": {"terminal": true,"outcome": "failed"}}}}
Your systems and the agents move it forward
Your systems send events to the journey, and agents send them with the journey_event tool, limited to the events the current state accepts. An event's data is merged into the journey's context and recorded in its history. An event the state does not accept returns 409 with the events it does accept.
- Retries
- A retried event with the same Idempotency-Key replays the first response instead of moving the journey twice.
const journey = await evry.journeys.start({definitionId: "jdf_...",subject: "member_8812",grantId: "grt_...",context: { rx: "RX1" },});// Days later, your scheduling system reports the visit happened.await evry.journeys.events.create({ journeyId: journey.id, type: "visit.completed", data: { visitId: "v1" } },{ idempotencyKey: `visit-${journey.id}` });
How it works
States, events and timeouts in one document
A definition has an initial state and its states. A state can name an agent and the prompt it gets on entry, the only tools it may use there, the events that move it on and how many hours to wait before timeout fires. Terminal states end the journey as completed or failed. A new version applies to new journeys, and running ones keep theirs.
A waiting journey holds no run and no worker
A state with timeoutHours sets a deadline, and a periodic sweep sends timeout to journeys past it, which follows the definition like any other event. While a journey waits nothing runs, so it can wait for a visit, a document or a person as long as the definition says.
Each step gets only the tools it needs
When a state lists tools, any other tool the agent calls returns TOOL_NOT_ALLOWED_IN_STATE instead of running, and the grant and policy still decide the ones that are allowed. An agent keeps one session across the states of a journey, so it sees its earlier conversation when it resumes.
The grant is checked again at every step
A journey started with a grant is checked when it starts and on every state entry that starts an agent. If the grant was revoked or expired, the journey fails with that reason instead of starting the next run. Each move emits journey.transitioned and writes an audit record, and the end emits journey.completed.
The specifics
Through the API or the TypeScript SDK.
States
Outcomes
Channel
Stopping
Events
Scopes
Bring EvryAi to your team
Sign in with your work account and start in a chat, or talk to us about rolling it out across your organization with the controls your admins need.