mech.app

The mech.app newsletter

Agentic AI, minus the noise.

Get practical field notes on AI agents, automation, developer tools and security delivered to your inbox.

No spam. Unsubscribe anytime.

AI Agents

Workflow as Knowledge: Semantic Persistence for Replayable, Debuggable LLM Workflows

A Lisp-inspired model for persisting LLM workflows as knowledge graphs, enabling replay, branching, and human-in-the-loop debugging.

Source: arxiv.org
Workflow as Knowledge: Semantic Persistence for Replayable, Debuggable LLM Workflows

Most LLM workflow systems treat execution as ephemeral. You run a multi-step agent workflow, it calls tools, retrieves context, branches on conditions, waits for human approval, and either succeeds or fails. The logs tell you what happened. The traces show you timing. But the workflow itself disappears once execution ends.

A new ArXiv paper (2607.08740v1) proposes a different model: workflows become persistent, structured knowledge objects. Instead of treating workflows as transient execution graphs, the authors argue for semantic persistence where workflow definitions, instances, inference records, context snapshots, and dependency relations live as inspectable, resumable, reviewable artifacts in a shared knowledge substrate.

The conceptual model is Lisp-inspired but language-agnostic. It borrows symbolic forms, object identity, and live-image thinking to explain how workflows can be serialized, replayed, and debugged without committing to a specific runtime or storage layer.

The Problem: Workflows Vanish After Execution

Production LLM workflows already handle:

  • Tool use: calling external APIs, databases, or compute resources
  • Retrieval: fetching context from vector stores or knowledge bases
  • Branching: conditional logic based on LLM outputs or tool results
  • Checkpointing: saving intermediate state for retry or resume
  • Human approval: pausing execution for manual review

Existing workflow engines (Temporal, Airflow, Prefect, LangGraph) manage execution, retries, and observability. But they treat workflows as code that runs and then stops. The execution trace is separate from the workflow definition. The context snapshots are logs, not first-class objects. Debugging means reading logs and re-running code.

Semantic persistence flips this: the workflow instance itself becomes a knowledge artifact that can be queried, branched, and replayed.

Semantic Persistence: Workflows as Knowledge Objects

The paper introduces a conceptual model where workflows are persistent, structured knowledge. The model distinguishes two core operations:

  • Derive: deterministic computation over available state (pure functions, data transformations)
  • Infer: LLM-mediated judgment under declared context and capability policy (non-deterministic, requires executor control)

This distinction matters because derive steps can be replayed exactly, while infer steps require context reconstruction and policy enforcement.

What Gets Persisted

The model proposes persisting:

  1. Workflow definitions: the structure of the workflow (steps, dependencies, branching logic)
  2. Workflow instances: specific executions with unique identities
  3. Inference records: LLM calls, prompts, responses, and context windows
  4. Context snapshots: the state of the world at each step (tool outputs, retrieved documents, user inputs)
  5. Dependency relations: which steps depend on which prior results

Each of these is a knowledge object with stable identity, not just a log entry.

Lisp-Inspired Representation

The paper uses Lisp concepts as explanatory lenses:

  • Symbolic forms: workflows are represented as nested structures (like S-expressions) that can be inspected and manipulated
  • Object identity: each workflow instance, inference record, and context snapshot has a stable identifier
  • Live-image thinking: the workflow state is a living object that can be paused, inspected, and resumed (like a Lisp REPL image)

This is not a Lisp implementation. It is a conceptual model that could be implemented in any language with support for structured data, object identity, and serialization.

Architecture: How Semantic Persistence Works

The paper does not prescribe a specific implementation but outlines a conceptual architecture:

┌─────────────────────────────────────────┐
│   Workflow Executor (runtime)           │
│   - Executes derive steps                │
│   - Mediates infer steps via LLM         │
│   - Enforces capability policy           │
└────────────────┬────────────────────────┘


┌─────────────────────────────────────────┐
│   Knowledge Substrate (persistence)      │
│   - Workflow definitions                 │
│   - Workflow instances                   │
│   - Inference records                    │
│   - Context snapshots                    │
│   - Dependency graph                     │
└─────────────────────────────────────────┘

Execution Flow

  1. Workflow definition is loaded from the knowledge substrate
  2. Workflow instance is created with a unique identity
  3. Derive steps execute deterministically and write results to the substrate
  4. Infer steps reconstruct context from the substrate, call the LLM, and persist the inference record
  5. Branching is handled by querying the substrate for prior results and selecting the next step
  6. Checkpointing is implicit: every step writes to the substrate, so the workflow can resume from any point
  7. Human approval pauses execution and persists the pending state as a reviewable object

Replay and Debugging

Because the substrate stores the full dependency graph, you can:

  • Replay a workflow by re-executing derive steps and optionally re-running infer steps with the same context
  • Branch from a checkpoint by creating a new workflow instance that starts from a prior step
  • Inspect inference records to see what the LLM saw, what it returned, and what policy constraints applied
  • Debug failures by querying the substrate for the state at the failure point

This is different from event sourcing (which stores events, not structured knowledge) and traditional checkpointing (which saves state blobs, not inspectable objects).

Implementation Trade-offs

The paper is conceptual, but the model implies specific engineering choices:

ConcernApproachTrade-off
StoragePersist every workflow instance, inference record, and context snapshot as a structured objectHigh storage cost, but enables full replay and debugging
SerializationUse a format that preserves object identity and dependency relations (e.g., RDF, JSON-LD, or custom graph format)More complex than JSON logs, but queryable and inspectable
ReplayRe-execute derive steps and optionally re-run infer steps with reconstructed contextDeterministic for derive, non-deterministic for infer (LLM may return different results)
BranchingCreate new workflow instances that share prior steps but diverge at a branch pointRequires stable object identities and dependency tracking
Human approvalPersist the pending state as a reviewable object that can be approved, rejected, or modifiedRequires UI for inspecting and acting on pending workflows
Capability policyDeclare which tools and resources each infer step can access, enforced by the executorAdds complexity but prevents runaway tool use

When Semantic Persistence Matters

This model is not for every workflow. It adds complexity and storage overhead. But it solves real problems in production LLM systems:

Use Cases

  • Long-running workflows that span hours or days and need to survive restarts
  • Human-in-the-loop workflows where approval steps must be inspectable and auditable
  • Debugging complex agent workflows where you need to see what the LLM saw at each step
  • Versioning and branching where you want to try different paths from the same checkpoint
  • Compliance and audit where you need to prove what happened and why

Anti-Patterns

  • Short, stateless workflows where the overhead of persistence is not worth it
  • High-throughput workflows where storage and serialization costs dominate
  • Workflows with large context windows where persisting every snapshot is impractical

Code Sketch: Conceptual Persistence Layer

The paper does not provide implementation details or formal transition semantics. Here is a sketch of what a semantic persistence layer might look like:

from dataclasses import dataclass
from typing import Any, Dict, List, Optional
from uuid import uuid4

@dataclass
class WorkflowInstance:
    id: str
    definition_id: str
    state: Dict[str, Any]
    dependencies: Dict[str, List[str]]  # step_id -> [dependency_ids]

@dataclass
class InferenceRecord:
    id: str
    workflow_instance_id: str
    step_id: str
    context_snapshot_id: str
    prompt: str
    response: str
    model: str
    policy: Dict[str, Any]

class KnowledgeSubstrate:
    def __init__(self):
        self.workflows = {}
        self.inferences = {}
        self.contexts = {}
    
    def persist_workflow(self, instance: WorkflowInstance):
        self.workflows[instance.id] = instance
    
    def persist_inference(self, record: InferenceRecord):
        self.inferences[record.id] = record
    
    def get_workflow(self, workflow_id: str) -> Optional[WorkflowInstance]:
        return self.workflows.get(workflow_id)
    
    def get_inference(self, inference_id: str) -> Optional[InferenceRecord]:
        return self.inferences.get(inference_id)

# Usage
substrate = KnowledgeSubstrate()

workflow = WorkflowInstance(
    id=str(uuid4()),
    definition_id="customer-support-workflow",
    state={"customer_id": "12345"},
    dependencies={}
)

substrate.persist_workflow(workflow)

inference = InferenceRecord(
    id=str(uuid4()),
    workflow_instance_id=workflow.id,
    step_id="classify-intent",
    context_snapshot_id="ctx-001",
    prompt="Classify the customer's intent...",
    response="intent: refund_request",
    model="gpt-4",
    policy={"allowed_tools": ["database", "email"]}
)

substrate.persist_inference(inference)

This is a toy example. A production implementation would need durable storage (Postgres, DynamoDB, or a graph database like Neo4j) capable of handling 10M+ inference records with sub-100ms query latency, serialization that preserves object identity and dependencies, a query interface for inspecting workflows and inferences, and policy enforcement that controls tool access during infer steps. The paper explicitly states that formal transition semantics and replay algorithms remain future work.

Technical Verdict

Use semantic persistence when:

  • Your workflows span more than 5 steps with at least one human approval or tool call
  • You need to debug failures by inspecting what the LLM saw at each step
  • Compliance or audit requirements demand full traceability of decisions
  • You want to branch or replay workflows from specific checkpoints
  • Your average workflow runs longer than 5 minutes and must survive restarts

Avoid it when:

  • Your workflows complete in under 30 seconds with no human interaction
  • You process more than 1,000 workflows per second (storage costs will dominate)
  • Your context windows exceed 100KB per step (snapshot storage becomes impractical)
  • Your workflow engine already provides sufficient observability and replay
  • You do not need to inspect or branch from intermediate states

The paper is conceptual, not a production system. But it identifies a real gap: most workflow engines treat execution as ephemeral, and most LLM observability tools treat traces as logs. Semantic persistence offers a third way where workflows become first-class knowledge objects that can be inspected, replayed, and debugged like live data structures.

The Lisp-inspired model is a lens, not a prescription. The real question is whether your workflows are complex enough to justify the overhead of persisting them as structured knowledge. For long-running, human-in-the-loop, or compliance-critical workflows, the answer is probably yes.

Tags

agentic-ai orchestration infrastructure

Primary Source

arxiv.org