Suppose you asked an agent to draft an email. You didn't ask it to send it, but it did anyway, just because it had permission to make that tool call.
That's the moment you stop trusting your agent.
Having the power to take an action doesn't mean an agent should take it without a human saying yes. Everyone agrees with that. The hard part is making it actually work.
I learned this the painful way. A while ago I built human-in-the-loop approvals on top of a popular AI SDK, and the agent kept doing weird things. It sent stuff without asking. It told me "done!" when nothing had happened. It forgot I had already approved something the moment I refreshed the page. I blamed the model and called it hallucination.
Then I spent some time reading the source code of Temporal Agent Kit, an open-source agent harness built on Temporal. And I realised most of my "hallucinations" were never the model's fault.
It wasn't the model. It was the plumbing.
When I went back through my old bugs, almost all of them had the same root cause: broken state.
- The agent acted without asking. My approval rule lived in the system prompt. So the model decided whether to ask. Sometimes it decided not to.
- It said "done" before anything ran. The tool result never made it back into the conversation properly. The model saw a gap and filled it with something plausible.
- It forgot approvals after a refresh. The conversation was rebuilt from the browser's copy on every request. One refresh or a second tab, and the history was different.
- It ran things twice, or got stuck. Waiting for a human meant holding a serverless function open. It timed out, retried, and ran the action again.
- It ignored my rejection. The "no" never reached the model as a clear answer.
In every case, the model was reacting quite sensibly to a history that was missing, stale or contradictory. The one thing plumbing can't fix is a model picking a wrong argument, like the wrong ID. That one really is on the model.
The fix is one idea
Here's the whole trick, in one line:
Put the approval in server-side code and state, never in the model's judgment or the browser's copy of the conversation.
That gives you three things:
- The gate lives in code. The model can only request a tool. Code decides whether it runs.
- State has one owner. The conversation and pending approvals live on the server. The browser just shows them and sends decisions.
- The wait is durable. The agent can wait for your click for five seconds or five days, and it survives crashes and redeploys in between.
That third one is where Temporal comes in. If you haven't used it: Temporal runs your code as "workflows" and records every step. If a process dies, another one picks up exactly where it stopped. I killed a worker mid-run on purpose just to watch it come back, and it's honestly a bit magical.
What happens when the agent asks for approval
The model never runs anything by itself. It just returns a structured request: "I want to call send_email with these arguments." What happens next is up to the workflow.
When you click Approve, your browser calls the server, the server sends a message (a Temporal "update") to the waiting workflow, and the workflow wakes up. If you approved, the tool runs. If you rejected, the model gets told exactly that. Either way, the next model call sees what really happened.
How Temporal Agent Kit does it
The code is MIT-licensed and surprisingly readable. Most of the logic is in one file, agent_workflow.py, and the comments explain why things are done, not just what. These are the bits that stood out to me (links point to release 0.13.0).
1. There is only one road to a tool
Every tool call goes through a dispatch function, and the very first thing it does is check the approval policy. Only after that does the tool actually run. There's no other path, so the model can't sneak around the gate.
2. The gate just... waits
The approval gate checks an allow-list first, then an optional "auto mode" (your code or another model can approve routine calls), and finally waits for a human. The waiting part is one line:
await workflow.wait_condition( lambda: runner._status.is_approval_resolved(tool_id) or runner._closed ) This isn't a sleep in a running process. The workflow is parked on the Temporal server. No server is kept busy, nothing times out, and if a worker crashes, another one resumes the wait.
3. "No" is a real answer
When you reject a call, the harness raises ToolApprovalDenied, and the model receives it as an error result with your reason:
tool 'send_email' was not approved: <your reason> The tool never runs, but the conversation keeps going. The model is never left guessing, so it has nothing to make up.
4. You can't approve the same thing twice
A validator checks every decision before it's recorded. Unknown call? Rejected. Already decided? Rejected. So double-clicks, a second tab or a retried request get an error instead of a second decision. The first decision wins.
5. Only one layer retries
This one is small but clever. The Gemini SDK retries failed requests on its own. Temporal also retries. Put the two together and one failure can turn into many hidden requests. So the adapter switches the SDK's retries off and lets Temporal handle them, where every attempt is visible.
6. Big payloads go around Temporal
Temporal limits each payload to about 2 MB, and long agent conversations get big fast. Anything over the limit is stored elsewhere (local disk or S3), and only a small reference passes through Temporal. Your code doesn't even notice.
On top of all this, every approval request and decision is logged as an event. So months later, you can still answer "who allowed this, and when?"
"Can I just ask it to change something before sending?"
This was my favourite question to dig into. Say the agent wants to send an email and you want "Yours sincerely" changed to "Yours faithfully". You might expect an Edit button. There isn't one. An approval is only approve or reject, plus an optional reason.
So you reject it, with your change as the reason. The model reads the rejection, writes a new email with the fix, and that new email comes back to you for approval. You check the actual text and approve.
One gotcha: if you type your change into the chat but click Approve on the old email, the old email goes out first. Your message only reaches the model afterwards. So for edits, always reject.
At first the missing Edit button annoyed me. Then it clicked: the text that gets sent is always exactly the text you approved. Nothing can quietly change between your click and the send.
Do you need Agent Kit for this?
No, and I think this is the most useful takeaway.
All the reliability comes from Temporal, not from Agent Kit itself. Temporal doesn't care what runs inside a step. So if you use another SDK, or even your own in-house one, you can get the same guarantees:
- Quick version: run your agent loop as a Temporal workflow, and make each model call and each tool call its own activity. Add approvals with
wait_conditionand an update, like above. - Proper version: wrap your SDK in a Temporal plugin, so your team writes normal SDK code and gets durability for free. Temporal's own integrations with the Vercel AI SDK and the OpenAI Agents SDK are good examples to copy from.
Agent Kit just saves you from building the approval rules, event stream and UI yourself.
What it won't fix
To be fair, this isn't magic.
- The model can still be wrong. If it picks a plausible but wrong amount, the gate shows it to you, but you still have to notice.
- You need to run Temporal, either on your own servers or on Temporal Cloud.
- There's a learning curve. Workflow code has to be deterministic (no random numbers or
datetime.now()inside it), and changing a workflow while old ones are still running takes some care. - Agent Kit is experimental. It shipped three releases in two weeks, with breaking changes. Temporal itself is mature; the agent harness isn't there yet.
My rule of thumb now: ask yourself "what happens if this crashes halfway?" If the answer is "eh, just run it again", you don't need any of this. If the answer is "the customer gets charged twice" or "we lose yesterday's approval", you really do.
Have you hit any of these "hallucinations" in your own agents? I'd love to hear how you solved them.
Sources: Temporal Agent Kit on GitHub (release 0.13.0, MIT license) · Temporal documentation

