Skip to content

Long-Poll Signaling in Temporal: Synchronizing Asynchronous Human Approvals with LLM Execution Trees

As autonomous AI agents navigate complex multi-step execution trees, introducing human approvals creates a fundamental timing mismatch between millisecond LLM calls and multi-hour human response times

@
Aug 13, 20266 min read

s autonomous AI agents navigate complex multi-step execution trees, introducing human approvals creates a fundamental timing mismatch between millisecond LLM calls and multi-hour human response times. By leveraging Temporal's durable execution model, long-poll signaling, and deterministic state management, developers can effortlessly synchronize human intervention with persistent agent workflows.

Long-Poll Signaling in Temporal: Synchronizing Asynchronous Human Approvals with LLM Execution Trees

The High-Stakes Friction in Autonomous Execution

Large Language Model (LLM) agents are rapidly evolving from simple single-prompt completion endpoints into sophisticated multi-step execution trees. Modern agent architectures—ranging from Model Context Protocol (MCP) tool orchestrators to tree-of-thought planners—branch recursively as they evaluate choices, run tools, and refine context. However, when an agent reaches a high-risk leaf node—such as executing arbitrary database migrations, sending financial transactions, or deploying production code—fully autonomous execution becomes a liability.

To bridge this gap, engineers implement Human-in-the-Loop (HITL) checkpoints. Yet, bridging the sub-second world of token streaming with the human world of Slack approvals, email notifications, and coffee breaks creates a profound architectural dilemma. Humans do not operate on HTTP timeout thresholds. A reviewer might respond in three seconds, three hours, or three days.

In traditional microservice architectures, keeping an HTTP connection open while waiting for a human is impossible, while naive polling databases for approval status leads to race conditions, worker memory leaks, and state loss when pods restart or deploy. As highlighted in recent analysis on building resilient agentic workflows with Temporal, traditional short-lived agent frameworks break down under long-running operational demands. What agentic systems truly require is an infrastructure mechanism that can sleep indefinitely without consuming compute resources, while remaining instantly responsive when human validation arrives.

Enter Temporal: Signals, Queries, and Long-Polling Mechanics

Temporal solves the long-running execution problem through its durable execution model. Instead of storing ephemeral state in worker memory or orchestrating state machines across dispersed Redis caches, Temporal persists workflow execution state as an event history.

When an LLM execution tree encounters a human approval node, Temporal allows the workflow to safely pause using deterministic wait conditions. During this paused state:

- Compute resources are completely freed up (zero CPU and memory overhead on worker nodes). - Workflow state remains fully durable and immune to process crashes, serverless restarts, or cluster rebalances, a core advantage documented in guides on durable AI agent architecture. - The execution tree maintains its exact point of evaluation in history.

To bridge the external world (such as a frontend dashboard, a Slack app, or an MCP client) with the paused workflow, Temporal provides two primary primitives: Signals and Queries. A Signal is an asynchronous, write-only event pushed directly into a running workflow, while a Query provides a synchronous read-only view of current workflow state.

When external web clients or frontend review portals need real-time updates without hammering backend endpoints, long-poll signaling comes into play. The client initiates a request that long-polls for state changes via workflow queries or handlers. Once a human clicks "Approve" or "Reject" on the review dashboard, the system fires a Temporal Signal to the target Workflow ID, immediately resuming the LLM execution tree.

Designing the Approval Architecture

Let's explore how long-poll signaling integrates with an LLM execution tree during a human approval cycle.

`` [LLM Execution Tree Node] | Requires High-Risk Tool Execution | +-----------v-----------+ | Pause Workflow via | | workflow.wait_condition| +-----------+----------+ | Waiting for Signal... | +--------------+--------------+ | | [User Reviews UI] [Durable Timer (e.g. 24h)] | | Emits Signal: Timeout Triggered: approve_action Cancel / Fallback Path | | +--------------+--------------+ | +-----------v-----------+ | Resume Execution Tree | | Pass Human Feedback | +-----------------------+ ``

1. Halting the Execution Branch

When an LLM agent evaluates a prompt and decides to trigger a tool marked as requiring approval (for example, in a Human-in-the-Loop MCP workflow), the workflow pauses state progression.

In Python, this is implemented using workflow.wait_condition():

```python from datetime import timedelta from temporalio import workflow

@workflow.defn class AgentExecutionWorkflow: def init(self): self._approval_status = None self._human_feedback = ""

@workflow.signal def submit_approval(self, status: str, feedback: str = ""): self._approval_status = status self._human_feedback = feedback

@workflow.run async def run(self, agent_prompt: str): # Step 1: LLM generates execution plan plan = await workflow.execute_activity( generate_plan_activity, agent_prompt, start_to_close_timeout=timedelta(minutes=2) )

# Step 2: Check if execution plan contains sensitive action if plan.requires_approval: # Yield execution until signal is received or timeout occurs await workflow.wait_condition( lambda: self._approval_status is not None, timeout=timedelta(hours=24) )

if self._approval_status == "REJECTED": # Re-feed feedback into LLM context tree to alter course return await workflow.execute_activity( replan_activity, self._human_feedback, start_to_close_timeout=timedelta(minutes=2) )

# Step 3: Proceed with safe execution return await workflow.execute_activity(execute_tool_activity, plan) ```

As detailed in Temporal's Python Human-in-the-Loop documentation, this model ensures that waiting for human feedback is treated as a first-class control flow operation.

2. Long-Polling and Querying State from the Frontend

While the workflow waits, the user-facing web dashboard needs to display pending approvals without inundating the database with continuous poll queries.

By querying the Temporal workflow's state or subscribing through long-polling API proxies, the client UI retrieves the exact state of the agent's decision tree, including generated context, proposed parameters, and rationale. When the human reviewer inspects the pending item and submits their decision, the backend calls the Temporal client SDK:

``python await temporal_client.get_workflow_handle(workflow_id).signal( AgentExecutionWorkflow.submit_approval, args=["APPROVED", "LGTM! Proceed with deployment."] ) ``

Handling Edge Cases: Deadlines, Rejections, and Reinjection

In production AI systems, asynchronous human signaling introduces operational edge cases that must be managed deterministically:

1. Approval Deadlines and Timeouts: What if the assigned human reviewer is out of the office? By combining workflow.wait_condition with durable timers, workflows can specify fallback behavior after a defined duration (e.g., automatically canceling the high-risk action, escalating to a secondary channel, or triggering a graceful fallback path). 2. Context Reinjection on Rejection: A human approval step isn't just a binary gate; it's a prompt engineering opportunity. If a reviewer rejects an action and adds notes ("Do not alter the user database schema; use a temporary staging table instead"), the workflow reinjects this feedback directly into the agent's context window. The agent then re-evaluates its execution tree with the corrected parameters. 3. Process Resiliency Across Deployments: If your agent system undergoes a code deployment or worker crash while waiting on human feedback, Temporal's event history guarantees that when the worker recovers, the workflow resumes precisely at the wait_condition statement without re-running previous LLM calls.

As explored across Temporal's AI Engineering Patterns and community case studies on durable execution for production agents, decoupling execution logic from execution persistence is what makes agentic AI truly enterprise-ready.

Bridging the Gap to Autonomous Systems

Building enterprise-grade AI agents requires reconciling the speed of generative models with the deliberate, non-deterministic pace of human oversight. Trying to force human-in-the-loop approvals into short-lived HTTP paradigms results in fragile, state-losing architectures.

By leveraging Temporal's long-poll signaling and durable execution, engineers can build resilient LLM execution trees that hold state securely across arbitrary timescales. Whether an approval arrives in three seconds or three days, your agent remains poised, precise, and ready to act.

Did you enjoy this article?

Recommend it — Standard Reader surfaces well-loved writing to more readers across the network.

Across the AtmosphereDiscussions