Storage Module¶
This module provides storage and playback functions of experimental data.
ReplayWriter¶
- class agentsociety2.storage.ReplayWriter(db_path, *, enabled=True)[source]¶
Bases:
ReplaySinkBack-compat alias over
ReplaySink.The legacy public API (
agentsociety2.storage, examples) constructed a SQLite writer with a.dbfile path and calledawait init()before use. That writer is gone; this alias keeps the symbol importable and writes the same JSONL format, mapping the legacydb_pathto a replay directory (a trailing.dbis stripped) so old call sites keep working without SQLite.
ReplayWriter¶
- class agentsociety2.storage.ReplaySink(replay_dir, *, enabled=True)[source]¶
Bases:
objectPer-process, distributed, append-only JSONL replay writer.
One instance per writer process (driver / env router actor / each agent Ray task). Holds its own open shard fds; per-shard lock files make concurrent appends to the same shard file safe for rows of any size.
ReplayDatasetSpec¶
- class agentsociety2.storage.ReplayDatasetSpec(dataset_id, table_name, module_name, kind, title='', description='', entity_key=None, step_key=None, time_key=None, default_order=<factory>, capabilities=<factory>, version=1)[source]¶
Semantic metadata for a replay dataset backed by a SQLite table.
- __init__(dataset_id, table_name, module_name, kind, title='', description='', entity_key=None, step_key=None, time_key=None, default_order=<factory>, capabilities=<factory>, version=1)¶
ReplayWriter¶
- class agentsociety2.storage.ReplayReader(replay_dir)[source]¶
Read replay
_schema.json+ sharded JSONL rows via DuckDB.- fetch_dataset_rows(dataset, *, order_by=None, desc=False, step=None, entity_id=None, start_step=None, end_step=None, max_step=None, columns=None, latest_per_entity=False, limit=None, offset=0)[source]¶
- count_dataset_rows(dataset, *, step=None, entity_id=None, start_step=None, end_step=None, max_step=None, latest_per_entity=False)[source]¶
ColumnDef¶
- class agentsociety2.storage.ColumnDef(name, type, nullable=True, default=None, title=None, description=None, logical_type=None, analysis_role=None, unit=None, enum_values=None, example=None, tags=<factory>)[source]¶
Table column definition (SQLite).
Field description:
name: Column name.type: SQLite column type string. SeeColumnTypefor available values.nullable: Whether NULL is allowed.default: Default value expression, such asCURRENT_TIMESTAMP.title: Optional human-readable column title.description: Optional semantic description used for replay, export, and analysis.logical_type: Optional logical type, such asgeo.lngormoney.analysis_role: Optional analysis role, such asmeasure.unit: Optional unit string used by analysis and reporting.enum_values: Optional list of enumeration values for discrete columns.example: Optional example value.tags: Optional free-form tag list.
- __init__(name, type, nullable=True, default=None, title=None, description=None, logical_type=None, analysis_role=None, unit=None, enum_values=None, example=None, tags=<factory>)¶
TableSchema¶
Distributed Replay Proxy¶
In large-scale simulations, ReplayProxy only carries replay_dir and the enabled flag. After each agent / env / society process receives the proxy, it lazily loads a local ReplaySink and appends sharded JSONL directly.
ReplayWriter¶
- class agentsociety2.storage.replay_proxy.ReplayProxy(replay_dir=None, enabled=True, _sink=None)[source]¶
Serializable config for distributed replay writing.
Carries only the replay output directory and an enable flag — no Ray actor handle. Methods lazily build+cache a process-local
ReplaySink(fromreplay_dir) on first use and delegate, so each agent Ray task / env actor that receives a deserialized copy gets its own sink and its own file descriptors.enabled=Falsemakes every method a no-op.- __init__(replay_dir=None, enabled=True, _sink=None)¶
- agentsociety2.storage.build_replay_sink(replay_proxy)[source]¶
Build a per-process
ReplaySinkfrom aReplayProxy.Returns
Nonewhen the proxy is disabled or carries noreplay_dir.
Compatible data model¶
The following models are only compatible with reading historical SQLite databases; new experiments no longer write to these agent tables by default.
AgentProfile¶
- class agentsociety2.storage.models.AgentProfile(*, id, name, profile={}, created_at=<factory>)[source]¶
agent profile information (frame table).
- __init__(**data)¶
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- model_config = {'from_attributes': True, 'read_from_attributes': True, 'read_with_orm_mode': True, 'registry': PydanticUndefined, 'table': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
AgentStatus¶
- class agentsociety2.storage.models.AgentStatus(*, id, step, t, action=None, status=None, created_at=<factory>)[source]¶
A snapshot of the agent’s state at a certain step (framework table).
- __init__(**data)¶
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- model_config = {'from_attributes': True, 'read_from_attributes': True, 'read_with_orm_mode': True, 'registry': PydanticUndefined, 'table': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
AgentDialog¶
- class agentsociety2.storage.models.AgentDialog(*, id=None, agent_id, step, t, type, speaker, content, created_at=<factory>)[source]¶
agent conversation record (frame table).
- __init__(**data)¶
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- model_config = {'from_attributes': True, 'read_from_attributes': True, 'read_with_orm_mode': True, 'registry': PydanticUndefined, 'table': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].