pressfit.ai

AI Infra in Graphics: take control flow away from the model

In a deterministic graph process engine, the business logic is an explicit graph. Application code handles the state, the parallel workers, the saves and the retries. The model is called only as a bounded step that has to return a typed result.

By Anthony Skinner, CEO and Co-Founder, and the Pressfit.ai Engineering Team

Orchestration
All code

A compiled state machine handles every route.

Model tokens
Bounded

No tokens spent on ingestion, math or routing.

State
Checkpointed

Typed JSON state saved after every step.

Failures
Deterministic

Code gates send low scores to a person.

The vendor audit graph, step by step

This is the reference graph from our starter kit. Click any step to see its contract, or run the graph and watch the shared WorkflowState change as it moves through code steps and the one model step.

Code step (no tokens) Bounded model step Code router
Entry: START 0 tokens | 2ms
Payload and schema validation

Pydantic checks vendor_id and vendor_docs before the graph starts.

↓
Code: ingest_data_node 0 tokens | 14ms
Sanitize the data and set the state

Plain Python strips whitespace and sets retry_count=0.

↓
Model: semantic_audit_node ~420 tokens | 780ms
Bounded model evaluation, parallel workers

Each isolated call must return a VerificationResult JSON schema.

Worker A: W9 tax audit
Worker B: insurance check
↓
Router: quality_gate_router 0 tokens | 1ms
The gate is code, not a prompt

if compliance_passed and audit_score >= 0.85:

Passes (≥ 0.85) ↓
Code
generate_approval

Commits the approval and ends the run.

Below (< 0.85) ↓
Human gate
flag_for_review

Pauses the state and alerts the team.

State is checkpointed after every step (Postgres or Redis)
Step inspector ingest_data_node

Sanitize the data and set the state

Plain Python cleans the inputs and sets the starting state.

Tokens
0 Tokens
Latency
14 ms
Determinism
100%
Typed WorkflowState (JSON) Fixed schema

            

An example run. Token and timing figures are illustrative.

Tokens and state, graph engine vs prompt agent

How compute and state memory behave in a deterministic graph engine compared with an unconstrained prompt agent across a multi-step workflow.

Tokens by step role

Most workflow steps need no generated tokens once they are written as code steps.

Takeaway: Keeping model calls to the semantic_audit_node stops token spend on ingestion, routing and report assembly.

Context size across the workflow

Typed state stays flat. An unconstrained chat history keeps growing with every step.

Takeaway: A bounded state schema keeps the context window from filling up and the run from drifting, even at 100+ steps.

Illustrative figures from the reference architecture, not measured test results. For measured results, see our research.

The design rules

To build this in production with LangGraph, Temporal or your own state machine, hold your codebase to these four boundaries.

Typed state, not chat history

Never pass raw message threads between steps. Define the state as a Pydantic or TypeScript schema, and pin business rules like approval thresholds as read-only values.

Structured output from every model step

Every model step must pass JSON schema validation before it hands control back to the graph. If it returns malformed JSON, a code retry catches it right away.

Routing in code, never in a prompt

Never ask a model which step comes next. Check scores, flags and thresholds with plain if/else edges in your code.

Save the state at every step

Checkpoint the state to Redis or Postgres on every edge. If an API times out or an approval waits two days, the run picks up where it stopped without losing tokens.

Build it yourself, or have us build it

Start with the Graph Workflow Starter Kit, or work with our dev team and Red Dev Test team to turn your skills into a tested, deterministic path.