> ## Documentation Index
> Fetch the complete documentation index at: https://docs.checkfu.com/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Base URL: https://api.checkfu.com. Current wire version: `2026-08-31` (`Checkfu-Version: 2026-08-31`).
> Mutating HTTP requests require `Authorization: Bearer $CHECKFU_API_KEY`, `Checkfu-Version: 2026-08-31`, `Content-Type: application/json`, and `Idempotency-Key` on retriable writes. Ordinary API keys are Workspace-bound; do not send a Workspace selector header.
> Core workflow: create an Agent (`POST /v1/agents`) and Environment (`POST /v1/environments`), grant `use_environment` (`POST /v1/permission-assignments`), create a Session (`POST /v1/sessions`), send events (`POST /v1/sessions/{id}/events`), stream progress (`GET /v1/sessions/{id}/events/stream`), and read the input result (`GET /v1/sessions/{id}/inputs/{input_id}/result`).
> Domain model: an Agent is mutable configuration; a Session freezes its AgentVersion and Environment at creation and owns its private workspace and ordered event history. Vault stores secret credentials; Connection links an external account; ActionApproval records human approval before an action runs.
> Capability status combines `audience`, `stability`, `availability`, evaluated prerequisites, and release evidence; check https://docs.checkfu.com/getting-started/status (`GET /v1/support/capabilities`) for live `available` status.

# Write nightly lessons to Memory

> Every night, read the Sessions since the last run, have a Curator Agent find lessons, check they are safe, and write them to a Memory store.

This recipe lets your support Agent learn between Sessions. Every night at 03:00 UTC it reads the support Agent's Sessions it has not processed yet and the current `/lessons.md` from a [Memory store](https://docs.checkfu.com/concepts/memory.md). A Curator Agent returns the updated document, a Model block answers "Are these lessons safe, accurate and free of private data?", and Yes writes the new version.

```text theme={"theme":{"light":"github-light","dark":"github-dark"}}
nightly → recent (Sessions) → current (read /lessons.md) → lessons (Curator Agent)
        → safe (Yes/No) → yes → save (write /lessons.md)
```

The write uses `mode: update` with the `sha256` the read returned, so it never overwrites a version it did not read. When the check says No, the run still ends normally: those Sessions count as processed and their lessons are dropped. Wire the `no` exit to another block if you want to review them.

To retire a document the Curator says no longer holds, add a `forget` boolean to its `output_schema`, an If block after `save` that checks `{{lessons.output.forget}}`, a read of that document, and a remove block with `expected_sha256: "{{<read>.sha256}}"`. Like the write, the remove refuses when someone changed the document after the read. A store that reviews changes can't take a remove yet.

> [!WARNING]
>
> The Checkfu CLI and TypeScript SDK are private-alpha artifacts with no self-service public installation channel.
> Part of this flow is behind a rollout fence; a deployment that has not enabled it refuses the request rather than running it.
> Confirm [capability status](https://docs.checkfu.com/getting-started/status.md) before making availability part of your application's contract.

## Before you start

You need:

* An API key with the `admin` or `root` role in `CHECKFU_API_KEY`.
* A service account for the Automation to run as (`SUPPORT_BOT`) and the person who authors it (`AUTHOR`). An API key is not a person, so a create through an API key names the author.
* The support Agent whose Sessions are read (`SUPPORT_AGENT`) and the Curator Agent (`CURATOR_AGENT`).
* The Memory store (`SUPPORT_MEMORY`, a `memstore_…`) and the [Environment](https://docs.checkfu.com/concepts/work-environments.md) the Curator runs in (`ENVIRONMENT`). When the Workspace has exactly one, delete the `environment_id` line and leave out `ENVIRONMENT`.
* A model routing profile with the key `fast-judge`, or change `route.profile` to one you have.

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
export SUPPORT_BOT=prin_0123456789abcdef0123456789abcdef
export AUTHOR=prin_fedcba9876543210fedcba9876543210
export SUPPORT_AGENT=agent_0123456789abcdef0123456789abcdef
export CURATOR_AGENT=agent_fedcba9876543210fedcba9876543210
export SUPPORT_MEMORY=memstore_0123456789abcdef0123456789abcdef
export ENVIRONMENT=env_0123456789abcdef0123456789abcdef
```

Create `/lessons.md` in the store once. It can be empty:

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
curl --request POST https://api.checkfu.com/v1/memory_stores/$SUPPORT_MEMORY/memories \
  --header "Authorization: Bearer $CHECKFU_API_KEY" \
  --header "Checkfu-Version: 2026-08-31" \
  --header "Idempotency-Key: $(uuidgen)" \
  --header "Content-Type: application/json" \
  --data '{ "path": "/lessons.md", "content": "" }'
```

The CLI examples use [CLI access](https://docs.checkfu.com/getting-started/cli-access.md) and the TypeScript examples use the [TypeScript SDK](https://docs.checkfu.com/reference/typescript-sdk.md).

## 1. Create the draft

Save the recipe as `dreaming.yaml`. It is the published [`dreaming.yaml`](https://docs.checkfu.com/automation-recipes/dreaming.yaml) with `created_by_principal_id` added:

```yaml dreaming.yaml theme={"theme":{"light":"github-light","dark":"github-dark"}}
# yaml-language-server: $schema=https://docs.checkfu.com/openapi.json#/components/schemas/CreateBlockAutomation
name: Nightly lessons for support
runs_as: "${SUPPORT_BOT}"
environment_id: "${ENVIRONMENT}"
created_by_principal_id: "${AUTHOR}"
blocks:
  - id: nightly
    type: trigger
    trigger: { type: schedule, cron: "0 3 * * *", timezone: UTC }
  - id: recent
    type: resource
    resource: { type: sessions, agent: "${SUPPORT_AGENT}", limit: 50 }
  - id: current
    type: resource
    resource: { type: memory_store, id: "${SUPPORT_MEMORY}", action: read, path: /lessons.md }
  - id: lessons
    type: agent
    agent: "${CURATOR_AGENT}"
    prompt: "Current lessons: {{current.content}} Add durable new lessons from these Sessions and return the full updated document: {{recent.sessions}}"
    output_schema:
      { type: object, properties: { markdown: { type: string } }, required: [markdown] }
  - id: safe
    type: model
    route: { profile: fast-judge }
    prompt: "Are these lessons safe, accurate and free of private data? {{lessons.output.markdown}}"
    format: { type: yes_no }
  - id: save
    type: resource
    resource:
      {
        type: memory_store,
        id: "${SUPPORT_MEMORY}",
        action: write,
        mode: update,
        path: /lessons.md,
        expected_sha256: "{{current.sha256}}",
        content: "{{lessons.output.markdown}}",
      }
wires:
  - { from: nightly, to: recent }
  - { from: recent, to: current }
  - { from: current, to: lessons }
  - { from: lessons, to: safe }
  - { from: safe, port: "yes", to: save }
```

```bash CLI theme={"theme":{"light":"github-light","dark":"github-dark"}}
checkfu automations create -f dreaming.yaml --var SUPPORT_BOT=$SUPPORT_BOT --var AUTHOR=$AUTHOR \
  --var SUPPORT_AGENT=$SUPPORT_AGENT --var CURATOR_AGENT=$CURATOR_AGENT \
  --var SUPPORT_MEMORY=$SUPPORT_MEMORY --var ENVIRONMENT=$ENVIRONMENT
```

```bash cURL theme={"theme":{"light":"github-light","dark":"github-dark"}}
curl --request POST https://api.checkfu.com/v1/automations \
  --header "Authorization: Bearer $CHECKFU_API_KEY" \
  --header "Checkfu-Version: 2026-08-31" \
  --header "Idempotency-Key: $(uuidgen)" \
  --header "Content-Type: application/json" \
  --data '{
    "name": "Nightly lessons for support",
    "runs_as": "'"$SUPPORT_BOT"'",
    "created_by_principal_id": "'"$AUTHOR"'",
    "environment_id": "'"$ENVIRONMENT"'",
    "blocks": [
      { "id": "nightly", "type": "trigger", "trigger": { "type": "schedule", "cron": "0 3 * * *", "timezone": "UTC" } },
      { "id": "recent", "type": "resource", "resource": { "type": "sessions", "agent": "'"$SUPPORT_AGENT"'", "limit": 50 } },
      {
        "id": "current",
        "type": "resource",
        "resource": { "type": "memory_store", "id": "'"$SUPPORT_MEMORY"'", "action": "read", "path": "/lessons.md" }
      },
      {
        "id": "lessons",
        "type": "agent",
        "agent": "'"$CURATOR_AGENT"'",
        "prompt": "Current lessons: {{current.content}} Add durable new lessons from these Sessions and return the full updated document: {{recent.sessions}}",
        "output_schema": { "type": "object", "properties": { "markdown": { "type": "string" } }, "required": ["markdown"] }
      },
      {
        "id": "safe",
        "type": "model",
        "route": { "profile": "fast-judge" },
        "prompt": "Are these lessons safe, accurate and free of private data? {{lessons.output.markdown}}",
        "format": { "type": "yes_no" }
      },
      {
        "id": "save",
        "type": "resource",
        "resource": {
          "type": "memory_store",
          "id": "'"$SUPPORT_MEMORY"'",
          "action": "write",
          "mode": "update",
          "path": "/lessons.md",
          "expected_sha256": "{{current.sha256}}",
          "content": "{{lessons.output.markdown}}"
        }
      }
    ],
    "wires": [
      { "from": "nightly", "to": "recent" },
      { "from": "recent", "to": "current" },
      { "from": "current", "to": "lessons" },
      { "from": "lessons", "to": "safe" },
      { "from": "safe", "port": "yes", "to": "save" }
    ]
  }'
```

```ts TypeScript theme={"theme":{"light":"github-light","dark":"github-dark"}}
import { Checkfu, recipes } from "@checkfu/sdk"

const checkfu = new Checkfu({ apiKey: process.env.CHECKFU_API_KEY })

const document = recipes.dreaming({
  runsAs: process.env.SUPPORT_BOT!,
  environmentId: process.env.ENVIRONMENT,
  sessionsOf: process.env.SUPPORT_AGENT!,
  curator: process.env.CURATOR_AGENT!,
  memoryStore: process.env.SUPPORT_MEMORY!,
  route: { profile: "fast-judge" },
})

const automation = await checkfu.automations.create(
  {
    ...document,
    created_by_principal_id: process.env.AUTHOR,
  },
  { idempotencyKey: crypto.randomUUID() },
)
```

Keep the `auto_…` id it returns in `AUTOMATION`.

## 2. Grant what it needs

The service account needs `observe` on the support Agent to see its Sessions, `read` and `write` on the Memory store, `act_as` on the Curator and `use_model` on the route. `GET /v1/automations/{id}/access` lists each one with its `status`:

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
curl https://api.checkfu.com/v1/automations/$AUTOMATION/access \
  --header "Authorization: Bearer $CHECKFU_API_KEY" \
  --header "Checkfu-Version: 2026-08-31"
```

Grant a missing one with a [PermissionAssignment](https://docs.checkfu.com/concepts/tenancy-and-governance.md). For example, to let it see the support Agent's Sessions:

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
curl --request POST https://api.checkfu.com/v1/permission-assignments \
  --header "Authorization: Bearer $CHECKFU_API_KEY" \
  --header "Checkfu-Version: 2026-08-31" \
  --header "Idempotency-Key: $(uuidgen)" \
  --header "Content-Type: application/json" \
  --data '{
    "subject": { "type": "principal", "id": "'"$SUPPORT_BOT"'" },
    "resource": { "type": "agent", "id": "'"$SUPPORT_AGENT"'" },
    "permission": "observe"
  }'
```

A grant that already exists answers `409`.

The account sees only the Sessions its grants allow. The `recent` block reports how many it skipped in `skipped`.

## 3. Publish

Testing a draft whose Sessions block reads real Sessions is not available yet, so publish and run it.

```bash CLI theme={"theme":{"light":"github-light","dark":"github-dark"}}
checkfu automations publish $AUTOMATION
```

```bash cURL theme={"theme":{"light":"github-light","dark":"github-dark"}}
curl --request POST https://api.checkfu.com/v1/automations/$AUTOMATION/publish \
  --header "Authorization: Bearer $CHECKFU_API_KEY" \
  --header "Checkfu-Version: 2026-08-31" \
  --header "Content-Type: application/json" \
  --data '{}'
```

```ts TypeScript theme={"theme":{"light":"github-light","dark":"github-dark"}}
const publication = await checkfu.automations.publish(automation.id, {})
console.log(publication.summary)
```

The summary names the schedule and the next run, for example "Runs on the schedule `0 3 * * *` in UTC; the next run is at 2026-10-29T03:00:00.000Z".

## 4. Run it now and read the result

You don't have to wait for 03:00. A manual run reads the same unprocessed Sessions:

```bash CLI theme={"theme":{"light":"github-light","dark":"github-dark"}}
checkfu automations run $AUTOMATION
```

```bash cURL theme={"theme":{"light":"github-light","dark":"github-dark"}}
curl --request POST https://api.checkfu.com/v1/automations/$AUTOMATION/run \
  --header "Authorization: Bearer $CHECKFU_API_KEY" \
  --header "Checkfu-Version: 2026-08-31" \
  --header "Idempotency-Key: $(uuidgen)" \
  --header "Content-Type: application/json" \
  --data '{ "event": {} }'
```

```ts TypeScript theme={"theme":{"light":"github-light","dark":"github-dark"}}
const run = await checkfu.automations.run(
  automation.id,
  { event: {} },
  { idempotencyKey: crypto.randomUUID() },
)
```

List the runs and their status:

```bash CLI theme={"theme":{"light":"github-light","dark":"github-dark"}}
checkfu automations runs $AUTOMATION --limit 5
```

```bash cURL theme={"theme":{"light":"github-light","dark":"github-dark"}}
curl "https://api.checkfu.com/v1/automation-runs?automation_id=$AUTOMATION&limit=5" \
  --header "Authorization: Bearer $CHECKFU_API_KEY" \
  --header "Checkfu-Version: 2026-08-31"
```

```ts TypeScript theme={"theme":{"light":"github-light","dark":"github-dark"}}
const runs = await checkfu.automationRuns.list({ automation_id: automation.id, limit: 5 })
```

When there are no new Sessions, `recent` takes its `none` exit and the run ends there. If the store reviews changes, the `save` block creates a proposal instead of writing, and its `status` is `proposed`.

See [Automations](https://docs.checkfu.com/concepts/automations.md) for every block and field, and [Memory](https://docs.checkfu.com/concepts/memory.md) for how stores and proposals work.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.