← Back to NIP Index

Agent State Model (ASM) - A Unified State Management Framework

NIP: 8 | Author: jolestar(@jolestar) | Status: Draft | Created: May 15, 2025


NIP-8: Agent State Model (ASM)

Abstract

Agent State Model (ASM) defines a unified framework for describing, merging, querying, and managing the lifecycle of persistent states in AI agents. It serves as the standard for state definition within Agent Capability Packages (ACPs) as specified in NIP-7. It extends JSON-Schema 2020-12 with a minimal set of x-asm annotations:

Area Annotation Purpose
Container kind container object, map, list, log
CRDT policy crdt or per-field x-crdt lww_register, rga_text, or_map, …
Lifecycle x-ttl, x-retention, x-compression automated ageing, summarisation, compression
Visibility x-visibility private, shared, public

Together with a small JSON-AST query language (ASM-QL) and the standard state.* tool family, ASM allows routers and runtimes to treat conversation history, long-term memory, settings, and arbitrary application data in a unified, verifiable way.

Motivation

Need Current pain ASM solution
Multiple data shapes Only record-like objects in NIP-7 Adds map, list, log containers
Conflict-free merging Each plugin hand-picks a CRDT Policy is declared in schema → runtime acts uniformly
Unified querying Ad-hoc filters per capability ASM-QL: portable, verifiable query AST
Memory & chat history Not standardised Built-in ConversationLog & MemoryStore models
Data isolation Name clashes across ACPs Namespace rules under DID hierarchy

This NIP addresses the need for a standardized and comprehensive state management framework for AI agents. Existing mechanisms (like NIP-7 for record-like objects) are insufficient for handling diverse data shapes, ensuring conflict-free data merging across different agent capabilities (ACPs), providing a unified query language, standardizing common state types like conversation history and memory, and enforcing data isolation. ASM provides these capabilities, leading to more robust, interoperable, and manageable agent states.

Specification

Terminology

Term Meaning
Container Top-level state shape (object, map, list, log).
CRDT policy Conflict-resolution algorithm bound to container / field.
Memory Scope Named partition (e.g. sc:note, sc:chat) governed by ASM rules.
ASM-QL JSON serialisable query language evaluated by runtime and optionally verified on-chain.

Built-in Core Models

Nuwa runtimes MUST create exactly one instance of each core model for every user on first run.

ConversationLog did:nuwa:core:ConversationLog#v1

{
  "$id": "did:nuwa:core:ConversationLog#v1",
  "type": "object",
  "x-asm": {
    "container": "log",
    "crdt": "append_only",
    "x-ttl": "P14D",
    "x-compression": "br",
    "x-visibility": "private"
  },
  "properties": {
    "entries": {
      "type": "array",
      "x-crdt": "log_rga",
      "items": {
        "type": "object",
        "properties": {
          "id":        {"type":"string","format":"uuid"},
          "role":      {"type":"string","enum":["user","assistant"]},
          "content":   {"type":"string"},
          "timestamp": {"type":"string","format":"date-time"}
        },
        "required":["id","role","content","timestamp"]
      }
    }
  },
  "required": ["entries"]
}

Note:

MemoryStore did:nuwa:core:MemoryStore#v1

{
  "$id": "did:nuwa:core:MemoryStore#v1",
  "type": "object",
  "x-asm": {
    "container": "map",
    "keyType": "string",
    "valueRef": "#/definitions/MemoryItem",
    "x-retention": {
      "window": "P90D",
      "strategy": "evict_low_importance"
    },
    "x-visibility": "private"
  },
  "properties": {
    "items": {
      "type": "object",
      "additionalProperties": { "$ref": "#/definitions/MemoryItem" }
    }
  },
  "definitions": {
    "MemoryItem": {
      "type": "object",
      "properties": {
        "value":     {"type":"string"},
        "importance":{"type":"number"},
        "createdAt": {"type":"string","format":"date-time"}
      },
      "required":["value","importance","createdAt"]
    }
  }
}

Note:

AgentSettings did:nuwa:core:AgentSettings#v1

{
  "$id": "did:nuwa:core:AgentSettings#v1",
  "type": "object",
  "x-asm": {
    "container": "object",
    "x-visibility": "private"
  },
  "properties": {
    "language": {"type":"string","enum":["zh","en","ja","es"]},
    "tone":     {"type":"string","enum":["casual","formal","kids"]},
    "theme":    {"type":"string","enum":["light","dark"]},
    "notifOpt": {"type":"boolean"}
  },
  "required": ["language"]
}

Note:

Container Kinds & CRDT Policies

Kind Typical usage Default CRDT
object Fixed structured record per-field mix
map Arbitrary key → value OR-Map
list Ordered sequence RGA / Y-list
log Append-only event stream Monotonic vector

The canonical x-crdt keywords are:

lww_register • mv_register • rga_text • grow_only_set • or_map • counter • flag • log_rga

Lifecycle & Visibility

Annotation Format Semantics
x-ttl ISO-8601 duration Hard expiry; entries beyond TTL MAY be deleted.
x-retention {window,strategy} Sliding window & summarisation rules.
x-compression "br" / "zstd" / "gzip" Runtime MAY store snapshots compressed.
x-visibility private / shared / public Router MUST enforce access control.

ASM-QL — Query Language

Example AST:

{
  "select": ["id","title"],
  "from":   "did:nuwa:state:note#v1",
  "where":  {"tags":{"$contains":"meeting"}},
  "order":  [{"field":"updatedAt","direction":"desc"}],
  "limit":  20,
  "cursor": "opaque-base64"
}

Runtimes MAY translate to SQL, RocksDB iterators, or CR-SQLite views. Provers MAY embed the same AST in a Merkle proof for verifiable reads.

state.* Tool Semantics

Tool Required params Behaviour
state.create schema_uri, object Validate via ASM, emit create-op
state.update schema_uri, id, patch JSON-Patch / $inc, $push diff
state.query query (ASM-QL) Stream results or single shot
state.delete schema_uri, id, mode Tombstone or hard delete

All ops are persisted into the NIP-4 CRDT Event Log; snapshots anchored on-chain by NIP-13.

Namespace Rules

Namespace Pattern Purpose
core did:nuwa:core:<Model>#<ver> Platform-built-in
cap did:nuwa:cap:<cap_id>:state:<Name>#<ver> Each ACP’s private data
app did:nuwa:app:<app_name>:state:<Name>#<ver> Multi-capability application
user did:nuwa:user:<did_suffix>:state:<Name>#<ver> Experimental / ad-hoc

Runtime Rules

  1. Schema resolution$id MUST resolve via local cache → Registry → DID resolver.
  2. Container isolation — Distinct memory_scope ↔ distinct CRDT log.
  3. TTL enforcement — Background task removes or summarises expired log ranges.
  4. Compression — If x-compression set, runtime MAY store chunks compressed and anchor CAR hash.

Integration with NIP-7 (Agent Capability Protocol)

The Agent State Model (ASM) defined in this NIP is the designated framework for specifying the schema section within an Agent Capability Package (.acp.yaml file) as detailed in NIP-7. Capabilities should define their state objects using ASM-compliant JSON Schemas, leveraging the x-asm annotations for CRDT policies, lifecycle management, and visibility controls. The schema_uri used in state.* tool calls within an ACP context will refer to the $id of such an ASM-compliant schema.

Rationale

The design choices for ASM prioritize extending familiar standards like JSON-Schema with minimal, targeted annotations (x-asm) to reduce the learning curve and promote adoption.

Backwards Compatibility

Test Cases

Test cases are mandatory for this NIP and will be provided in a separate document or repository. They will cover:

Reference Implementation

A reference implementation of an ASM-compliant runtime module is planned. This will include:

Security Considerations

Copyright and related rights waived via CC0.

References

  1. JSON-Schema 2020-12
  2. DIDComm v2, Decentralized Identity Foundation
  3. ZCAP-LD, W3C CCG
  4. Automerge Binary File Format
  5. Conflict-Free Replicated Data Types (Shapiro et al.)