Building Production AI Agents with Temporal-Based Workflow Orchestration

retool · Tech · 2025 · source Agentic: yes · promotional bias: med · source-backed · extracted with prompt 0.5.5 (schema v2)

Generated from extraction.json — do not edit by hand. Every claim cites verbatim source evidence; stated means the quote directly asserts the claim, implied means it supports it indirectly.

Problem

Domain: Enterprise agent orchestration on durable workflow infrastructure

Retool needed to launch production AI agents for enterprise users without rebuilding durability, retries, human approval, observability, state persistence, and scale infrastructure from scratch. Agents could run for minutes to hours, crash mid-task, call unreliable tools, require dangerous-action approval, and need auditability when they made bad decisions.

Constraints:

Architecture

Retool reused its Temporal-backed Workflows platform as the execution substrate for Retool Agents. Clients start agents through Retool, the backend kicks off a workflow run, Temporal queues work for agent workers, and the agent follows a loop of LLM call, optional human approval, tool execution, and continuation until completion. Temporal workflows represent deterministic state transitions and human-approval signal handling, while Temporal activities run nondeterministic LLM calls, tool calls, user code, status updates, billing, audit logs, and other side effects. Child workflows isolate sub-agent context. Temporal Signals implement human-in-the-loop approval, and event history provides a complete audit trail. Dedicated namespaces, task queues, and Datadog monitors keep agent workloads separate from standard Retool Workflows.

Diagram confidence: explicit (topology described by the source).

flowchart LR
  retool-client["Retool client"] --> retool-backend["Retool backend"]
  retool-client --> agent-chat-interface["Agent chat interface"]
  retool-backend --> temporal-cluster["Temporal cluster"]
  retool-backend --> sandbox-code-executor["Sandbox code executor"]
  temporal-cluster --> agent-worker["Agent worker"]
  temporal-cluster --> temporal-workflow-state-machine["Temporal workflow state machine"]
  temporal-cluster --> temporal-activities["Temporal activities"]
  agent-worker --> temporal-workflow-state-machine
  agent-worker --> agent-execution-block["Agent execution block"]
  agent-execution-block --> temporal-workflow-state-machine
  agent-execution-block --> temporal-activities
  temporal-workflow-state-machine --> temporal-activities
  temporal-workflow-state-machine --> human-approval-signal-handler["Human approval signal handler"]
  temporal-workflow-state-machine --> child-workflow-sub-agents["Child workflow sub-agents"]
  temporal-activities --> tool-execution-layer["Tool execution layer"]
  temporal-activities --> sandbox-code-executor
  tool-execution-layer --> human-approval-signal-handler
  human-approval-signal-handler --> retool-client
  temporal-cluster --> temporal-event-history["Temporal event history"]
  temporal-cluster --> dedicated-agent-infrastructure["Dedicated agent infrastructure"]
  dedicated-agent-infrastructure --> agent-worker
  dedicated-agent-infrastructure --> datadog-monitors["Datadog monitors"]
  temporal-event-history --> datadog-monitors
Drag to pan · scroll or use +/− to zoom · reconstructed from the source's described component topology

Components

Component Role Interacts with
Retool client Starts workflows or agents through Retool's UI/API and receives human-readable agent responses. Retool backend, Agent chat interface
Retool backend Accepts client requests, creates workflow runs, and submits orchestration work to Temporal. Retool client, Temporal cluster, Sandbox code executor
Temporal cluster Provides durable workflow execution, queues, retries, signals, event history, state persistence, and orchestration. Retool backend, Agent worker, Temporal workflow state machine, Temporal activities
Agent worker Picks up agent tasks from Temporal queues and runs the agent loop over LLM calls, approvals, tools, and completion. Temporal cluster, Temporal workflow state machine, Agent execution block
Temporal workflow state machine Represents deterministic edges, state transitions, loop continuation, wait blocks, and human-approval signal handling. Agent worker, Human approval signal handler, Temporal activities, Child workflow sub-agents
Temporal activities Execute nondeterministic side-effecting work such as LLM calls, tool calls, user code, audit logging, billing, and run status updates. Temporal workflow state machine, Tool execution layer, Sandbox code executor
Agent execution block Retool's product-level block that wraps the agent loop while still using workflow/activity concepts underneath. Agent worker, Temporal workflow state machine, Temporal activities
Tool execution layer Runs tools such as database queries, Slack messages, emails, configuration changes, money transfers, or code deployment. Temporal activities, Human approval signal handler
Human approval signal handler Pauses dangerous actions with Temporal Signals and resumes when users approve from a device. Temporal workflow state machine, Tool execution layer, Retool client
Child workflow sub-agents Run independent sub-agents with separate event history, timeout policy, and retry policy to protect parent context. Temporal workflow state machine
Temporal event history Records tool calls, results, decisions, and execution trace for observability and auditability. Temporal cluster, Datadog monitors
Sandbox code executor Runs customer-sensitive code and block logic under Retool's workflow execution model. Retool backend, Temporal activities
Dedicated agent infrastructure Separates agent namespaces, task queues, and Datadog monitors from regular Retool Workflows for independent scaling and profiles. Temporal cluster, Agent worker, Datadog monitors
Datadog monitors Observe agent-specific queues and workloads without conflating them with standard workflow workloads. Dedicated agent infrastructure, Temporal event history
Agent chat interface Displays the final human-readable response after the workflow completes. Retool client

Data flow

A Retool client starts an agent. The Retool backend creates a workflow run and passes it to a Temporal queue. Agent workers pick up the task and execute a dynamic state machine: call the LLM, pause for human approval when required, execute tools as Temporal activities, then loop until done. If a tool action needs approval, the workflow edge registers a signal handler and waits on a promise race between an approval signal and a sleep timer. Tool failures use activity retries with configurable backoff. Sub-agents run as child workflows with their own event history, timeout policy, and retry policy. When the workflow completes, Retool returns a human-readable response to the agent chat UI.

5 supporting quotes
“whenever they spin off an agent, we kick off a workflow run. We pass that off to Temporal queue for the agent worker to pick up the task”transcript, stated
“You have an LLM call, if you need human approval, you ask a human in the loop. You execute tools and then you loop until it's done.”transcript, stated
“Temporal workflows being used for state transitions, for agent loops and human approval, and Temporal activities being used for LM calls and tool calls.”transcript, stated
“Temporal signals to pause workflows indefinitely with zero resources and resume when the user approves. And then finally observability, you can use Temporal's event history to get a complete audit trail of every agent decision. So while the best”transcript, stated
“when the workflow completes, we actually return the human-readable response, and that's what you see in the agent chat at Retool.”transcript, stated

Why this architecture

Retool already had Temporal-based workflow infrastructure that matched the hard parts of production agents: durable execution, retryable tools, human approval, observability, state persistence, and long-running loops. Reusing those primitives let a small team avoid rebuilding state persistence, crash recovery, retries, human-loop infrastructure, and auditability, while preserving go-to-market velocity. Static Retool Workflows can use a V3 preplanned DAG for speed/cost, but dynamic agents use the same conceptual stack with a V2-like per-iteration activity grouping because the loop can continue until the task is complete.

4 supporting quotes
“every single challenge I propose actually maps to workflow capability that we've already built with Temporal and Retool workflows.”transcript, stated
“Temporal already covers all of checks every box, covers all of this while maintaining the go-to-market velocity that we need.”transcript, stated
“infrastructure we built for Retool workflows. And so let's talk about how we build agents. Surprise, it's actually just a workflow underneath the hood. >> [laughter] >> So let's talk about what that actually means. Under the hood for Retool agents, we actually just use Retool”transcript, stated
“We actually have dynamic state machines that could go on theoretically forever until the task is completed. So, while those two differences matter, so for V3, we can actually plan that up front and optimize for activities. In agent execution, it's closer to”transcript, stated

Models used: LLM agent model

Scale

Alternatives considered (roads not taken)

Build an in-house Temporal-like queue with PG Boss and AWS Lambda

Rejected because: The initial in-house approach hit scaling limits around 15-minute execution, while Temporal supported weeks-long execution and enterprise guarantees.

“initially with our small team of two to three, and we built an in-house version of Temporal Queue with PG Boss and AWS Lambda. But we ran into scaling problems pretty quickly. I think at that point when we created it, it only ran for about 15 minutes, but now with Temporal we can run it”transcript, stated
“it only ran for about 15 minutes, but now with Temporal we can run it for weeks on end. And so, when we're looking for this, the two top order concerns for our team were operational burden and go-to-market velocity. And when we think about all of these”transcript, stated

Execute every workflow block as its own Temporal activity

Rejected because: This V1 implementation was simple but activity overhead and per-action pricing became too costly and slow at Retool's scale.

“take this graph, we perform a topological sort, and then we execute each block one by one. Each block runs in its own activity. And this is great. This worked when we initially started, but we ran into two major issues um with scale. And that is cost”transcript, stated
“block runs in its own activity. And this is great. This worked when we initially started, but we ran into two major issues um with scale. And that is cost and latency. One, while Temporal overhead is pretty slim per block execution for activities, it adds up pretty quickly. If you assume”transcript, stated

Group workflow activities only at runtime

Rejected because: The V2 eager engine reduced activity count but blocked independent branches when human approval or wait blocks paused a branch.

“with V2, since we're now grouping activities that don't require their own into a block at iteration runtime, we end up with four activities instead”transcript, stated
“mentioned before, uh since we're doing this at runtime, we actually end up blocking branches when the human uh approval is required. And so, we want to be able to make execution faster by parallelizing as much as we can. And that enters our final V3 architecture, which we use today to have one”transcript, stated

Use static V3 DAG preplanning for agent execution

Rejected because: Static DAG optimization fits Retool Workflows, but agents are dynamic state machines that can run until completion and are closer to V2 activity grouping.

“in V3 that we have static DAGs that we can plan for up front. However, with agents, it's different. We actually have dynamic state machines that could go on theoretically forever until the task is completed. So, while those two differences matter, so for V3,”transcript, stated
“In agent execution, it's closer to our V2 architecture, where we have every agent iteration of tool calls in one activity.”transcript, stated

Build human-in-the-loop infrastructure from scratch

Rejected because: A custom implementation would require polling, webhooks, state, timeouts, crash recovery, and concurrent approvals; Temporal Signals gave Retool the same capability in about 50 lines.

3 supporting quotes
“You might need a polling service, a webhook handler, state database, timeout manager, crash recovery, concurrent approval handling.”transcript, stated
“webhook handler, state database, timeout manager, crash recovery, concurrent approval handling. This takes weeks of engineering to build from scratch. But we did it in one and we did it in 50 lines with Temporal Signals. So [clears throat] this is a simplification of what”transcript, stated
“recovery, concurrent approval handling. This takes weeks of engineering to build from scratch. But we did it in one and we did it in 50 lines with Temporal Signals. So [clears throat] this is a simplification of what is actually in our code base, but when we implemented human loop, we”transcript, stated

Run agents on the same Temporal namespace and task queues as regular workflows

Rejected because: Retool separated agent infrastructure so agent workloads could scale independently and use different timeout/execution profiles.

3 supporting quotes
“matters is we do have agent dedicated infrastructure. We actually separate our Temporal namespaces, task queues, um and DataDog monitors to be able to make sure that agent workflows don't compete with Retool workflow workloads. So this allows us to independently scale agent workers without touching”transcript, stated
“task queues, um and DataDog monitors to be able to make sure that agent workflows don't compete with Retool workflow workloads. So this allows us to independently scale agent workers without touching uh Retool workflows, and then also it has different profiles. Agents often need longer execution”transcript, stated
“workflows, and then also it has different profiles. Agents often need longer execution windows and timeout policies than workflows. So all of this being said, um traditional infrastructure that would create agents from scratch have a lot of moving pieces. We'd have to build a state persistence”transcript, stated

Patterns

durable-execution (orchestration)

Retool uses Temporal workflows and queues so long-running agent loops survive crashes, preserve state, and resume execution after approval or failure recovery.

3 supporting quotes
“Some of the main ones to call out here are for long-running agents, you need durable execution. They can run for minutes to hours, but things can fail unexpectedly halfway through and they can crash.”transcript, stated
“Long-running loops, Temporal already guarantees durable execution out of the box. Context management, we can actually use child workflows to spawn independent sub-agents to not pollute the parent context.”transcript, stated
“And then finally, we need to be able to have state persistence so that workflows can survive any failure. And think about this problem, uh it's a lot.”transcript, stated

tool-use-orchestration (agent-loop)

The agent loop is implemented as workflow state transitions around activities for LLM calls and tool calls, looping until the task is complete.

3 supporting quotes
“It uses an LLM to decide what to do next. Two, it calls tools to be able to execute what the user desires.”transcript, stated
“You can think of Temporal workflows being used for state transitions, for agent loops and human approval, and Temporal activities being used for LM calls and tool calls. And so, to try and drive the nail across a little bit more, here's a simple diagram of how the agent architecture works.”transcript, stated
“the exact same state machine of those four steps that I mentioned earlier.”transcript, stated

human-in-the-loop-gate (approval)

Dangerous agent actions use Temporal Signals and workflow conditions to pause, wait for approval, and resume from any device.

3 supporting quotes
“the human-in-the-loop problems, agents can do a lot of different things, a lot of really powerful things, but dangerous actions need human review. I don't think I need to state this um too often because I think you guys have heard all of the nightmare stories that have happened in production,”transcript, stated
“with Temporal Signals. So [clears throat] this is a simplification of what is actually in our code base, but when we implemented human loop, we just used Temporal Signals. So at the workflow edges, we register a signal handler, and in between activities when tools are being called, if human”transcript, stated
“resume execution anytime as long as they can kick off the signal and approve it from their device anywhere they want.”transcript, stated

observability-tracing (operations)

Temporal event history acts as an execution trace that records agent decisions, tool calls, results, and failure points for debugging and audit.

3 supporting quotes
“When the agent decides something wrong, you need to know what exactly went wrong and why.”transcript, stated
“you can use Temporal's event history to get a complete audit trail of every agent decision.”transcript, stated
“For your agent execution trace to track what went wrong and when uh what tools were called and results were uh called, then you can use the event history.”transcript, stated

agent-memory (context)

Retool uses child workflows for sub-agents so sub-agent event history, timeout policy, and retry policy do not pollute parent agent context.

3 supporting quotes
“Context management, we can actually use child workflows to spawn independent sub-agents to not pollute the parent context.”transcript, stated
“It has its own fresh event history, timeout policies, uh and retry policies”transcript, stated
“It has its own fresh event history, timeout policies, uh and retry policies, and that will allow you to manage context much easier. And then finally, for scheduled agents, we actually use uh we built this a couple years ago, so we actually use workflows.”transcript, stated

fallback-degradation (resilience)

Tool failures are handled with automatic configurable activity retries and backoff rather than failing the entire agent run immediately.

3 supporting quotes
“API calls can fail, databases can time out, and rate limits can hit.”transcript, stated
“we have activity retries that are automatic configurable with backoff that can retry when things fail.”transcript, stated
“design systems with guardrails, uh, failure, crashes, and retries in place day one.”transcript, stated

latency-optimization (workflow-engine)

Retool's V3 static DAG preplanning reduces Temporal activity count and enables independent branches to run in parallel instead of blocking on human-approval branches.

3 supporting quotes
“So instead of doing it at runtime and allocating temporal activities as we go through down the tree, we can actually pre-plan this and do this up front. So our new algorithm, we check the parents.”transcript, stated
“we have four parallelizable activity nodes in this static DAG of a workflow”transcript, stated
“we don't need to block branches that aren't dependent on each other.”transcript, stated

cost-aware-routing (workflow-engine)

The workflow engine groups blocks into fewer Temporal activities when retry/async/start boundaries permit, reducing per-action cost and latency.

3 supporting quotes
“To optimize this cost and latency, we asked one key question. Can we run multiple blocks all in the same activity?”transcript, stated
“We go from 30 activities in V1 to six, we get five times fewer activities, it's almost eight times faster, and in temporal prices, it's five times cheaper.”transcript, stated
“Uh and that saves us over $9 million a year and it's a little bit contrived, but we have 735 years of saved latency for customers overall.”transcript, stated

Tradeoffs

Core orchestration substrate

Chose Temporal for durable workflow execution over In-house PG Boss plus AWS Lambda queue.

Rationale: Temporal gave Retool durability, timeouts, retries, concurrency, state persistence, lower operational burden, and faster go-to-market than building infrastructure itself.

3 supporting quotes
“we built an in-house version of Temporal Queue with PG Boss and AWS Lambda.”transcript, stated
“it only ran for about 15 minutes, but now with Temporal we can run it for weeks on end.”transcript, stated
“the two top order concerns for our team were operational burden and go-to-market velocity.”transcript, stated

Workflow engine activity allocation

Chose V3 static DAG preplanning for workflows over V1 one-block-one-activity and V2 runtime-only eager grouping.

Rationale: Preplanning uses the static DAG to reduce activities and preserve parallel branch execution while respecting retry/async boundaries.

3 supporting quotes
“with our V1 engine, we'd actually have eight activities, one for each node.”transcript, stated
“with V2, since we're now grouping activities that don't require their own into a block at iteration runtime”transcript, stated
“we have four parallelizable activity nodes in this static DAG of a workflow”transcript, stated

Agent execution model

Chose Dynamic state machine with per-iteration activity grouping over Static DAG preplanning for each agent run.

Rationale: Agent loops can continue indefinitely and choose tools dynamically, so Retool keeps the same Temporal concepts but uses a V2-like model for agent iterations.

3 supporting quotes
“We actually have dynamic state machines that could go on theoretically forever until the task is completed.”transcript, stated
“In agent execution, it's closer to our V2 architecture, where we have every agent iteration of tool calls in one activity. But ultimately, it's the same core architecture.”transcript, stated
“But ultimately, it's the same core architecture. And this is the kind of thing I want to drive across. Although I'm telling you guys that agents are Retool workflows under the hood, these same concepts are not unique to Retool.”transcript, stated

Dangerous action approval

Chose Temporal Signals and workflow conditions over A custom polling/state/timeout/crash-recovery stack.

Rationale: Signals let workflows pause without resources and resume when approved, removing weeks of custom approval infrastructure.

3 supporting quotes
“Temporal signals to pause workflows indefinitely with zero resources and resume when the user approves.”transcript, stated
“This takes weeks of engineering to build from scratch. But we did it in one and we did it in 50 lines with Temporal Signals.”transcript, stated
“But we did it in one and we did it in 50 lines with Temporal Signals. So [clears throat] this is a simplification of what is actually in our code base, but when we implemented human loop, we just used Temporal Signals.”transcript, stated

Sub-agent context management

Chose Child workflows for sub-agents over Sharing sub-agent state inside the parent event/context history.

Rationale: Child workflows give sub-agents isolated event histories, timeouts, and retries, reducing parent-context pollution.

“child workflows to spawn independent sub-agents to not pollute the parent context.”transcript, stated
“It has its own fresh event history, timeout policies, uh and retry policies”transcript, stated

Agent infrastructure isolation

Chose Dedicated namespaces, task queues, and monitors for agents over Sharing standard workflow infrastructure directly.

Rationale: Agents need independent scaling and longer execution/timeout profiles, so they should not compete with normal Retool Workflows.

“We actually separate our Temporal namespaces, task queues, um and DataDog monitors”transcript, stated
“this allows us to independently scale agent workers without touching uh Retool workflows”transcript, stated

Gotchas (what bit them)

Agent crashes can erase multi-step progress without durable state.

Root cause: An agent may be many steps into a task with database queries and Slack messages already sent when the worker crashes.

Resolution: Run the agent loop on Temporal so workflow state and event history survive failures.

3 supporting quotes
“imagine your agent is 10 steps in a processing refund. You've already made three DB query calls, you've sent three Slack messages”transcript, stated
“the worker crashes, all the context is gone, and the user has to start over.”transcript, stated
“Long-running loops, Temporal already guarantees durable execution out of the box.”transcript, stated

Naive one-block-one-activity workflow execution becomes expensive and slow.

Root cause: Temporal adds 50-100ms overhead per activity and charges per action, so many activities multiply latency and cost.

Resolution: Group blocks into activities where retry, start, and async-completion boundaries allow it.

3 supporting quotes
“Each block runs in its own activity. And this is great. This worked when we initially started, but we ran into two major issues um with scale.”transcript, stated
“the Temporal overhead is about 50 to 100 milliseconds per activity”transcript, stated
“you get charged per action, and at scale when at Retool we have over 10 million workflow runs per day”transcript, stated

Runtime activity grouping can block independent branches.

Root cause: The V2 eager engine groups while iterating at runtime, so a human-approval/wait block can hold branches that do not depend on it.

Resolution: Pre-plan the static workflow DAG in V3 so independent activity nodes can execute in parallel.

3 supporting quotes
“we actually end up blocking branches when the human uh approval is required.”transcript, stated
“The key insight here is that we realized workflows are static DAG.”transcript, stated
“So instead of doing it at runtime and allocating temporal activities as we go through down the tree, we can actually pre-plan this and do this up front. So our new algorithm, we check the parents.”transcript, stated

Agents cannot always use the same static-DAG optimization as workflows.

Root cause: Agent execution is a dynamic state machine that can theoretically continue forever rather than a known DAG.

Resolution: Use the same Temporal primitives, but execute agents closer to the V2 model with each iteration of tool calls grouped into one activity.

“We actually have dynamic state machines that could go on theoretically forever until the task is completed.”transcript, stated
“In agent execution, it's closer to our V2 architecture, where we have every agent iteration of tool calls in one activity.”transcript, stated

Human approval is more than a button.

Root cause: Scratch implementations need polling, webhooks, state, timeouts, crash recovery, and concurrent approval handling.

Resolution: Use Temporal Signals with workflow conditions and a promise race between approval and a timer.

“You might need a polling service, a webhook handler, state database, timeout manager, crash recovery, concurrent approval handling.”transcript, stated
“all we do is uh have it have the workflow handle that state, and then we send off a workflow condition with a promise race”transcript, stated

Agent workloads can interfere with regular workflow workloads if they share infrastructure.

Root cause: Agents have longer execution windows and timeout policies than standard workflows.

Resolution: Separate Temporal namespaces, task queues, and Datadog monitors for agent infrastructure.

“make sure that agent workflows don't compete with Retool workflow workloads.”transcript, stated
“Agents often need longer execution windows and timeout policies than workflows.”transcript, stated

One-at-a-time human supervision will not scale to future agent volumes.

Root cause: Future AI agents may outnumber humans and produce hundreds of thousands of tasks and approval decisions.

Resolution: Design for guardrails, crashes, retries, and a transition from human-in-the-loop toward humans-on/out-of-the-loop.

3 supporting quotes
“AI agents will probably eventually outnumber humans on the internet”transcript, stated
“There's going to be hundreds of thousands of tasks, um, decisions that need to be approved.”transcript, stated
“Human in the loop today is just a phase, but realistically it's going to be humans on the loop or even humans out of loop eventually.”transcript, stated

Evaluation

The talk evaluates the architecture through production-scale workflow metrics and operational reasoning rather than a formal model benchmark. Retool compares V1, V2, and V3 workflow engines on activity counts, parallelism, latency, and Temporal cost. It uses Temporal event history for agent execution traces, Datadog monitors for dedicated agent infrastructure, and workflow semantics to reason about crash recovery, retries, human approval, sub-agent context isolation, and status queries.

Metrics: Activity count per workflow version. · Temporal overhead per activity. · Workflow execution latency. · Temporal per-action cost. · Workflow runs per day. · Annual cost savings. · Saved latency across customers. · Human approval code size and wait duration. · Agent-specific namespace/task-queue/monitor isolation. · Event-history trace of tools called, results, and failure points.

4 supporting quotes
“we get five times fewer activities, it's almost eight times faster, and in temporal prices, it's five times cheaper.”transcript, stated
“Uh and that saves us over $9 million a year and it's a little bit contrived, but we have 735 years of saved latency for customers overall.”transcript, stated
“you can use Temporal's event history to get a complete audit trail of every agent decision.”transcript, stated
“We actually separate our Temporal namespaces, task queues, um and DataDog monitors”transcript, stated

Outcomes

Retool reports thousands of customers and over 10 million workflow runs per day. The talk cites 50-100ms activity overhead, a 10-block workflow adding almost a second of overhead, a 30-activity to six-activity optimization, $9M/year estimated savings, 735 years of saved latency, human approval in 50 lines, 2-minute-to-years approval timers, and over 200 integrations.

4 supporting quotes
“We go from 30 activities in V1 to six, we get five times fewer activities”transcript, stated
“we actually were able to build agents in weeks, not months, with the infrastructure and the building blocks that we already created at Retool.”transcript, stated
“we actually started work on this like early 2025, and we were able to launch Retool Agents mid-2025”transcript, stated
“over 200 integrations to any service, enterprise ready, secure by default.”transcript, stated