Skip to main content

What it does

write_data_store changes rows in a data store (a structured knowledge base). It supports single-row and multi-row writes, one-shot keyed saves (upsert), and atomic multi-statement batch writes. All values are parameterized, and the tool can never run schema changes — that’s manage_data_store’s job.
For an overview of structured data stores, see Data Stores.

Parameters

Key behaviors

  • upsert is the way to save keyed rows — “save this user’s score for this deal” is one call, with no select-first and no race. It needs a unique index on the conflict keys. The result reports whether the row was inserted or updated.
  • Optimistic concurrency — pass if_match with the version you last read (e.g. an updated_at); if another writer changed the row first, the write is skipped and the current row is returned so you can reconcile.
  • batch is atomic — several mutations in one transaction, all committed or none. Use it for coordinated multi-row changes.
  • update and delete require at least one filter — a guard against accidentally rewriting a whole table.
  • Errors carry the raw Postgres code (for example 23505 for a unique violation) plus the constraint name, so callers can branch on the code rather than parse a message.
  • bulk_load is file transport — for rows the agent is moving (imports, daily syncs from an external system), not reasoning about. The agent writes JSONL to the sandbox with execute_python, then one bulk_load call streams it server-side in a single transaction — the rows never pass through model context. mode: upsert with conflict_keys makes a daily refresh idempotent. More than 5 malformed lines aborts the whole load rather than half-loading a garbled file.

Common use cases

Insert rows

Upsert a keyed row