Skip to content

Add a workflow-as-agent human-in-the-loop example resuming tool approval across the NewAgent boundary - #744

Open
PratikDhanave wants to merge 3 commits into
microsoft:mainfrom
PratikDhanaveFork:workflow-as-agent-hitl-example
Open

Add a workflow-as-agent human-in-the-loop example resuming tool approval across the NewAgent boundary#744
PratikDhanave wants to merge 3 commits into
microsoft:mainfrom
PratikDhanaveFork:workflow-as-agent-hitl-example

Conversation

@PratikDhanave

Copy link
Copy Markdown
Contributor

What

Adds examples/03-workflows/agents/workflow_as_an_agent_human_in_the_loop and registers it in cmd/verifyexamples.

The example builds a sequential workflow that hosts a single agent whose function tool is wrapped with tool.ApprovalRequiredFunc, then wraps the whole workflow as an agent via agentworkflow.NewAgent. It:

  1. Runs the wrapped agent on a single agent.Session.
  2. Iterates the response contents to detect the surfaced *message.ToolApprovalRequestContent.
  3. Prompts the user to approve/deny (via the shared demo.UserInputRequest helper, mirroring the approval-detail printing used by group_chat_tool_approval).
  4. Re-runs the SAME session passing request.CreateResponse(approved, "") so agentworkflow matches it against the pending request and routes it back into the workflow as a workflow.ExternalResponse to complete the turn.

Why

The agentworkflow package doc already documents that pending workflow RequestInfoEvents are surfaced as agent ResponseUpdates carrying request content, resumable by including message.ToolApprovalResponseContent in the next agent run. This path is exercised by TestNew_ApprovalRoundtrip_ResponseIsProcessed, but no runnable example demonstrated it: the existing workflow_as_an_agent sample wraps a concurrent bilingual workflow with no approval, and group_chat_tool_approval handles approval at the RAW workflow level (inproc.RunStreaming + run.SendResponse), NOT across the NewAgent agent boundary.

This closes the parity gap with the Python SDK's workflow_as_agent_human_in_the_loop.py, which demonstrates the same resume-across-the-agent-boundary flow. It keeps the Go samples aligned with the cross-SDK "workflow as an agent" HITL story.

Testing

  • go build ./...
  • go vet ./cmd/verifyexamples/... ./examples/03-workflows/agents/...
  • go test ./cmd/verifyexamples/... (registration compiles and validates)

The underlying resume behavior is already covered by TestNew_ApprovalRoundtrip_ResponseIsProcessed in workflow/agentworkflow/workflow_test.go; this change is example-only and touches no production code.

Copilot AI review requested due to automatic review settings July 24, 2026 04:01
@PratikDhanave
PratikDhanave requested a review from a team as a code owner July 24, 2026 04:01

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new Go example demonstrating a human-in-the-loop tool approval flow when a workflow is wrapped as an agent (resuming approval responses across the agentworkflow.NewAgent boundary), and registers it with the example verifier so it can be exercised alongside other workflow samples.

Changes:

  • Adds examples/03-workflows/agents/workflow_as_an_agent_human_in_the_loop showing tool approval request detection and resume via request.CreateResponse(...) on the same session.
  • Registers the new example in cmd/verifyexamples under the workflows/agents set.

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 1 comment.

File Description
examples/03-workflows/agents/workflow_as_an_agent_human_in_the_loop/main.go New runnable sample: sequential workflow wrapped as an agent, with tool approval handled via surfaced request content and resumed on the same session.
cmd/verifyexamples/examples.go Adds the new example to the workflowExamples registry for automated verification.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread cmd/verifyexamples/examples.go
@github-actions

This comment has been minimized.

@github-actions github-actions Bot added the parity-approved Go API consistency review found no parity issues label Jul 24, 2026
Add examples/03-workflows/agents/workflow_as_an_agent_human_in_the_loop
demonstrating tool approval resumed across the agentworkflow.NewAgent
boundary. A sequential workflow hosts an agent whose function tool is
wrapped with tool.ApprovalRequiredFunc; wrapping the workflow as an agent
surfaces the pending approval request as a ToolApprovalRequestContent on
the run response, and resuming the same session with the matching
ToolApprovalResponseContent routes it back into the workflow as an
external response to complete the turn.

Register the example in cmd/verifyexamples.
@PratikDhanave
PratikDhanave force-pushed the workflow-as-agent-hitl-example branch from 2fb6754 to 3611998 Compare July 24, 2026 09:30
@github-actions

This comment has been minimized.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

binary needs removing

@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Parity Review: ✅ Approved

This PR is example-only — it adds examples/03-workflows/agents/workflow_as_an_agent_human_in_the_loop/main.go and registers it in cmd/verifyexamples. No exported Go APIs or user-visible production behavior are changed.

Cross-SDK sample parity: The new example directly maps to python/samples/03-workflows/agents/workflow_as_agent_human_in_the_loop.py in the upstream microsoft/agent-framework repository, covering the same workflow-as-agent HITL resume-across-agent-boundary scenario.

No public API change: The public-api-change label is not applicable here.

Verdict: The Go example is semantically aligned with its Python counterpart. The parity-approved label is correct. No parity issues found.

Generated by Go API Consistency Review Agent · sonnet46 · 15.4 AIC · ⌖ 4.12 AIC · ⊞ 5.7K ·

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

parity-approved Go API consistency review found no parity issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants