replay

suspend fun <State> CompiledGraph<State>.replay(checkpoint: Checkpoint<State>, config: GraphConfig<State> = GraphConfig(), update: suspend (State) -> State = { it }, scenario: suspend GraphTest<State>.() -> Unit)

Runs this graph again from checkpoint, a checkpoint of an earlier run, and checks in scenario what it does from there. scenario holds the same checks as in test.

Use it to find out why a run went wrong: save a checkpoint of the run, for example the file a FileCheckpointer wrote, read it with CheckpointCodec, and run this graph from it with a scripted model or the node you fixed. The graph does not have to be the one that saved the checkpoint, only to have its nodes.

val history = CheckpointCodec<AgentState>().decodeHistory("ticket-42", readResource("ticket-42.json"))
val model = ScriptedChatModel { says("Your pizza is 5 minutes away.") }

// The run failed in its fourth step, which was not saved: the last checkpoint is the one after step 3.
helpDeskAgent(model).replay(history.last()) {
expectNode("model")
expectFinished { state -> assertEquals("Your pizza is 5 minutes away.", state.answer) }
}

The run continues like CompiledGraph.fork does: on the thread of config, with the step numbers of the run that saved checkpoint. When config has no checkpointer, the test adds a MemoryCheckpointer.

Parameters

update

edits the state of checkpoint before the run continues.

Throws

if the run does not do what scenario expects.