AgentRun handle immediately. Poll Status while waiting, optionally call Cancel, wait on Done(), then Get() for the result. Uses WithApprovalHandler so tool calls can be approved interactively on stdin — same semantics as a blocking Run + Get.
Source: examples/agent_with_nonblocking_run/
What it demonstrates
Runreturning anAgentRunhandle immediately- Polling
AgentRun.Statuswhile the run is in progress AgentRun.Cancelto stop the run (demo: after ~10s if still running — e.g. waiting on approval)- Waiting on
AgentRun.Done(), thenGet() WithApprovalHandlerfor tool approval during the run
AgentRun method table. AgentStream shares Status / Cancel / Done / Get and adds Events — see Streaming.
Run
Fromexamples/:
y or n at the approval prompt. If you wait ~10s without answering, the example calls Cancel.
Key code
Get context only unblocks the waiter — use AgentRun.Cancel to cancel the agent run itself.
On the Temporal runtime, persist runID before waiting. After a process crash, reconnect with GetAgentRun and call Get again — see Durable Execution.
The approval handler receives *agent.ApprovalRequest and calls req.Respond(agent.ApprovalStatusApproved) or Rejected. See Approvals for stream-based approval with Stream.
Expected output
n rejects the tool call and the agent replies without that result. Leaving the prompt unanswered long enough triggers Cancel and a cancelled/failed finish path.
Learn more
Run
AgentRun — Get, Done, Status, Cancel, GetAgentRun
Durable Execution
Reconnect a Run after crash with GetAgentRun
Approvals
Policies, handlers, and stream events