Skip to content

Conversation

@vinci-grape
Copy link
Collaborator

Change Summary

fix bugs in webui mcp

Related issue number

Checklist

  • The pull request title is a good summary of the changes - it will be used in the changelog
  • Unit tests for the changes exist
  • Run pre-commit install and pre-commit run --all-files before git commit, and passed lint check.
  • Documentation reflects the changes where applicable

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @vinci-grape, 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 refines the web UI's agent interaction by improving how tool calls and results are communicated and displayed to the user. It also includes enhancements to configuration parsing, project visibility control, and the underlying package path resolution, aiming to fix bugs and provide a more robust and informative user experience.

Highlights

  • Enhanced Web UI Chat Interaction: The web UI now provides richer feedback during agent interactions, specifically for tool calls and results. It flushes pending chat responses and sends explicit 'waiting_input' messages to the frontend when the agent requires user input. Dedicated UI components have been added to display tool calls with their arguments and tool execution results (success or error) in a structured and visually distinct manner.
  • Improved Configuration Handling: The configuration loading logic has been updated to automatically convert specific string values to their appropriate types (e.g., 'temperature' to float, 'max_tokens' to int) when adding new config keys, preventing potential type-related bugs.
  • Project Discovery Filtering: A whitelist mechanism has been introduced for project discovery, ensuring that only specified projects (initially 'code_genesis' and 'singularity_cinema') are displayed in the web UI, providing better control over visible content.
  • Robust Package Path Resolution: The method for determining the 'ms_agent' package installation path has been made more robust by prioritizing the use of the __path__ attribute, which is more reliable for installed packages.
  • Streamlined Startup Script: The webui/start.sh script has been simplified by removing the redundant step of reinstalling ms-agent in development mode, which was causing unnecessary overhead.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • ms_agent/config/config.py
    • Added type conversion for 'temperature' (to float) and 'max_tokens' (to int) when setting new configuration values.
  • projects/code_genesis/PR_ARTICLE.md
    • Updated references to foundation models from Qwen2.5 to Qwen3.
  • webui/backend/agent_runner.py
    • Implemented flushing of chat responses and sending 'waiting_input' messages to the frontend when the agent is awaiting user input.
    • Introduced logic to detect and parse [tool_calling]: markers and tool execution results from agent output.
    • Added _flush_tool_call method to send structured tool call information to the frontend.
    • Modified _process_chat_line to handle assistant output, tool calls, and tool results distinctly.
    • Adjusted _flush_chat_response to not immediately reset _collecting_assistant_output, allowing for multi-part assistant responses.
  • webui/backend/project_discovery.py
    • Introduced a VISIBLE_PROJECTS whitelist to control which projects are displayed in the UI.
    • Modified discover_projects to filter projects based on the VISIBLE_PROJECTS whitelist.
  • webui/backend/websocket_handler.py
    • Improved the logic for determining the ms_agent package path, prioritizing __path__ for better reliability.
  • webui/frontend/src/components/ChatView.tsx
    • Added new Material-UI icons (ToolIcon, SuccessIcon, ErrorIcon) for visual feedback.
    • Modified input handling for isWaitingForInput to use the sendMessage function.
    • Implemented dedicated rendering for tool_call messages, displaying tool names and arguments.
    • Implemented dedicated rendering for tool_result messages, indicating success or error status.
    • Adjusted message filtering to allow tool calls with empty content to be rendered.
  • webui/start.sh
    • Removed the command that reinstalled ms-agent in development mode, streamlining the startup process.
Activity
  • The pull request aims to fix bugs in the web UI's interaction with the Multi-Agent Communication Protocol (MCP).
  • Changes include refining how agent outputs, especially tool calls and results, are processed and displayed.
  • Updates to configuration handling and project discovery mechanisms were also implemented.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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 significant enhancements to the Web UI, primarily adding support for tool calling in the chat interface and fixing several bugs related to agent state management. Key changes include updating the agent runner to parse tool call information from logs, adding new UI components to display tool interactions, and improving configuration handling. The PR also includes some refactoring and bug fixes, such as making project discovery configurable and improving how the agent's "waiting for input" state is communicated to the frontend. My review focuses on improving maintainability by reducing code duplication and suggesting structural improvements for better readability and flexibility.

Comment on lines +220 to +232
value_to_set = value
if final_key == 'temperature' and isinstance(
value_to_set, str):
try:
value_to_set = float(value_to_set)
except (ValueError, TypeError):
pass
elif final_key == 'max_tokens' and isinstance(
value_to_set, str):
try:
value_to_set = int(value_to_set)
except (ValueError, TypeError):
pass
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The logic for converting temperature and max_tokens from strings is helpful. However, this if/elif structure can become cumbersome to maintain as more type-specific conversions are needed. Consider using a dictionary to map keys to their conversion functions for a more scalable and maintainable approach.

Suggested change
value_to_set = value
if final_key == 'temperature' and isinstance(
value_to_set, str):
try:
value_to_set = float(value_to_set)
except (ValueError, TypeError):
pass
elif final_key == 'max_tokens' and isinstance(
value_to_set, str):
try:
value_to_set = int(value_to_set)
except (ValueError, TypeError):
pass
# A mapping for specific type conversions
CONVERSIONS = {
'temperature': float,
'max_tokens': int,
}
value_to_set = value
if final_key in CONVERSIONS and isinstance(value_to_set, str):
try:
value_to_set = CONVERSIONS[final_key](value_to_set)
except (ValueError, TypeError):
pass

Comment on lines +411 to +424
# Flush any pending chat response before waiting
if self._is_chat_mode:
self._flush_chat_response()
# Send waiting_input message to enable frontend input
if self.on_output and not self._waiting_input_sent:
self.on_output({
'type': 'waiting_input',
'content': '',
'role': 'system',
'metadata': {
'waiting': True
}
})
self._waiting_input_sent = True
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This block of logic for handling the "waiting for input" state is duplicated at lines 457-470. To improve maintainability and avoid future inconsistencies, consider extracting this logic into a private helper method, for example _handle_waiting_for_input().

if self._is_chat_mode and self._tool_call_json_buffer.strip(
) and self.on_output:
try:
import json
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

It's a best practice in Python to place all imports at the top of the file. This improves readability and helps avoid issues like circular dependencies. Please move import json to the top of webui/backend/agent_runner.py.

"""Discovers and manages projects from the ms-agent projects directory"""

# Whitelist of projects to show in the UI
VISIBLE_PROJECTS = {'code_genesis', 'singularity_cinema'}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Hardcoding the VISIBLE_PROJECTS whitelist in the source code can make it difficult to update without code changes and redeployment. For better flexibility and maintainability, consider moving this list to a configuration file (e.g., a JSON or YAML file).

Comment on lines +395 to +518
// Render tool call
if (isToolCall) {
const toolName = String(message.metadata?.tool_name || 'Unknown Tool');
const args = message.metadata?.arguments || {};
return (
<motion.div
initial={{ opacity: 0, y: 10 }}
animate={{ opacity: 1, y: 0 }}
exit={{ opacity: 0 }}
transition={{ duration: 0.2 }}
>
<Box
sx={{
display: 'flex',
alignItems: 'flex-start',
justifyContent: 'flex-start',
mb: 1.5,
px: 2,
}}
>
<Paper
elevation={0}
sx={{
maxWidth: '75%',
minWidth: 60,
px: 2,
py: 1.25,
borderRadius: '12px',
backgroundColor: alpha(theme.palette.info.main, 0.1),
border: `1px solid ${alpha(theme.palette.info.main, 0.3)}`,
}}
>
<Box sx={{ display: 'flex', alignItems: 'center', gap: 1, mb: 0.5 }}>
<ToolIcon sx={{ fontSize: 16, color: theme.palette.info.main }} />
<Typography variant="caption" sx={{ fontWeight: 600, color: theme.palette.info.main }}>
Calling Tool: {toolName.replace('---', ' / ')}
</Typography>
</Box>
{Object.keys(args).length > 0 && (
<Typography
variant="caption"
sx={{
display: 'block',
color: theme.palette.text.secondary,
fontFamily: 'monospace',
fontSize: '0.75rem',
whiteSpace: 'pre-wrap',
wordBreak: 'break-all',
}}
>
{JSON.stringify(args, null, 2)}
</Typography>
)}
</Paper>
</Box>
</motion.div>
);
}

// Render tool result
if (isToolResult) {
const isToolError = message.metadata?.is_error;
return (
<motion.div
initial={{ opacity: 0, y: 10 }}
animate={{ opacity: 1, y: 0 }}
exit={{ opacity: 0 }}
transition={{ duration: 0.2 }}
>
<Box
sx={{
display: 'flex',
alignItems: 'flex-start',
justifyContent: 'flex-start',
mb: 1.5,
px: 2,
}}
>
<Paper
elevation={0}
sx={{
maxWidth: '75%',
minWidth: 60,
px: 2,
py: 1.25,
borderRadius: '12px',
backgroundColor: isToolError
? alpha(theme.palette.error.main, 0.1)
: alpha(theme.palette.success.main, 0.1),
border: `1px solid ${alpha(isToolError ? theme.palette.error.main : theme.palette.success.main, 0.3)}`,
}}
>
<Box sx={{ display: 'flex', alignItems: 'center', gap: 1, mb: 0.5 }}>
{isToolError ? (
<ErrorIcon sx={{ fontSize: 16, color: theme.palette.error.main }} />
) : (
<SuccessIcon sx={{ fontSize: 16, color: theme.palette.success.main }} />
)}
<Typography
variant="caption"
sx={{
fontWeight: 600,
color: isToolError ? theme.palette.error.main : theme.palette.success.main,
}}
>
{isToolError ? 'Tool Error' : 'Tool Result'}
</Typography>
</Box>
<Typography
variant="caption"
sx={{
display: 'block',
color: theme.palette.text.secondary,
whiteSpace: 'pre-wrap',
wordBreak: 'break-word',
}}
>
{message.content}
</Typography>
</Paper>
</Box>
</motion.div>
);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The ChatMessageBubble component has grown quite large with the addition of rendering logic for tool calls and tool results. To improve readability and maintainability, consider extracting the rendering logic for tool_call (lines 395-452) and tool_result (lines 454-518) into their own separate components (e.g., ToolCallBubble and ToolResultBubble).

@tastelikefeet tastelikefeet merged commit ad38a48 into main Feb 3, 2026
2 of 3 checks passed
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.

3 participants