-
Notifications
You must be signed in to change notification settings - Fork 1.4k
add a2ui example #1101
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
Open
Osier-Yi
wants to merge
20
commits into
agentscope-ai:main
Choose a base branch
from
Osier-Yi:interactive_agent
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
add a2ui example #1101
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
0a9dfa2
add inital a2ui example
Osier-Yi 44dfe87
add inital a2ui example
Osier-Yi 33ca9a8
refine lit
Osier-Yi b043ec5
Merge branch 'main' into interactive_agent
Osier-Yi cead69c
a2ui with skills
Osier-Yi d999f58
add notice about the model and cost time in readme
Osier-Yi d945c32
delete unnecessary files
Osier-Yi a7a2f82
delete unnecessary files
Osier-Yi 7212e51
delete unnecessary files
Osier-Yi 02df889
delete unnecessary files
Osier-Yi be0a663
update readme about the dependicies
Osier-Yi 851f789
fix logging issue
Osier-Yi 38d8642
add more exampels
Osier-Yi 21c43da
Merge branch 'main' into interactive_agent
Osier-Yi 7d9dadc
improve skills
Osier-Yi b132ecf
simplified examples
Osier-Yi 25884e7
delete_unnecessary_files
Osier-Yi 28a7553
delete unnecessary files
Osier-Yi bcd3299
delete unnecessary files
Osier-Yi a516f2e
move file structure to top
Osier-Yi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -148,4 +148,5 @@ package-lock.json | |
| *.tsbuildinfo | ||
| .wireit/ | ||
| .angular/ | ||
| *.ts | ||
| *.ts | ||
| uv.lock | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| # A2UI in AgentScope | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The current directory hierarchy appears to have some redundant nesting: It seems that the |
||
|
|
||
| [A2UI (Agent-to-Agent UI)](https://github.com/google/A2UI) is a protocol for agents to send | ||
| streaming, interactive user interfaces to clients. It enables LLMs to generate platform-agnostic, | ||
| declarative UI definitions that clients can render progressively using native widget sets. | ||
|
|
||
| In this example, we demonstrate how to integrate A2UI into a ReAct agent in AgentScope. This | ||
| implementation is based on the official A2UI agent samples, adapted to use AgentScope's agent | ||
| framework. | ||
|
|
||
| Specifically, we have: | ||
|
|
||
| 1. **Reimplemented the agent with AgentScope**: The agent part of the official A2UI samples has | ||
| been reimplemented using AgentScope's `ReActAgent`, providing a more familiar and integrated | ||
| development experience for AgentScope users. | ||
|
|
||
| 2. **Progressive schema and template exposure via skills**: To help the agent learn and generate | ||
| A2UI-compliant interfaces, we use AgentScope's skill system to progressively expose the A2UI | ||
| schema and UI templates. The agent can dynamically load these resources through the | ||
| `A2UI_response_generator` skill, enabling it to understand component definitions and learn from | ||
| example UI structures. | ||
|
|
||
| ## Note on External Dependencies | ||
|
|
||
| The following directories in this example contain content sourced from the [Google A2UI repository](https://github.com/google/A2UI): | ||
|
|
||
| - **`samples/client/`**: A2UI client sample applications | ||
|
|
||
| **NPM Package Status**: As of now, the A2UI client libraries (`@a2ui/lit` and `@a2ui/angular`) are **not yet published to NPM**. According to the [official A2UI client setup guide](https://a2ui.org/guides/client-setup/#renderers): "The Lit client library is not yet published to NPM. Check back in the coming days." | ||
|
|
||
| Therefore, these dependencies are currently included in this example repository using local file paths (e.g., `"@a2ui/lit": "file:../../../../renderers/lit"` in `package.json` files). This mirrors the approach used in the [official A2UI repository](https://github.com/google/A2UI), where the renderers and samples also use local file paths to reference each other. Additionally, the `copy-spec` task in `renderers/lit/package.json` copies files from the local `specification/` directory during the build process. | ||
|
|
||
| **Future Plans**: Once those libraries are published to NPM, we plan to gradually migrate to using the official NPM packages and remove these locally included directories. | ||
|
|
||
| ## Quick Start | ||
|
|
||
| Download the a2ui and agentscope package to the same directory | ||
|
|
||
| ```bash | ||
| git clone https://github.com/google/A2UI.git | ||
| git clone -b main https://github.com/agentscope-ai/agentscope.git | ||
| # copy the renders and specification directory to AgentScope/examples/agent/a2ui_agent | ||
| copy -r a2ui/renderers AgentScope/examples/agent/a2ui_agent | ||
| copy -r a2ui/specification AgentScope/examples/agent/a2ui_agent | ||
| ``` | ||
|
|
||
|
|
||
| Then, navigate to the client directory and run the restaurant finder demo: | ||
|
|
||
| ```bash | ||
| cd AgentScope/examples/agent/a2ui_agent/samples/client/lit | ||
| npm run demo:restaurant | ||
| ``` | ||
|
|
||
| This command will: | ||
| - Install dependencies and build the A2UI renderer | ||
| - Start the A2A server (AgentScope agent) for the restaurant finder | ||
| - Launch the client application in your browser | ||
|
|
||
| > Note: | ||
| > - The example is built with DashScope chat model. Make sure to set your `DASHSCOPE_API_KEY` | ||
| > environment variable before running the demo. | ||
| > - If you are using Qwen series models, we recommend using `qwen3-max` for better performance in | ||
| > generating A2UI-compliant JSON responses. | ||
| > - Generating UI JSON responses may take some time, typically 1-2 minutes, as the agent needs to | ||
| > process the schema, examples, and generate complex UI structures. | ||
| > - The demo uses the standard A2UI catalog. Custom catalog and inline catalog support are under | ||
| > development. | ||
| ## Roadmap | ||
|
|
||
| AgentScope's main focus going forward will be on improving **How Agents Work** with A2UI. The | ||
| workflow we're working towards is: | ||
|
|
||
| ``` | ||
| User Input → Agent Logic → LLM → A2UI JSON | ||
| ``` | ||
|
|
||
| Our optimization efforts will focus on: | ||
|
|
||
| - **Agent Logic**: Improving how agents process inputs and orchestrate the generation of A2UI JSON | ||
| messages | ||
|
|
||
|
|
||
| - **Handle user interactions from the client**: Enabling agents to properly process and respond to | ||
| user interactions from the client (such as button clicks, form submissions), treating them as new | ||
| user input to create a continuous interactive loop | ||
|
|
||
| **Current approach**: The skill-based method we've implemented in this example is our first step | ||
| towards this goal. By using AgentScope's skill system to progressively expose the A2UI schema and | ||
| templates, agents can learn to generate compliant UI structures. Future improvements will focus on | ||
| streamlining this process and making it more intuitive for developers to build A2UI-capable agents. | ||
|
|
||
| **Next steps for Agent Logic improvement** | ||
|
|
||
| - **Agent skills improvements**: | ||
| - Support flexible schema addition: Enable developers to easily add and customize schemas without | ||
| modifying core skill code | ||
| - Separate schema and examples into dedicated folders: Organize schema definitions and example | ||
| templates into distinct directories for better maintainability and clearer structure | ||
|
|
||
| - **Context management in Memory for A2UI long context**: | ||
| - Currently, A2UI messages are extremely long, which makes multi-turn interactions inefficient | ||
| and degrades the quality of agent responses. We plan to implement better context management | ||
| strategies to handle these long-form messages and improve the quality of multi-turn conversations. | ||
|
|
||
| - **Keep up with A2UI protocol updates**: | ||
| - We will follow A2UI protocol updates and make corresponding adjustments. For example, we plan to | ||
| support streaming UI JSON introduced in A2UI v0.9. | ||
|
|
||
35 changes: 35 additions & 0 deletions
35
examples/agent/a2ui_agent/samples/agent/general_agent/__main__.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| # -*- coding: utf-8 -*- | ||
| """Main entry point for running the restaurant finder A2UI server.""" | ||
| import logging | ||
| import os | ||
| import uvicorn | ||
| from starlette.staticfiles import StaticFiles | ||
| from setup_a2ui_server import app | ||
|
|
||
| if __name__ == "__main__": | ||
| # Get the directory where this script is located | ||
| script_dir = os.path.dirname(os.path.abspath(__file__)) | ||
| images_dir = os.path.join(script_dir, "images") | ||
|
|
||
| # Mount static files if images directory exists | ||
| if os.path.exists(images_dir): | ||
| app.mount("/static", StaticFiles(directory=images_dir), name="static") | ||
| logging.info( | ||
| "Mounted static files from %s at /static", | ||
| images_dir, | ||
| ) | ||
| else: | ||
| logging.warning( | ||
| "Images directory not found at %s, " | ||
| "static files will not be served", | ||
| images_dir, | ||
| ) | ||
|
|
||
| # Run the app manually with uvicorn | ||
| uvicorn.run( | ||
| app, | ||
| host="0.0.0.0", | ||
| port=10002, | ||
| log_level="info", | ||
| access_log=True, | ||
| ) |
Oops, something went wrong.
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.
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.
Keeping *.ts in .gitignore seems conflict with the current pull request?