Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jul 30, 2025

Fixes the Append property in TaskArtifactUpdateEvent to accurately reflect what actually occurred during artifact updates, rather than simply echoing the user's request. Additionally adds comprehensive usage examples for the UpdateArtifactAsync method in the samples.

Problem

When calling UpdateArtifactAsync(taskId, artifact, append: true) on a task with no existing artifacts, the system would:

  1. Create a new artifact (correct behavior)
  2. Set Append = true in the event (incorrect - misleading)

This was confusing because the event indicated that appending occurred when actually a new artifact was created. Additionally, the UpdateArtifactAsync method lacked clear usage examples in the samples.

Solution

The Append property in TaskArtifactUpdateEvent now reflects the actual operation performed:

  • Append = true when parts were successfully appended to an existing artifact
  • Append = false when a new artifact was created (regardless of what the user requested)

Enhanced the EchoAgentWithTasks sample to demonstrate proper UpdateArtifactAsync usage patterns alongside the existing ReturnArtifactAsync usage.

Changes

  • Modified UpdateArtifactAsync to always set Append = false when creating new artifacts
  • Added comprehensive test coverage for the edge case where append=true is requested but no artifacts exist
  • Enhanced EchoAgentWithTasks sample with three usage patterns:
    • ReturnArtifactAsync for simple, complete responses (default behavior)
    • UpdateArtifactAsync with streaming for chunked responses (use stream: <text>)
    • UpdateArtifactAsync with append for building artifacts incrementally (use append: <text>)
  • Fixed inconsistent indentation in A2A.csproj

This ensures that event consumers receive accurate information about what actually happened, while providing clear examples of how to use both artifact methods effectively.

Fixes #21.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: brandonh-msft <20270743+brandonh-msft@users.noreply.github.com>
@brandonh-msft brandonh-msft changed the title [WIP] Add support for TaskArtifactUpdateEvents that use append = true fix: Add support for TaskArtifactUpdateEvents that use append = true Jul 31, 2025
@brandonh-msft brandonh-msft marked this pull request as ready for review July 31, 2025 16:19
@brandonh-msft brandonh-msft enabled auto-merge July 31, 2025 16:19
@brandonh-msft
Copy link
Collaborator

@copilot try again

…tifact regardless of user request

Co-authored-by: brandonh-msft <20270743+brandonh-msft@users.noreply.github.com>
auto-merge was automatically disabled August 27, 2025 03:43

Head branch was pushed to by a user without write access

Copy link
Contributor Author

Copilot AI commented Aug 27, 2025

@copilot try again

Fixed the Append flag logic in TaskArtifactUpdateEvent. The issue was that when append=true was requested but no existing artifacts existed, the event still showed Append=true even though we actually created a new artifact.

Now the Append property correctly reflects what actually happened:

  • Append=true when parts were appended to an existing artifact
  • Append=false when a new artifact was created (regardless of user request)

Added a specific test case to cover this scenario. All 190 tests are passing.

Commit: bf9ba4e

Copilot AI changed the title fix: Add support for TaskArtifactUpdateEvents that use append = true fix: Correctly set Append flag in TaskArtifactUpdateEvent based on actual behavior Aug 27, 2025
Copilot finished work on behalf of brandonh-msft August 27, 2025 03:44
/// <param name="lastChunk">Whether this is the last chunk of the artifact.</param>
/// <param name="cancellationToken">A cancellation token that can be used to cancel the operation.</param>
/// <returns>A task representing the asynchronous operation.</returns>
Task UpdateArtifactAsync(string taskId, Artifact artifact, bool append = false, bool? lastChunk = null, CancellationToken cancellationToken = default);
Copy link
Collaborator

Choose a reason for hiding this comment

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

@copilot This method is not used yet (except in tests). Show me how it is supposed to be used on agent implementations in samples/ folder. This should play nice with the current ReturnArtifactAsync method implementation so observe how it is being used in samples/

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Enhanced the EchoAgentWithTasks sample to demonstrate how UpdateArtifactAsync should be used in agent implementations. The sample now shows three patterns:

  1. Simple responses: ReturnArtifactAsync for complete, single artifacts (default behavior)
  2. Streaming responses: UpdateArtifactAsync with chunked data (use stream: <text> command)
  3. Incremental building: UpdateArtifactAsync with append functionality (use append: <text> command)

The key difference from ReturnArtifactAsync is that UpdateArtifactAsync supports:

  • append parameter to add to existing artifacts vs creating new ones
  • lastChunk parameter for streaming scenarios
  • More granular control over artifact construction

This demonstrates the proper usage patterns alongside the existing ReturnArtifactAsync usage in the samples. Commit: 8a8af29

…examples in EchoAgentWithTasks

Co-authored-by: Blackhex <23485+Blackhex@users.noreply.github.com>
Copilot AI changed the title fix: Correctly set Append flag in TaskArtifactUpdateEvent based on actual behavior fix: Correctly set Append flag in TaskArtifactUpdateEvent and add UpdateArtifactAsync usage examples Aug 27, 2025
Copilot finished work on behalf of Blackhex August 27, 2025 11:31
Copilot AI requested a review from Blackhex August 27, 2025 11:31
…copilot/fix-21

# Conflicts:
#	src/A2A/A2A.csproj
#	tests/A2A.UnitTests/Server/TaskManagerTests.cs
if (append && task.Artifacts.Count > 0)
{
// Append to the last artifact by adding parts to it
var lastArtifact = task.Artifacts[^1];

Choose a reason for hiding this comment

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

Hello @brandonh-msft. Why are you taking the last artifact from the task ?
Is this a limitation from the A2A protocol, meaning we can only append to the last artifact from the task ?
If this is not a limitation, you could use the artifact object received from the method params and look for a corresponding artifactId ?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for TaskArtifactUpdateEvents that use append = true

4 participants