-
Couldn't load subscription status.
- Fork 41
fix: Correctly set Append flag in TaskArtifactUpdateEvent and add UpdateArtifactAsync usage examples #120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: brandonh-msft <20270743+brandonh-msft@users.noreply.github.com>
d12a2fa to
21ec564
Compare
|
@copilot try again |
…tifact regardless of user request Co-authored-by: brandonh-msft <20270743+brandonh-msft@users.noreply.github.com>
Head branch was pushed to by a user without write access
Fixed the Now the
Added a specific test case to cover this scenario. All 190 tests are passing. Commit: bf9ba4e |
| /// <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); |
There was a problem hiding this comment.
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/
There was a problem hiding this comment.
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:
- Simple responses:
ReturnArtifactAsyncfor complete, single artifacts (default behavior) - Streaming responses:
UpdateArtifactAsyncwith chunked data (usestream: <text>command) - Incremental building:
UpdateArtifactAsyncwith append functionality (useappend: <text>command)
The key difference from ReturnArtifactAsync is that UpdateArtifactAsync supports:
appendparameter to add to existing artifacts vs creating new oneslastChunkparameter 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/fix-21 # Conflicts: # src/A2A/A2A.csproj # tests/A2A.UnitTests/Server/TaskManagerTests.cs
…copilot/fix-21
| if (append && task.Artifacts.Count > 0) | ||
| { | ||
| // Append to the last artifact by adding parts to it | ||
| var lastArtifact = task.Artifacts[^1]; |
There was a problem hiding this comment.
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 ?
Fixes the
Appendproperty inTaskArtifactUpdateEventto accurately reflect what actually occurred during artifact updates, rather than simply echoing the user's request. Additionally adds comprehensive usage examples for theUpdateArtifactAsyncmethod in the samples.Problem
When calling
UpdateArtifactAsync(taskId, artifact, append: true)on a task with no existing artifacts, the system would:Append = truein the event (incorrect - misleading)This was confusing because the event indicated that appending occurred when actually a new artifact was created. Additionally, the
UpdateArtifactAsyncmethod lacked clear usage examples in the samples.Solution
The
Appendproperty inTaskArtifactUpdateEventnow reflects the actual operation performed:Append = truewhen parts were successfully appended to an existing artifactAppend = falsewhen a new artifact was created (regardless of what the user requested)Enhanced the
EchoAgentWithTaskssample to demonstrate properUpdateArtifactAsyncusage patterns alongside the existingReturnArtifactAsyncusage.Changes
UpdateArtifactAsyncto always setAppend = falsewhen creating new artifactsappend=trueis requested but no artifacts existEchoAgentWithTaskssample with three usage patterns:ReturnArtifactAsyncfor simple, complete responses (default behavior)UpdateArtifactAsyncwith streaming for chunked responses (usestream: <text>)UpdateArtifactAsyncwith append for building artifacts incrementally (useappend: <text>)A2A.csprojThis 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.