Skip to content

.NET: Add declarative HttpRequestAction sample#5572

Merged
peibekwe merged 10 commits intomainfrom
peibekwe/declarative-openapi-tool
Apr 29, 2026
Merged

.NET: Add declarative HttpRequestAction sample#5572
peibekwe merged 10 commits intomainfrom
peibekwe/declarative-openapi-tool

Conversation

@peibekwe
Copy link
Copy Markdown
Contributor

Description

Adds a new declarative InvokeHttpRequest sample demonstrating HttpRequestAction with a multi-turn conversation. Also fixes regression on System.LastMessage behavior where user-authored text gets lost in state after AgentProvider round-tripping strips or alters TextContent.

Contribution Checklist

  • The code builds clean without any errors or warnings
  • The PR follows the Contribution Guidelines
  • All unit tests pass, and I have added new tests where possible
  • Is this a breaking change? If yes, add "[BREAKING]" prefix to the title of the PR.

Copilot AI review requested due to automatic review settings April 29, 2026 16:53
@moonbox3 moonbox3 added .NET workflows Related to Workflows in agent-framework labels Apr 29, 2026
Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

Automated Code Review

Reviewers: 4 | Confidence: 86%

✓ Correctness

The PR introduces a MergeForLastMessage extension method to preserve original text content while keeping server-side media references when setting System.LastMessage. It also reorders ExecuteAsync in RootExecutor to run after SetLastMessageAsync, adds a guard in WorkflowRunner to prevent re-processing already-responded-to external requests during resume, and adds an InvokeHttpRequest sample. The core logic changes are correct: the MergeForLastMessage merge strategy is sound, the RootExecutor reordering is safe because generated ExecuteAsync implementations only initialize variables (independent of System.LastMessage) and still complete before child actions execute via SendResultMessageAsync, and the WorkflowRunner guard correctly skips replayed requests by comparing RequestId. One test claims to exercise a fallback path but doesn't actually reach it due to ChatMessage constructor behavior.

✓ Security Reliability

This PR adds HttpRequestAction support (sample + factory plumbing), introduces a MergeForLastMessage extension to preserve original user text while keeping server-side media references after round-tripping, reorders RootExecutor so System.LastMessage is set before workflow actions execute, and adds a guard in WorkflowRunner to prevent duplicate request processing. All changes are internal or shared-sample code operating on trusted data within the workflow pipeline. No injection risks, resource leaks, missing input validation, or unhandled failure modes were identified. The MergeForLastMessage method mutates the round-tripped message's Contents list in place, but this is safe since the object is freshly returned from CreateMessageAsync and consumed only once. The unit tests thoroughly cover the merge behavior.

✓ Test Coverage

The new MergeForLastMessage extension method has thorough unit test coverage with 9 test cases covering null input, text replacement, server media preservation, multiple text slots, fallback paths, server property preservation, and empty contents. However, there are two notable test coverage gaps: (1) the WorkflowRunner.cs behavioral change that filters duplicate RequestInfoEvent request IDs has zero test coverage, and (2) the RootExecutor.cs reordering — moving ExecuteAsync after SetLastMessageAsync — has no test that specifically validates the new execution order matters (existing workflow tests use mocks that return identical text, making the merge a no-op). The WorkflowRunner and WorkflowFactory are shared sample utilities without a test project, which partially explains their lack of tests. Overall, the unit tests for the core new logic are well-structured and meaningful.

✓ Design Approach

The workflow/runtime changes mostly head in the right direction, but the new MergeForLastMessage strategy is too narrow for multimodal input. It restores missing text by appending it after provider-returned content, which can reorder text relative to media and change the meaning of System.LastMessage when that message is later reused as agent input.

Suggestions

  • Consider adding a workflow-level test where the mock's CreateMessageAsync returns a message with stripped/altered text, then assert that System.LastMessage.Text still reflects the original user input. The existing DeclarativeWorkflowTest.CreateMockProvider returns identical text, making the merge a no-op and leaving the RootExecutor reordering—the key behavioral fix—effectively unvalidated at the integration level.

Automated review by peibekwe's agents

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds a new declarative InvokeHttpRequest workflow sample and fixes a regression where System.LastMessage could lose user-authored text after AgentProvider round-tripping, while preserving server-side media references.

Changes:

  • Adds InvokeHttpRequest declarative workflow sample (YAML + runner) demonstrating HttpRequestAction.
  • Introduces ChatMessage.MergeForLastMessage(...) and wires it into executors to preserve original user text in System.LastMessage while keeping server media references.
  • Updates workflow execution plumbing to pass through an IHttpRequestHandler and adjusts request tracking behavior in WorkflowRunner.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/Extensions/ChatMessageExtensionsTests.cs Adds unit tests covering merge semantics for System.LastMessage.
dotnet/src/Shared/Workflows/Execution/WorkflowRunner.cs Adjusts how request info updates externalResponse based on request id.
dotnet/src/Shared/Workflows/Execution/WorkflowFactory.cs Adds HttpRequestHandler wiring into workflow options for HttpRequestAction.
dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/Kit/RootExecutor.cs Stores merged last message (original text + server media) before executing workflow.
dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/Interpreter/DeclarativeWorkflowExecutor.cs Stores merged last message (original text + server media) for declarative execution path.
dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/Extensions/ChatMessageExtensions.cs Implements MergeForLastMessage merging logic.
dotnet/samples/03-workflows/Declarative/InvokeHttpRequest/Program.cs New sample host wiring up DefaultHttpRequestHandler and running the workflow.
dotnet/samples/03-workflows/Declarative/InvokeHttpRequest/InvokeHttpRequest.yaml New workflow using HttpRequestAction + follow-up agent loop.
dotnet/samples/03-workflows/Declarative/InvokeHttpRequest/InvokeHttpRequest.csproj New sample project file.
dotnet/agent-framework-dotnet.slnx Adds the new sample project and minor ordering tweaks.

Comment thread dotnet/src/Shared/Workflows/Execution/WorkflowRunner.cs
Comment thread dotnet/samples/03-workflows/Declarative/InvokeHttpRequest/InvokeHttpRequest.yaml Outdated
Comment thread dotnet/samples/03-workflows/Declarative/InvokeHttpRequest/InvokeHttpRequest.yaml Outdated
Comment thread dotnet/samples/03-workflows/Declarative/InvokeHttpRequest/InvokeHttpRequest.yaml Outdated
@github-actions github-actions Bot changed the title Add declarative HttpRequestAction sample .NET: Add declarative HttpRequestAction sample Apr 29, 2026
@peibekwe peibekwe self-assigned this Apr 29, 2026
@peibekwe peibekwe marked this pull request as ready for review April 29, 2026 18:37
Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

Automated Code Review

Reviewers: 4 | Confidence: 89% | Result: All clear

Reviewed: Correctness, Security Reliability, Test Coverage, Design Approach


Automated review by peibekwe's agents

@peibekwe peibekwe added this pull request to the merge queue Apr 29, 2026
Merged via the queue into main with commit 6853f64 Apr 29, 2026
25 checks passed
@peibekwe peibekwe deleted the peibekwe/declarative-openapi-tool branch April 30, 2026 22:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

.NET workflows Related to Workflows in agent-framework

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants