For the complete documentation index, see llms.txt. This page is also available as Markdown.

Persistence

Persist the Workflow State across executions.

When we talk about persistence in Neuron, we're talking about the system's ability to capture and preserve the complete state of a running workflow at any moment.

Think of it like a sophisticated "save game" feature, but for business processes. At any point, when an interruption is asked from a node, Neuron create a snapshot of your workflow's state and store it in the persistence layer. Later, whether that's seconds, hours, or weeks, the workflow can be restored to exactly where it left of and continue as if nothing happened.

As usual in Neuron the Workflow persistence layer is built on top of a common interface so it's extensible and interchangeable. Below the supported persistence layer.

InMemoryPersistence

It keep data in memory only for the current execution cycle.

use NeuronAI\Workflow\Persistence\InMemoryPersistence;
use NeuronAI\Workflow\Persistence\PersistenceInterface;

class MyWorkflow extends Workflow
{
    ...
    
    protected function persistence(): PersistenceInterface
    {
        return new InMemoryPersistence();
    }
}

FilePersistence

It will store the Workflow data and state into a local file.

DatabasePersistence

To persist the workflow interruption in the database you need to pass a PDO instance. If you are working on top of a framework you can easily get it from the ORM in the same way of the SQLChatHistory for chat history persistence.

Here are the SQL scripts to create the table:

EloquentPersistence

You should create your own Eloquent model and pass the class string as the constructor argument. The model can have custom relations, scopes, attributes, etc. but the basic structure must be based on this migration script:

WorkflowInterrupt model

This is the minimal required structure:

Use it in the Workflow:

Last updated