This page has been superseded by Distributed Storage — JDBC. 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
mysql:mysql-connector-j).
Quickstart
Custom database / table names
[a-zA-Z_][a-zA-Z0-9_-]* and be ≤ 64 chars to avoid SQL injection.
Schema
WhencreateIfNotExist=true, the table is created automatically:
utf8mb4_bin while the table default stays utf8mb4_unicode_ci: session_id and state_key are case-sensitive identifiers, and the table default is case-insensitive, so without the binary collation two ids differing only in letter case would collide on the primary key and share a row. Note that utf8mb4_bin is PAD SPACE — values differing only in trailing spaces still compare equal.
Migrating tables created before this change
CREATE TABLE IF NOT EXISTS does not alter a table that already exists, so a deployment created earlier keeps the case-insensitive default and needs an operator to migrate it. agentscope_store, agentscope_sessions and agentscope_snapshots all key on a caller-supplied identifier, so the same reasoning applies to each:
agentscope_snapshots — the agentscope-extensions-jdbc dialect and the legacy agentscope-extensions-mysql snapshot client — now pin the same collation, so the statement above is the only thing a deployment created earlier needs.
Two things to plan for:
-
Read semantics change with the collation. Comparisons and prefix lookups (
session_id = ?,LIKE 'prefix%') become case-sensitive, so a lookup that previously matchedSESS-1forsess-1will no longer match. Migrate at a point where no session is mid-flight. -
Rows may already be gone. If two keys differing only in case were written before the migration, the second write overwrote the first through
ON DUPLICATE KEY UPDATE; that lost row cannot be recovered from the table. -
The
(userId, sessionId)pair is packed into thesession_idcolumn 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 withstate_key='xxx:_hash'is used for change detection.
Direct API usage
MysqlAgentStateStore implements the AgentStateStore interface:
Configuration
truncateAllSessions()issuesTRUNCATE TABLEand requires DROP privilege; DDL is non-rollbackable, so reserve it for tests or ops cleanup.