Skip to main content

State Replay & Self-Debugging for AI Agents - Track, replay, undo, and checkpoint state changes

Project description

StateCLI - Python Client

State Replay & Self-Debugging for AI Agents.

Installation

pip install statecli

Quick Start

from statecli import StateCLI

# Initialize
cli = StateCLI()

# Track state changes
cli.track("order", "7421", {"status": "pending"}, actor="ai-agent")
cli.track("order", "7421", {"status": "processing"}, actor="ai-agent")

# Replay to see what happened
replay = cli.replay("order:7421")
print(f"Found {len(replay.changes)} changes")
for change in replay.changes:
    print(f"  Step {change.step}: {change.before} -> {change.after}")

# Create checkpoint before risky operation
cli.checkpoint("order:7421", "before-refund")

# Make risky change
cli.track("order", "7421", {"status": "refunded", "amount": 0})

# Undo if something went wrong
result = cli.undo("order:7421", steps=1)
print(f"Undid {result.steps_undone} step(s)")

# View history
log = cli.log("order:7421")
for change in log.changes:
    print(f"{change.timestamp}: {change.actor} -> {change.after}")

Self-Debugging Pattern

from statecli import StateCLI

class SelfHealingAgent:
    def __init__(self):
        self.cli = StateCLI()
    
    async def execute(self, task):
        entity = f"task:{task.id}"
        
        # Checkpoint before risky operation
        self.cli.checkpoint(entity, "before-execution")
        
        try:
            await self.run_task(task)
        except Exception as e:
            # Replay to see what happened
            replay = self.cli.replay(entity)
            print(f"Task failed. Replay: {replay.changes}")
            
            # Undo and retry
            self.cli.undo(entity)
            await self.retry_with_fix(task, replay)

API Reference

StateCLI(db_path=None)

Initialize client. Uses ~/.statecli/state.db by default.

track(entity_type, entity_id, state, actor="ai-agent")

Track a state change.

replay(entity, actor=None)

Replay state changes for an entity.

undo(entity, steps=1)

Undo the last N state changes.

checkpoint(entity, name)

Create a named checkpoint.

log(entity, since=None, actor=None)

View state change history.

restore_checkpoint(entity, name)

Restore to a named checkpoint.

Links

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

statecli-0.4.0.tar.gz (12.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

statecli-0.4.0-py3-none-any.whl (14.4 kB view details)

Uploaded Python 3

File details

Details for the file statecli-0.4.0.tar.gz.

File metadata

  • Download URL: statecli-0.4.0.tar.gz
  • Upload date:
  • Size: 12.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.0

File hashes

Hashes for statecli-0.4.0.tar.gz
Algorithm Hash digest
SHA256 b6cfc2495a84ae4c98ca74572f86e3417feeb0f2916d60d353c09653bea4756c
MD5 c4cfe05cc05411b1707fc4600cc2b452
BLAKE2b-256 5c0a405147ab2897ab831ab24e4ea4e20dc900009482f6b71042261b01cd9b36

See more details on using hashes here.

File details

Details for the file statecli-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: statecli-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 14.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.0

File hashes

Hashes for statecli-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e7f2e48905cde126bd1969b25df65ad5b9cda03f5c2e54ad9e0f29ec66da7238
MD5 ecb11338e58bf143266e9b9f3b95b256
BLAKE2b-256 95badf6bfa5972e5531061676891eb45626890d93ecf00e0200903e67b0b65f8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page