proomt

Search

Search posts, papers, and topics

All posts

SitePoint18 min readintermediate

Building Deterministic Multi-Agent State Machines in TypeScript

Summary

The article shows how to build a deterministic, checkpoint‑backed finite state machine engine in TypeScript for orchestrating multi‑agent AI workflows. It uses Zod for schema validation, better‑sqlite3 for atomic persistence, and a pure transition function to make workflows traceable and recoverable in serverless environments.

  • Define FSM states, events, and transitions with Zod schemas so runtime validation stays in sync with TypeScript types.
  • Validate the workflow graph as a DAG at startup using Kahn's algorithm to catch cycles and unreachable non‑terminal states.
  • Implement transitions as pure functions that return a new snapshot; guard functions must be deterministic to preserve overall determinism.
  • Persist each state change atomically with better‑sqlite3 inside a transaction before side‑effects, enabling rollback and safe retries.

Engineers building multi‑agent AI pipelines need deterministic orchestration and reliable recovery, especially when deploying to serverless environments.

6/10

Related reading

  1. Build a Typed Context Compaction Gate for AI Agents

    A step‑by‑step tutorial showing how to build a typed context‑compaction gate for AI agents in TypeScript using LangChain and Zod. It defines a discriminated‑union schema for keep/summarize/discard actions, implements a fast gpt‑4o‑mini classifier, validates decisions at runtime, and wires the gate as middleware in an agent loop, with testing and production‑grade tuning advice.

    SitePointsitepoint.com16 min
  2. Constraint Decay: The Fragility of LLM Agents in Backend Code Generation

    A systematic evaluation of LLM agents generating multi‑file backend code shows a sharp drop in correctness when structural constraints (framework conventions, ORM usage, API contracts) are added. Across 100 tasks in 8 Python web frameworks, assertion pass rates fall ~27 points, with data‑layer bugs (bad queries, ORM violations) driving most failures. Mid‑size models cope with minimal frameworks (…

    arXiv cs.SE (Software Engineering)arxiv.org1 minpaperHN287197
  3. Eliminating AI Code Hallucinations with TypeScript Compiler Diagnostics and TDD Loops

    The article shows how to replace raw TypeScript compiler output with a programmatic JSON feedback loop that merges diagnostics and Vitest test failures, feeding the structured data back to an LLM coding agent for self‑correction. It provides concrete code for extracting, enriching, validating, and de‑duplicating errors, and demonstrates token savings and deterministic iteration until compilation…

    SitePointsitepoint.com15 min
  4. Building Composite Model Context Protocol (MCP) Gateways in TypeScript

    Step‑by‑step tutorial showing how to build a stateless composite Model Context Protocol (MCP) gateway in TypeScript using Hono, Zod, and the MCP SDK. It covers config‑driven upstream registration, namespaced tool discovery, JSON‑RPC routing, per‑tool auth middleware, and a token‑bucket rate limiter, with concrete code snippets and design trade‑offs.

    SitePointsitepoint.com16 min