
From Agent Loops to Durable Agentic Systems
A SparrowX case study on where agent frameworks end, durable orchestration begins, and how systems like Embabel and Temporal work together in production..
For the actual Sparrow-X system production code, find it in this Github Repo.
Aggrey Lelei
Agentic AI · Agent Orchestration · Durable Execution · AI Infrastructure Distributed Systems · Temporal · Embabel · Human-in-the-Loop
12 min read · September 1, 2026
"When I first saw heavyweight orchestration platforms like Temporal or Durable Functions being introduced into agentic architectures, my knee-jerk reaction was skepticism: why stack yet another infrastructure layer onto tools that already manage state and execution?
But that perspective stemmed from seeing agents through a lightweight lens—treating them purely as local, single-session tool-callers. The gap becomes obvious the moment an agentic system transitions from a localized script into an enterprise-grade distributed pipeline.
Frameworks like Embabel or LangGraph provide the brain—the reasoning loops, memory structures, and tool selection mechanisms. Orchestration engines provide the central nervous system and dynamic memory card—ensuring that when that reasoning loop spans dozens of async microservices, human-in-the-loop gates, or multi-day waits, the entire process is crash-proof, deterministic, and fully replayable."
Rather than treating this purely as a theoretical debate, I built Sparrow-x: A production-ready agentic architecture to directly address and answer these questions that usually get conflated:
- If frameworks handle execution loops and tooling out of the box, why stack orchestration on top?
- If an engine dictates system state, does the system retain its agentic nature, or is it just a structured workflow?
- Where does the framework end and the orchestration engine actually take over?
Chapter 1: Agent Loop and Agent Orchestration.
1.1 Definition.
Before diving into question 1, let's get on the same page with a few essential terms that often get blurred together:
The Agent Loop (The Cognitive Mechanics): The core reasoning pattern of the application. It dictates how the model processes context, decides whether to plan versus execute, invokes tools, and determines its terminal condition. This logic is the defining essence of an agent.
The Agent Framework (The Engineering Scaffolding): The application-level developer layer (e.g. Embabel, LangGraph, Strands). It wraps the raw reasoning loop in enterprise infrastructure—handling tool registration, memory ingestion, tracing, structured logging, and multi-agent dispatch. Its primary role is velocity: taking a local reasoning loop and turning it into production-ready software quickly.
The Orchestration Engine (The Infrastructure Layer): The underlying execution backbone (e.g., Temporal, Durable Functions). It offloads execution state entirely to handle distributed, system-level challenges: surviving host crashes, managing multi-day human-in-the-loop pauses, coordinating multi-agent workflows, and guaranteeing execution durability across process boundaries.
Frameworks accelerate feature delivery and lower the entry barrier for building AI applications; orchestration engines guarantee operational resilience and state preservation under load. Rather than being mutually exclusive, they form a symbiotic technical stack.
Consider a real-world enterprise agentic task managed via Sparrow-x: resolving an internal inquiry might demand dozens of sequential LLM reasoning steps, queries across a company directory, deep dives into internal research repositories, multiple tool executions, and multi-day pauses waiting for human administrative sign-off. Every single point in this chain introduces network latency, potential API timeouts, or transient infrastructure faults.
While application frameworks provide convenient local retry logic, they are fundamentally ill-equipped to preserve state across node crashes, survive Kubernetes pod evictions, or maintain execution history during extended multi-day waits. Orchestration engines bridge this exact reliability deficit—offloading state management from application memory to durable infrastructure so complex workflows run to completion regardless of underlying platform instability.
1.2 Boundary Between an Orchestration Engine and an Agent.
The underlying distinction boils down to where non-determinism lives within the architecture. True agency does not require an unpredictable system hierarchy; rather, it requires that the model retains real-time control over action selection within defined goal boundaries. Frameworks like Embabel leverage Goal-Oriented Action Planning (GOAP) precisely to enable this: the system dynamically evaluates available actions, environment state, and target goals to resolve its own execution path autonomously.
When an orchestration engine wraps an agentic system, it does not strip away this autonomy or collapse the process into a rigid, step-by-step pipeline like Step 1 -> Step 2 -> Step 3. Instead, the orchestration layer acts as a durable host for the non-deterministic reasoning loop. The LLM—guided by GOAP mechanics—continues to dynamically select tools, iterate on intermediate results, and evaluate progression toward the goal, while the orchestration engine simply records each decision point to guarantee that the agent's emergent control flow can survive system failure without losing its place.
The 3 Orchestration Patterns.
Pattern A — External Orchestration in SparrowX

Temporal sits outside the Embabel agent and treats each agent execution as one durable workflow step. It manages sequencing, retries, recovery, waits, and human approval without controlling the agent’s internal reasoning.
Temporal Workflow
Step 1: Invoke SparrowX AgenticService
[intent → planning → tools → review → result]
Step 2: Wait for approval / external event
Step 3: Resume or invoke another agent execution
Step 4: Return the final mission resultInside agenticsvc, Embabel remains responsible for the reasoning loop. It can plan dynamically, call intsvc, query docsvc, use LLMs, review results, and decide when the task is complete.
Temporal only sees the higher-level execution state: started, waiting, retried, failed, or completed. This preserves agent autonomy, but gives Temporal relatively coarse observability unless SparrowX explicitly exposes internal checkpoints.
For SparrowX, the boundary is simple: Embabel owns the agent loop; Temporal makes that loop durable.
Pattern B — Internal Orchestration in SparrowX

Pattern B moves durability inside the agent execution. Instead of Temporal treating the whole Embabel agent as one opaque operation, important reasoning and tool-execution boundaries become individually recoverable steps.
Temporal + Embabel
Step 1: Interpret mission
Step 2: Build / update plan
Step 3: Execute intsvc or docsvc capability
Step 4: Evaluate resulting evidence
Step 5: Continue, re-plan, or synthesize
↳ next step determined dynamicallyAt first this can resemble a conventional workflow: intent → planning → tool execution → synthesis. But SparrowX is not simply executing a fixed sequence. Its MissionAgent is already modeled as an Embabel graph whose route is derived from typed states—MissionRunInput → IntentState → PlanState → MissionEvidence → MissionResult—rather than a hard-coded pipeline.
The agent also works against capabilities such as document evidence, internal entity search, governance and synthesis rather than one predetermined tool chain. Embabel therefore retains responsibility for deciding which valid action becomes reachable next.
Pattern B changes where the durability boundary sits. Instead of recovering an entire mission-level agent invocation, Temporal can persist progress around smaller agent actions. If execution fails after evidence retrieval, SparrowX can recover from that boundary rather than repeating the whole reasoning run.
So Pattern B does not turn SparrowX into a static workflow. Embabel still determines the agent path; Temporal makes more of that path durable and observable.
Pattern 3 — Hybrid
SparrowX combines both styles in production: autonomous agents can run as durable black-box steps, while critical operations are exposed as smaller recoverable actions. Human approval can pause either flow, giving Temporal control and durability without reducing Embabel’s agent autonomy.
Temporal Workflow — SparrowX Composite Pattern
┌─ Step 1: Interpret / Plan Mission ──────────────────────────┐
│ Fine-grained execution (Pattern B) │
│ Embabel: intent → planning → next action │
└───────────────────────────────────────────────────────────┘
↓
┌─ Step 2: Invoke Specialist Agent ──────────────────────────┐
│ Black-box execution (Pattern A) │
│ Agent runs its own Embabel reasoning loop internally │
└───────────────────────────────────────────────────────────┘
↓
┌─ Step 3: Wait for Human Approval ──────────────────────────┐
│ Temporal durable wait / signal │
│ Mission can pause and resume without restarting │
└───────────────────────────────────────────────────────────┘
↓
┌─ Step 4: Continue Fine-Grained Agent Execution ─────────────┐
│ Pattern B │
│ Planning, intsvc/docsvc calls, review and synthesis │
│ can be checkpointed and recovered independently │
└───────────────────────────────────────────────────────────┘
↓
┌─ Step 5: Complete Mission ─────────────────────────────────┐
│ Build grounded result + citations │
│ Temporal records completion and final workflow state │
└───────────────────────────────────────────────────────────┘| Dimension | Pattern A — External | Pattern B — Internal | Hybrid — Composite |
|---|---|---|---|
| Agent autonomy | Fully preserved | Preserved through dynamic routing | Preserved with selective control points |
| Observability | Coarse, mission/agent level | Fine-grained, action/tool level | Configurable by execution path |
| Fault recovery | Retry whole agent step | Recover individual actions | Mix of coarse and fine-grained recovery |
| Durability | Mission-level | Step-level | Applied where needed |
| Complexity | Low | High | Medium–High |
| Flexibility | High | High if routing stays dynamic | High |
| HITL support | Between agent executions | Between internal steps | Native across both styles |
| Best fit | Simple autonomous agents | Critical, highly observable flows | SparrowX production default |
Chapter 2: Core Mechanism of Durable Orchestration in SparrowX
Chapter 1 covered how Temporal and Embabel can work together without reducing SparrowX agents to fixed workflows. The next question is what Temporal contributes beneath the agent runtime.
Step → Persist → Resume
At its core, durable execution separates agent progress from the life of a single process. Important operations are recorded outside the running service so a SparrowX mission can recover without starting again from the beginning.
① Step — define durable boundaries
SparrowX identifies meaningful operations such as agent actions, intsvc or docsvc calls, human-approval waits, and other external work. In Temporal, these boundaries are typically represented by Workflow operations and Activities.
② Persist — record completed work
Temporal records workflow decisions and Activity outcomes in its durable Event History. SparrowX can additionally persist application-level mission checkpoints in PostgreSQL where richer agent state needs to survive independently of the workflow engine.
This separates two concerns: Temporal preserves execution history; SparrowX preserves domain and agent state.
③ Replay — reconstruct and continue
After a worker crash, restart, or long pause, Temporal rebuilds the Workflow from its Event History. Operations that already completed are resolved from recorded history rather than executed again, and execution continues from the outstanding work.
For SparrowX, this means a completed docsvc retrieval, intsvc lookup, or other durable Activity does not need to be repeated simply because the worker disappeared. Embabel can continue operating from the recovered mission state while Temporal restores the execution path around it.
The resulting model is:
Embabel decides what the agent should do
↓
Temporal executes durable boundaries
↓
Event History records execution progress
↓
SparrowX checkpoints preserve agent/domain state
↓
Failure
↓
Replay history + restore state
↓
Continue remaining workThe important distinction is that replay is not rerunning the whole agent. Temporal reconstructs completed workflow progress from history, allowing SparrowX to resume from a durable boundary while avoiding unnecessary repeated tool calls, side effects, and LLM usage.
Scenario 1: Crash Recovery — Resume Instead of Restarting
Suppose a SparrowX mission has been running for 20 minutes, finishes eight durable operations, then the worker fails during the ninth.
Without durable orchestration: SparrowX would need to restart the mission, reconstruct execution from stored traces, or implement its own recovery system. Restarting may repeat LLM calls, intsvc/docsvc requests, and other expensive work.
With Temporal: completed Activities are already represented in Workflow history. During recovery, Temporal replays the Workflow using those recorded results and continues from the unfinished operation instead of recomputing everything that came before it.
Steps 1–8 completed
↓
Worker crashes during Step 9
↓
Temporal replays Workflow history
↓
Steps 1–8 resolve from recorded results
↓
Step 9 resumes / retriesThis is fundamentally different from restoring an agent conversation and asking the LLM to continue. A trace helps the model understand what happened; durable execution tells the runtime what has already completed.
Two differences matter in SparrowX:
- Avoid unnecessary LLM and tool cost — if an LLM or service call completed as a recorded Activity, recovery does not need to invoke it again simply to reconstruct progress.
- Infrastructure-level recovery — Temporal determines completed work from Workflow history rather than relying on Embabel or the LLM to infer which operations should be repeated.
There is one important production detail: external side effects should still be idempotent. An Activity can be retried if failure occurs around the boundary between performing the external operation and recording its completion. Temporal provides durable recovery; idempotency prevents a retry from creating duplicate effects.
For SparrowX, the result is simple: a process failure should interrupt a mission, not erase its progress.
Scenario 2: Long-Running Missions — Outliving the Worker
SparrowX missions should not depend on one JVM, pod, or worker remaining alive for their entire duration. Research tasks, approval-driven workflows, and other long-running missions may continue far beyond the lifetime of the process that started them.
The solution is to keep execution state outside the worker. Temporal stores durable workflow history, while SparrowX can persist richer mission and checkpoint state in PostgreSQL. Embabel workers then become replaceable execution hosts rather than owners of mission progress.
Temporal + SparrowX Durable State
Worker A Worker B Worker C
──────── ──────── ────────
Execute Steps 1–3 → Replay history → Replay history
Persist progress Continue Steps 4–6 Continue Step 7
↓ ↓ ↓
Pod terminated HITL wait: 3 days Mission completeIf one worker disappears, another can continue the same Temporal Workflow using recorded history instead of restarting the mission. A human-approval wait can also remain durable for hours or days without keeping the original worker alive.
The key architectural shift is that the process becomes temporary, while the mission remains durable. Embabel continues to drive agent execution, but Temporal ensures that execution can survive worker restarts, scaling events, deployments, and infrastructure failures.
Scenario 3: Human-in-the-Loop — Durable Waiting Without Holding a Worker
SparrowX missions may need human input before continuing: approving a sensitive action, validating evidence, or resolving an escalation. Those pauses can last hours or days, far longer than any individual worker should remain occupied.
Without durable orchestration: SparrowX would need to serialize mission state, persist it, release the process, receive an external callback, restore the state, and reconstruct execution manually.
With Temporal: the Workflow can enter a durable wait using a Signal, Update, timer, or Workflow.await. Temporal records the waiting state while the worker is released. No JVM thread or pod needs to remain blocked while approval is pending.
SparrowX executes Steps 1–3
│
▼
Step 4: Request Human Approval
│
├── Temporal records waiting state
│ Worker is released
│
│ ... 3 days pass ...
│
├── Approval Signal received
│
▼
Temporal restores Workflow state
│
▼
Embabel continues from the approved path
│
▼
Step 5 onwardCompleted work is reconstructed from Temporal's Workflow history, while SparrowX's persisted mission state remains available to Embabel. The approval event simply unlocks the next valid part of the mission.
The result is that a SparrowX mission can wait for human input for days without keeping an agent process alive, then continue from the same durable execution state once the response arrives.
Scenario 4: Stability — Isolate Failures and Retry Only What Broke
SparrowX depends on external systems such as LLM providers, intsvc, docsvc, databases, and other APIs. At production scale, transient failures are expected. The goal is to stop one failed call from invalidating the entire mission.
Without durable orchestration: retry logic ends up scattered throughout agent code—backoff, retryability checks, attempt limits, and recovery rules mixed into tool and service implementations.
With Temporal: Activities can use declarative retry policies. If one external call fails, Temporal retries that Activity independently while previously completed work remains intact.
Step 1 ✔ → Step 2 ✔ → Step 3 ✘ ↻ ↻ ✔ → Step 4 ✔ → DoneFor SparrowX, this keeps infrastructure concerns outside Embabel's reasoning logic. Embabel decides what action should happen next; Temporal decides how that action should survive transient infrastructure failure.
The result is localized recovery instead of mission-wide failure: a temporary docsvc, intsvc, database, or LLM error can be retried without replaying unrelated work.
Scenario 5: Observability — Event History + Visibility + LLM Tracing
Most teams today rely on tracing tools (Langfuse, Braintrust) for agent observability — tracking prompts, completions, token usage, and latency. This is valuable, but in my view it's only half the picture. Production agent observability should have two complementary layers:
Layer 1: Execution-level observability — from the orchestration engine (Event History + Visibility)
Event History records every step's start/complete/fail/retry, Signal send/receive, timing, and return values — a complete audit trail of execution flow. On top of this, a Visibility layer provides SQL-like queries across all workflows (e.g., "find all Failed workflows for customer C123"). This tells you what happened during execution: which steps ran, which failed, how long the wait was, how many retries occurred. (Temporal Events Docs)
Layer 2: Inference-level observability — from LLM tracing tools (Langfuse/Braintrust)
This records prompt/completion content, token usage + cost, latency, and evaluation scores. This tells you how the agent reasoned: what it was asked, what it answered, how much it cost, and whether the output quality was good. It does NOT record workflow execution state, retry logic, or Signal handling.
Connecting the two layers
The two layers can be connected via OpenTelemetry and shared trace_id, enabling full-stack agent observability:
- Agent output quality is poor → check Langfuse for prompt/completion to debug reasoning
- Agent execution stuck/failed → check Temporal UI for execution state and retry logs
- Jump between them via trace correlation — from Temporal's Activity directly into Langfuse to see the specific LLM call content
The Agent Loop Is Only the Beginning
Building an agent is relatively easy. Building an agentic system that can reason, recover, wait, retry, and survive real production failures is a different engineering problem. SparrowX makes that boundary explicit: agenticsvc owns the reasoning and orchestration of the mission, while intsvc and docsvc provide the structured internal knowledge and document evidence the agent acts on. Embabel determines what should happen next; durable orchestration ensures that progress is not lost when the infrastructure underneath it changes or fails. The result is not just an agent loop, but a system capable of carrying that loop reliably from intent to outcome.