Files
wehub-resource-sync e071084ebe
govulncheck / govulncheck (push) Has been cancelled
Lint / golangci-lint (push) Has been cancelled
Run Tests / Unit Tests (push) Has been cancelled
Run Tests / Etcd Integration Tests (push) Has been cancelled
Harness (E2E) / Harnesses (mock LLM) (push) Has been cancelled
Harness (E2E) / Provider harnesses (live LLM conformance) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:40:33 +08:00

45 lines
1.8 KiB
Markdown

# Agent Human Input Pause/Resume
Agents can pause a durable run when the model needs a human decision before it
can continue. This keeps the services → agents → workflows lifecycle in one
runtime: services expose tools, the agent decides it needs operator input, and
the same checkpointed run resumes once that input arrives.
## Pattern
```go
cp := flow.StoreCheckpoint(nil, "deploy-agent")
ag := agent.New(
agent.Name("deploy-agent"),
agent.WithCheckpoint(cp),
)
resp, err := ag.Ask(ctx, "Deploy the service")
if err != nil {
// If the model called the built-in request_input tool, the run is saved as
// paused/input-required instead of losing state or completing early.
pending, _ := agent.Pending(ctx, ag)
runID := pending[0].ID
// Later, after an operator supplies the missing answer, the same run ID
// continues with the original prompt, human input, memory, and completed
// tool history intact.
resp, err = agent.ResumeInput(ctx, ag, runID, "Deploy to us-east-1")
}
_ = resp
```
The model sees a built-in `request_input` tool with a `prompt` argument. When it
calls that tool, Go Micro persists the run with status `paused` and stage
`input-required`. Plain `agent.Resume` continues to support completed, failed,
and approval-paused runs; input-required runs are resumed with
`agent.ResumeInput` so the human response is explicit.
## Cancellation and deadlines
`ResumeInput` uses the caller's `context.Context` for checkpoint reads, writes,
and the resumed model/tool turn. If the context is canceled or its deadline
expires before the resume is committed, the call returns the context error and
the checkpointed run remains `paused` at `input-required`; list it with
`agent.Pending` and retry with a fresh context once the operator is ready.