Skip to main content
This page has been superseded by Distributed Storage — MySQL. Content below is kept for reference.

MySQL State Store

agentscope-extensions-mysql persists AgentScope agent state into MySQL. A good fit when you already have a MySQL infrastructure or need transactional / SQL-based access to state data.

Add the dependency

Bring the matching JDBC driver yourself (e.g. mysql:mysql-connector-j).

Quickstart

If the database and table are pre-created, use the safer form:

Custom database / table names

Database and table names must match [a-zA-Z_][a-zA-Z0-9_-]* and be ≤ 64 chars to avoid SQL injection.

Schema

When createIfNotExist=true, the table is created automatically:
  • The (userId, sessionId) pair is packed into the session_id column as {userSegment}:{sessionId} (userSegment = userId, or __anon__ for anonymous sessions).
  • Single value: item_index = 0
  • List: item_index = 0, 1, 2, ... — one row per item; an extra row with state_key='xxx:_hash' is used for change detection.

Direct API usage

MysqlAgentStateStore implements the AgentStateStore interface:

Configuration

truncateAllSessions() issues TRUNCATE TABLE and requires DROP privilege; DDL is non-rollbackable, so reserve it for tests or ops cleanup.