✂️ refactor: use artifacts and callbacks to pass UI resources#9472
Closed
samuelpath wants to merge 1 commit intodanny-avila:mainfrom
Closed
✂️ refactor: use artifacts and callbacks to pass UI resources#9472samuelpath wants to merge 1 commit intodanny-avila:mainfrom
samuelpath wants to merge 1 commit intodanny-avila:mainfrom
Conversation
deff11b to
792260d
Compare
742d88c to
c0cecf0
Compare
samuelpath
commented
Sep 8, 2025
| resource: (item) => { | ||
| if (item.resource.uri.startsWith('ui://')) { | ||
| uiResources.push(item.resource as t.UIResource); | ||
| return; |
Contributor
Author
There was a problem hiding this comment.
Now that the UI Resources are passed as artifacts and are thus not sent to the LLM, we can still pass the parsed UI Resources to the LLM as a regular resource. This will be useful in the next integration phase.
samuelpath
commented
Sep 8, 2025
| ); | ||
| } | ||
|
|
||
| // TODO: a lot of duplicated code in createToolEndCallback |
Contributor
Author
There was a problem hiding this comment.
I first introduce a test file for this file before introducing any refactoring of this class. I have some ideas to make it way simpler with way less duplications, but I first want to introduce the non-regression unit tests.
c0cecf0 to
1c995f6
Compare
1c995f6 to
bf21d9c
Compare
8 tasks
Owner
|
I redid the PR with my changes here since I couldn't push up to your fork: #9581 There were some minor typing and import issues that were easier for me to address to get this merged in sooner. Thanks for your work on this! |
8 tasks
8 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Tip
A few tests were broken but had nothing to do with this PR. After a few rebases on main, all tests are now green ✅.
Summary
I recently shipped the 2 followings PRs to enable a basic integration with MCP-UI:
The approach I took to pass the UI resources received from the MCP Server tool response to the front-end was to use a content item of type
textand passing the UI resources array in a newmetadataproperty.This worked but the issue is that these content items of type
textare passed as such the LLMs. We have been lucky so far since all the LLM providers we've tested silently ignored this unknownmetadataproperty. But there is no guarantee that all providers do, nor that existing providers could enforce stricter payload checks.In order to work around this, we proposed the following PR in the Agents package: danny-avila/agents#16. It would remove the
metadataproperty just before the call to the LLM would be made. However, this was rightly rejected by @danny-avila who explained that there was a better way, using callbacks.This PR now uses @danny-avila's recommended approach with the callbacks.
Here's the idea:
Tools.ui_resourcesToolCalltoToolCallInfoToolCallInfoto render themChange Type
Testing
See the 2 PRs mentioned above. The behaviour tested is the same.
Test Configuration:
Checklist
Please delete any irrelevant options.