-
Notifications
You must be signed in to change notification settings - Fork 280
feat(agui): add support for frontend tool calls and update the examples #762
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
Summary of ChangesHello @TornadoDragon, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the AgentScope AG-UI by enabling agents to interact with the client-side browser environment through a new frontend tool calling mechanism. This expands the capabilities of agents, allowing them to perform actions like retrieving browser information, accessing local storage, or reading the clipboard, directly from the user's interface. The changes include new client-side JavaScript for tool management and execution, UI updates to display these tools, and backend logic to integrate these frontend tools seamlessly with the agent's existing toolkit. Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
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.
Code Review
This pull request introduces frontend tool call support, a significant feature. The implementation is mostly solid, but there are a few critical bugs in the JavaScript logic for handling tool results that would prevent the feature from working correctly. Additionally, there's significant code duplication in the main HTML file that should be refactored to improve maintainability. I've also noted some smaller issues regarding API clarity in both the Java and JavaScript code. Addressing these points will make the new feature more robust and the codebase easier to maintain.
| id: 'tool-result-' + Date.now() + '-' + Math.random(), | ||
| role: 'tool', | ||
| content: JSON.stringify(result.output), | ||
| toolCallId: result.toolCallId |
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.
The property name for the tool call ID should be tool_call_id to match the snake_case convention expected by the backend and defined in the AguiMessage model. Using toolCallId will likely cause deserialization issues on the server.
| toolCallId: result.toolCallId | |
| tool_call_id: result.toolCallId |
| onToolCallEnd: (toolCallId) => { | ||
| // Tool call completed | ||
| // Tool call completed - if it's a frontend tool, execute it | ||
| const pendingCall = frontendTools.getPendingCall(toolCallId); | ||
| if (pendingCall) { | ||
| executeFrontendTool(pendingCall.toolCallId, pendingCall.toolName, pendingCall.parsedArgs); | ||
| } | ||
| }, |
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.
The onToolCallEnd callback now executes the frontend tool. However, the sendToolResultMessage function, which is called after tool execution, has significant code duplication with the sendMessage function. Both functions set up and execute a client.run call with nearly identical callbacks. This duplication makes the code harder to maintain.
Consider refactoring the client.run logic into a shared function that can be called by both sendMessage and sendToolResultMessage to avoid repeating the same setup and event handling logic.
...pe-extensions-agui/src/main/java/io/agentscope/core/agui/processor/AguiRequestProcessor.java
Show resolved
Hide resolved
agentscope-core/src/main/java/io/agentscope/core/tool/Toolkit.java
Outdated
Show resolved
Hide resolved
| setTimeout(() => { | ||
| if (!isRunning) { | ||
| sendToolResultMessage(); | ||
| } | ||
| }, 500); |
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.
Using setTimeout with a fixed delay of 500ms to trigger sending tool results is a code smell. It introduces an arbitrary delay and can be unreliable. If the goal is to batch results from multiple tool calls, there might be a more deterministic approach. For example, you could wait for all tool calls in a given turn to complete before sending the results back. The current implementation might be sensitive to timing issues.
| let requestMessages = [...messageHistory]; | ||
| pendingResults.forEach(result => { | ||
| requestMessages.push({ | ||
| id: 'tool-result-' + Date.now() + '-' + Math.random(), |
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.
Using Math.random() to generate part of a message ID is not a robust way to ensure uniqueness, as collisions are possible, although unlikely in this specific context. For a more production-ready example, consider using a library that generates UUIDs (e.g., crypto.randomUUID() which is available in modern browsers/Node.js) or a simple incrementing counter to guarantee unique IDs within the session.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
| * @param toolName Tool name | ||
| * @param groupName Group name | ||
| */ | ||
| public void addToolToGroup(String toolName, String groupName) { |
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.
Why add this?
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.


AgentScope-Java Version
1.0.9-SNAPSHOT
Description
Add support for frontend tool calls in agui and update the examples.
Checklist
Please check the following items before code is ready to be reviewed.
mvn spotless:applymvn test)