Skip to content
  • sdk
  • cli
  • dashboard

Give agent modules state, Workflows, and schedules

samva 0.48 and CLI 0.42 let an agent written as code keep data between calls, start Workflows, and run on a cron schedule. Add Samva to Vercel from the dashboard.

An agent you write as code can now remember things, run long work, and act without a message. Upgrade samva to 0.48.0 and @samva/cli to 0.42.0, then publish with samva agents publish. Nothing breaks: a module that uses none of this publishes as before.

What you can do

  • Keep state. Export a State class from agent.ts. ctx.state.agent holds data shared across the agent's conversations, and ctx.state.conversation holds data for one. Both keep their data when you publish new code.
  • Start a Workflow. Register a named Workflow in defineAgent and start it from a tool or handler with ctx.workflows.start. Repeating a start with the same idempotency key returns the same run, and a running Workflow keeps the module version that started it.
  • Run on a schedule. Add a handler to schedules under a five-field cron expression in UTC. It runs from the current published version without a model turn.
schedules: {
  "0 9 * * 1-5": async (ctx) => {
    await ctx.state?.agent.call("increment", 1);
  },
},
  • Resume a conversation after a contact connects. Subscribe to contact.connection_completed under eventTriggers. When a contact finishes the connection the agent asked for, only the conversation and agent that requested it wake.
  • Write email and WhatsApp templates from a brief. Pass channel: "email" or channel: "whatsapp" to suggestions and from-brief, or --channel on samva templates suggest and from-brief. Pass variantOf (--variant-of) to make a template's other-channel version in one call, joined to the source's family. Template suggestions now include channel, and their slug can be null, so handle that before you use it.
  • Add Samva to Vercel. In Integrations → Vercel, choose Add to Vercel to give your projects a mailbox. Samva writes SAMVA_API_KEY and SAMVA_MAILBOX_ID for you, and every message that key sends waits for a person to approve it. API key responses include an optional source naming the Vercel install that created the key.

See keep state across calls for the full ctx.state contract and add Samva to Vercel for the install steps.

Links

Related

All changelog entries