Implementation:AIScientists Dev WorldSeed openclaw session logs
| Knowledge Sources | |
|---|---|
| Domains | Server, Persistence |
| Last Updated | 2026-10-26 18:00 GMT |
Overview
Concrete reader for OpenClaw agent session JSONL log files, providing session discovery, log extraction, and agent text aggregation provided by the WorldSeed library.
Description
The logs module finds and reads OpenClaw session files keyed by `agent:{slug_or_id}:worldseed:{run_id}`. `find_all_sessions` discovers all sessions for a given agent across runs; `resolve_session_file` resolves a specific run's JSONL path; `read_session_logs` parses the JSONL and extracts message/tool records; `read_agent_texts` scans all agents' sessions for a run, reverse-maps slugified agent IDs back to originals via the run config, and extracts assistant text responses with preceding tool-call summaries. The `_slugify_agent_id` function matches the TypeScript `slugifyAgentId` in the gateway — ASCII IDs pass through lowercase, non-ASCII IDs get a stable md5-based slug.
Usage
Import this module from server route handlers when you need to surface agent session history to the frontend — e.g., the `/api/agent-texts` endpoint uses `read_agent_texts` to extract agent dialogue for a run's pilot presentation.
Code Reference
Source Location
- Repository: WorldSeed
- File: src/worldseed/server/logs.py
Signature
def find_all_sessions(agent_id: str, openclaw_dir: str = "") -> list[dict[str, Any]]:
"""Find all OpenClaw sessions for a WorldSeed agent. Sorted newest first."""
def resolve_session_file(agent_id: str, run_id: str, openclaw_dir: str = "") -> Path | None:
"""Resolve the JSONL file path for an agent's session in a specific run."""
def read_session_logs(agent_id: str, run_id: str | None = None, limit: int = 0, openclaw_dir: str = "") -> list[dict[str, Any]]:
"""Read OpenClaw session JSONL for an agent, optionally for a specific run."""
def read_agent_texts(run_id: str, openclaw_dir: str = "") -> list[dict[str, Any]]:
"""Extract all agents' text responses for a run. Returns {agent_id, text, ts, tool_calls}."""
Import
from worldseed.server.logs import find_all_sessions, resolve_session_file, read_session_logs, read_agent_texts
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| agent_id | str | Yes | WorldSeed agent ID (may be non-ASCII) |
| run_id | str | Yes (resolve/read) | Run identifier |
| limit | int | No | Max number of recent messages (0 = all) |
| openclaw_dir | str | No | OpenClaw data dir (default: ~/.openclaw or OPENCLAW_DIR env) |
Outputs
| Name | Type | Description |
|---|---|---|
| find_all_sessions returns | list[dict] | Session metadata: {run_id, session_key, file, updated_at} |
| resolve_session_file returns | None | JSONL file path or None |
| read_session_logs returns | list[dict] | Parsed message records |
| read_agent_texts returns | list[dict] | {agent_id, text, ts, tool_calls} sorted by timestamp |
Usage Examples
from worldseed.server.logs import read_agent_texts
# Extract all agent dialogue for a run's pilot presentation
texts = read_agent_texts("run_2026_04_26")
# texts = [{"agent_id": "alex_opt", "text": "I'll try AdamW...", "ts": "...", "tool_calls": [...]}]
from worldseed.server.logs import resolve_session_file
# Find a specific agent's session file for a run
path = resolve_session_file("old_chen", "run_2026_04_26")
if path:
print(f"Session at {path}")