Class: SwarmSDK::StateSnapshot

Inherits:
Object
  • Object
show all
Defined in:
lib/swarm_sdk/state_snapshot.rb

Overview

Creates snapshots of swarm/workflow conversation state

Unified implementation that works for both Swarm and Workflow. Captures conversation history, context state, scratchpad contents, and read tracking information.

The snapshot is a plain Ruby hash that can be serialized to JSON or any other format. Configuration (agent definitions, tools, prompts) stays in your YAML/DSL and is not included in snapshots.

Examples:

Snapshot a swarm

swarm = SwarmSDK.build { ... }
swarm.execute("Build authentication")
snapshot = swarm.snapshot
snapshot.write_to_file("session.json")

Snapshot a workflow

workflow = SwarmSDK.workflow { ... }
workflow.execute("Build feature")
snapshot = workflow.snapshot
snapshot.write_to_file("workflow_session.json")

Instance Method Summary collapse

Constructor Details

#initialize(orchestration) ⇒ StateSnapshot

Initialize snapshot creator

Parameters:

  • orchestration (Swarm, Workflow)

    Swarm or workflow to snapshot



29
30
31
# File 'lib/swarm_sdk/state_snapshot.rb', line 29

def initialize(orchestration)
  @orchestration = orchestration
end

Instance Method Details

#snapshotSnapshot

Create snapshot of current state

Returns a Snapshot object that encapsulates the snapshot data with convenient methods for serialization and file I/O.

Returns:



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/swarm_sdk/state_snapshot.rb', line 39

def snapshot
  data = {
    version: "2.1.0", # Bumped for plugin state abstraction
    type: type_name,
    snapshot_at: Time.now.utc.iso8601,
    swarm_sdk_version: SwarmSDK::VERSION,
    metadata: ,
    agents: snapshot_agents,
    delegation_instances: snapshot_delegation_instances,
    scratchpad: snapshot_scratchpad,
    read_tracking: snapshot_read_tracking,
    plugin_states: snapshot_plugin_states,
  }

  # Wrap in Snapshot object
  SwarmSDK::Snapshot.new(data)
end