Architecture
~9 min readUpdated: November 2026

Compiling Agent Traces into Typed Workflows: 98x Cheaper Execution

Compiling Agent Traces into Typed Workflows IR Architecture in Smoke Monkey

Compiling Agent Traces into Typed Workflows (`arXiv:2611.36322`) introduces an intermediate representation (IR) partitioning recurring agent procedures into three typed graph nodes: EXECUTE (deterministic code/tools), DECIDE (bounded candidate selection), and GENERATE (open-ended synthesis). Evaluated on AppWorld, compiled graphs solved 100% of held-out instances at 98x lower cost and 76x faster speed.

Technical Review: Smoke Monkey Core Architecture Team
Tested on Node.js 18+ & BunTypeScript 5.x
Quick Answer & Executive Definition

Compiling Agent Traces into Typed Workflows: 98x Cheaper Execution: Compiling Agent Traces into Typed Workflows (`arXiv:2611.36322`) introduces an intermediate representation (IR) partitioning recurring agent procedures into three typed graph nodes: EXECUTE (deterministic code/tools), DECIDE (bounded candidate selection), and GENERATE (open-ended synthesis). Evaluated on AppWorld, compiled graphs solved 100% of held-out instances at 98x lower cost and 76x faster speed. Designed as a zero-dependency, open-source TypeScript architecture under the MIT License with native Model Context Protocol (MCP) support and deterministic phase state machines.

Key Architectural Takeaways
Quick Implementation Examplecompiled-workflow-ir.ts
compiled-workflow-ir.tstypescript
import { createAgent } from '@smoke-monkey/harness';
// Step 1: Harvest successful agent traces via Smoke Monkey Harness
const traceCompilerAgent = createAgent({
agentId: 'trace-to-ir-compiler',
provider: 'anthropic',
model: 'claude-sonnet-4-20250514',
workspacePath: process.cwd(),
permissions: {
read_file: 'allow',
write_file: 'allow',
run_command: 'ask',
},
});
async function compileRecurringTrace() {
const result = await traceCompilerAgent.run(
'Analyze traces/reschedule-calendar/*.jsonl and compile a typed DAG using EXECUTE for API calls, DECIDE for slot selection, and GENERATE only for user confirmation.'
);
console.log('Compiled Workflow Graph:', result.summary);
}
compileRecurringTrace().catch(console.error);
Video Guides

Watch: Related Video Guides

Deterministic AI agents: workflows as tools

Build Deterministic AI Tools for Reliable AI Agents: Leapter + n8n Demo

What Is Typed Workflow Compilation? The EXECUTE / DECIDE / GENERATE IR

Most production agent workloads are structurally repetitive—rescheduling meetings, triaging CI failures, reconciling invoices, or migrating schema files across different inputs. Running a full frontier LLM loop with multi-turn context accumulation on every execution wastes 98% of token spend.

Research in arXiv:2611.36322 solves this by treating successful agent traces as source code and compiling them into a typed directed workflow graph partitioned by output space: EXECUTE nodes perform deterministic computation and direct tool API calls with zero LLM tokens; DECIDE nodes pick one bounded candidate declared by the graph; and GENERATE nodes invoke a language model only for open-ended text synthesis.

AppWorld Evaluation: 98x Cost Reduction & Break-Even Analysis

When traces generated by a full LLM agent were compiled into typed IR workflows and executed on held-out AppWorld test instances without keeping the agent loop or conversation context, the compiled runner matched 100% task completion at dramatic speed and cost improvements.

Execution ModeHeld-Out Solve RateRelative Cost / RunRelative SpeedupCompilation Overhead & Break-Even
Full Agent Loop (Baseline)100% (evaluated set)1.0x (100% tokens)1.0xNone (per-run context bloat)
Compiled Typed Workflow IR100% (all instances)98x cheaper76x faster3–5 min compile; pays back in 31–50 runs

Crucially, the paper enforces strict deployment invariants: compiled EXECUTE operations must hit real system APIs rather than simulated stubs, inputs are restricted to what the caller explicitly supplies, and the runner terminates deterministically rather than letting an LLM decide when to stop.

Structuring EXECUTE, DECIDE & GENERATE Nodes in TypeScript

You can apply this exact three-node IR partition inside Smoke Monkey Harness pipelines by promoting stable tool-call sequences out of the LLM loop into typed TypeScript steps and calling a lightweight model only at explicit DECIDE or GENERATE boundaries.

typescript
type NodeKind = 'EXECUTE' | 'DECIDE' | 'GENERATE';

interface WorkflowGraph {
  id: string;
  steps: Array<
    | { kind: 'EXECUTE'; tool: string; mapArgs: (ctx: Record<string, unknown>) => unknown }
    | { kind: 'DECIDE'; candidatesFrom: string; prompt: string }
    | { kind: 'GENERATE'; schema: string; promptTemplate: string }
  >;
}

When to Compile vs Keep Dynamic Agent Loops

Compilation takes 3–5 minutes of trace analysis and breaks even after 31–50 executions. Compile recurring operational workflows; keep full dynamic agent loops for novel, one-off engineering tasks.

Promoting Verified Traces to Production Workflows in Smoke Monkey

Smoke Monkey Harness logs structured execution traces across its 6-phase state machine (Explore -> Plan -> Edit -> Verify -> Recover -> Complete). Teams can inspect recurring verified trajectories, compile deterministic file/bash steps into EXECUTE blocks, and reserve LLM inference strictly for DECIDE branching.

Google Search Questions & Answers

Frequently Asked Questions

Q:What are the three node types in the compiled agent workflow IR?

Every workflow step maps into one of three output-space categories: `EXECUTE` (deterministic code and tool calls), `DECIDE` (selecting one bounded candidate declared in the graph), and `GENERATE` (open-ended LLM generation).

Q:How much cheaper and faster are compiled workflows compared to running the full agent?

On held-out AppWorld tasks, compiled typed workflows solved all evaluated instances at 98x lower cost and 76x faster execution per run because the runner drops the agent loop and accumulated context.

Q:How many runs does it take for trace compilation to pay for itself?

Compiling a workflow from successful traces takes roughly 3 to 5 minutes and breaks even in total cost after 31 to 50 executions.

Q:Does a compiled workflow still use an LLM at runtime?

Only on explicit `DECIDE` and `GENERATE` nodes. All deterministic `EXECUTE` tool calls and data transformations run natively with zero token cost.

Related Alternatives & Comparisons

Related Architecture Guides

View all guides

Build with Smoke Monkey Harness

Zero dependencies. 24 built-in tools. Human-in-the-loop safety. 100% open source under the MIT License.

npm install smoke-monkey-harness