polyclaw v5.0.0

State Management

Polyclaw uses a file-based state system with JSON stores. All state files live under POLYCLAW_DATA_DIR (default: ~/.polyclaw/).

State Modules

Session Store

File: sessions/<session_id>.json

Each chat session is persisted as a separate JSON file containing message history, metadata, and timestamps.

FeatureDescription
One file per sessionEasy inspection and backup
Archival policies24h, 7d, 30d, never
Session resumeLast 20 messages loaded as context
MetadataModel, title, message count, created/updated timestamps

Memory Store

Directory: memory/

The memory system consolidates chat interactions into long-term memories:

  • daily/ – Daily log files summarizing interactions
  • topics/ – Topic-specific notes extracted from conversations

Memory formation is triggered after MEMORY_IDLE_MINUTES (default: 5) of inactivity. The MEMORY_MODEL LLM generates structured summaries from buffered chat turns.

Profile Store

File: agent_profile.json

Tracks the agent’s identity and behavioral state:

FieldDescription
nameAgent display name
emojiVisual identity
locationTimezone context
emotional_stateCurrent mood (affects responses)
preferencesCommunication style preferences

Related data is stored in separate files:

FileDescription
skill_usage.jsonUsage counts per skill
interactions.jsonRecent interaction log (last 1 000 entries)

The get_full_profile() helper merges the profile with skill usage, per-day contribution counts, and activity statistics.

MCP Config

File: mcp_servers.json

Stores MCP server definitions. Supports four server types:

TypeDescription
localSpawned as a subprocess
stdioCommunicates via stdin/stdout
httpRemote HTTP endpoint
sseServer-Sent Events endpoint

Proactive State

File: proactive.json

Manages autonomous proactive messaging:

FieldDescription
enabledWhether proactive messaging is active
pendingSingle pending message awaiting delivery
historyLast 100 delivered messages with reactions
preferencesTiming, frequency, and topic constraints

The messages_sent_today() and hours_since_last_sent() methods compute daily counts and gap tracking from the history rather than persisting them as separate fields.

Guardrails Config

Files: guardrails.json, policy.yaml

Stores human-in-the-loop (HITL) approval rules, tool-level and context-level policies, model-specific overrides, and Content Safety settings. A YAML policy file is generated alongside the JSON and consumed by the PolicyEngine at runtime.

Monitoring Config

File: monitoring.json

Stores OpenTelemetry and Application Insights configuration including connection strings, sampling ratio, live metrics toggle, and provisioning metadata.

Tool Activity Store

File: tool_activity.jsonl

Append-only JSON-lines log of every tool invocation. Each entry records tool name, arguments, result, duration, risk score, and Content Safety shield results. Supports query, timeline, CSV export, and session-level breakdowns for audit.

Other State Files

FilePurpose
SOUL.mdAgent personality definition
scheduler.jsonScheduled task definitions
deployments.jsonDeployment records
infra.jsonInfrastructure configuration (bot, channels, voice)
plugins.jsonPlugin enabled/disabled state
sandbox.jsonSandbox configuration and session pool metadata
foundry_iq.jsonAzure AI Foundry IQ / Search settings
conversation_refs.jsonBot Framework conversation references

Design Principles

  • No database required – everything is flat files for simplicity and portability
  • Human-readable – JSON, JSONL, and Markdown files can be inspected and edited manually
  • Docker-friendly – mount ~/.polyclaw as a volume for persistence
  • Thread-safe I/O – shared stores use threading.Lock for concurrent access