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 2 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 2 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

Copy link
Copy Markdown
Contributor

Parity Review: PR #744

Summary: This PR adds a new example examples/03-workflows/agents/workflow_as_an_agent_human_in_the_loop/main.go and a corresponding entry in cmd/verifyexamples/examples.go. No exported Go APIs are introduced or changed.

Scope: Example-only addition — no public API surface changes.

Upstream parity check:

  • Python: python/samples/03-workflows/agents/workflow_as_agent_human_in_the_loop.py exists (uses a custom escalation pattern via ReviewerWithHumanInTheLoop executor). Additionally, python/samples/03-workflows/tool-approval/ contains sequential_builder_tool_approval.py, concurrent_builder_tool_approval.py, and group_chat_builder_tool_approval.py — covering the tool-approval-in-workflow pattern.
  • .NET: dotnet/samples/03-workflows/Agents/GroupChatToolApproval/ and dotnet/samples/03-workflows/HumanInTheLoop/ cover analogous scenarios.

The Go example specifically demonstrates the combination of workflow-as-agent with tool.ApprovalRequiredFunc / ToolApprovalRequestContent and session-based resumption across the NewAgent boundary. This aligns semantically with the upstream tool-approval workflow samples and HITL patterns, following Go idioms.

Verdict: ✅ No parity issues found. The example scenario has clear upstream equivalents. The existing parity-approved label is appropriate. No public-api-change label is needed since no exported API surface was modified.

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • awmgmcpg

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "awmgmcpg"

See Network Configuration for more information.

Generated by Go API Consistency Review Agent · 44.3 AIC · ⌖ 5.62 AIC · ⊞ 5.9K ·

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

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