Skip to content

version0.5.1 -> 0.5.6 : assistantagent use mcp tools as arg output garbled text,workbench is normal. Is version 0.5.6 of the tools incompatible with the old version? #6496

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
zhangwei668 opened this issue May 9, 2025 · 5 comments

Comments

@zhangwei668
Copy link

What happened?

version0.5.1 -> 0.5.6 : assistant use tools as arg output garbled text,workbench is normal. 是否0.5.6 tools不兼容旧版本

Which packages was the bug in?

Python AgentChat (autogen-agentchat>=0.4.0)

AutoGen library version.

Python dev (main branch)

Other library version.

No response

Model used

No response

Model provider

None

Other model provider

No response

Python version

None

.NET version

None

Operating system

None

@zhangwei668 zhangwei668 changed the title version0.5.1 -> 0.5.6 : assistant use tools as arg output garbled text,workbench is normal. 是否0.5.6 tools不兼容旧版本 version0.5.1 -> 0.5.6 : assistant use mcp tools as arg output garbled text,workbench is normal. 是否0.5.6 tools不兼容旧版本 May 9, 2025
@zhangwei668 zhangwei668 changed the title version0.5.1 -> 0.5.6 : assistant use mcp tools as arg output garbled text,workbench is normal. 是否0.5.6 tools不兼容旧版本 version0.5.1 -> 0.5.6 : assistantagent use mcp tools as arg output garbled text,workbench is normal. 是否0.5.6 tools不兼容旧版本 May 9, 2025
@zhangwei668 zhangwei668 changed the title version0.5.1 -> 0.5.6 : assistantagent use mcp tools as arg output garbled text,workbench is normal. 是否0.5.6 tools不兼容旧版本 version0.5.1 -> 0.5.6 : assistantagent use mcp tools as arg output garbled text,workbench is normal. Is version 0.5.6 of the tools incompatible with the old version? May 9, 2025
@SongChiYoung
Copy link
Contributor

Thanks for reporting this @zhangwei668.

Just to clarify — in v0.5.6, some internal handling of tool arguments may have changed when used via AssistantAgent versus Workbench. Before we dig deeper:

  1. Could you confirm the versions of the following packages?
    It’s important that all three versions match:
pip show autogen-core
pip show autogen-agentchat
pip show autogen-ext
  1. Could you also share a minimal code example that reproduces the issue?
    Preferably, one that uses AssistantAgent with McpWorkbench as a tool argument. This will help us determine whether it’s a compatibility or integration issue.

Happy to help once we can reproduce it. Thanks!

@zhangwei668
Copy link
Author

zhangwei668 commented May 10, 2025

The model is the qwen2.5 model deployed with vllm
mcp server is local deployment
This version is also aligned.
The main problem now is that the printed output is in Unicode encoding.
Through the conversion, it was found that the content is correct, but the output format is in Unicode encoding, which was not a problem before.

import asyncio
from autogen_ext.models.openai import OpenAIChatCompletionClient
from autogen_ext.tools.mcp import SseMcpToolAdapter, SseServerParams
from autogen_agentchat.agents import AssistantAgent
from autogen_agentchat.ui import Console
from autogen_core import CancellationToken

async def main() -> None:
# Create server params for the remote MCP service
server_params = SseServerParams(
url="https://api.example.com/mcp",
headers={"Authorization": "Bearer your-api-key", "Content-Type": "application/json"},
timeout=30, # Connection timeout in seconds
)

# Get the translation tool from the server
adapter = await SseMcpToolAdapter.from_server_params(server_params, "mcp-name")

# Create an agent that can use the translation tool
model_client =OpenAIChatComplete...............

agent = AssistantAgent(
name="translator",
model_client=model_client,
tools=[adapter],
system_message="You are a helpful translation assistant.",
)

# Let the agent translate some text
await Console(
    agent.run_stream(task="Translate 'Hello, how are you?' to Spanish", cancellation_token=CancellationToken())
)

if name == "main":
asyncio.run(main())
`

@SongChiYoung
Copy link
Contributor

SongChiYoung commented May 11, 2025

Are you using FastMCP?
In my case, @playwright/mcp@latest could send CJK well.
However FastMCP dummpy_server could not send CJK well, it send unicode escape shape.

We could fix it -ad-hoc- with change this code.

for content in result.content:
if isinstance(content, TextContent):
result_parts.append(TextResultContent(content=content.text))
elif isinstance(content, ImageContent):
result_parts.append(ImageResultContent(content=Image.from_base64(content.data)))
elif isinstance(content, EmbeddedResource):
# TODO: how to handle embedded resources?
# For now we just use text representation.
result_parts.append(TextResultContent(content=content.model_dump_json()))
else:
raise ValueError(f"Unknown content type from server: {type(content)}")

to

         result_parts.append(TextResultContent(content=content.text.encode('utf-8').decode('unicode_escape'))) 

however, I could not agree that change. Cause, I have worry about that there is no comparison between when MCP intentionally sends such a form and when it does not.

@zhangwei668
Copy link
Author

Are you using FastMCP? In my case, @playwright/mcp@latest could send CJK well. However FastMCP dummpy_server could not send CJK well, it send unicode escape shape.

We could fix it -ad-hoc- with change this code.

autogen/python/packages/autogen-ext/src/autogen_ext/tools/mcp/_workbench.py

Lines 214 to 224 in 6427c07

for content in result.content:
if isinstance(content, TextContent):
result_parts.append(TextResultContent(content=content.text))
elif isinstance(content, ImageContent):
result_parts.append(ImageResultContent(content=Image.from_base64(content.data)))
elif isinstance(content, EmbeddedResource):
# TODO: how to handle embedded resources?
# For now we just use text representation.
result_parts.append(TextResultContent(content=content.model_dump_json()))
else:
raise ValueError(f"Unknown content type from server: {type(content)}")
to

         result_parts.append(TextResultContent(content=content.text.encode('utf-8').decode('unicode_escape'))) 

however, I could not agree that change. Cause, I have worry about that there is no comparison between when MCP intentionally sends such a form and when it does not.

I discovered the reason for the json return: return json.dumps([serialize_item(item) for item in value], ensure_ascii=False)
https://github.com/microsoft/autogen/blob/main/python/packages/autogen-ext/src/autogen_ext/tools/mcp/_base.py

def return_value_as_string(self, value: list[Any]) -> str:
    """Return a string representation of the result."""

    def serialize_item(item: Any) -> dict[str, Any]:
        if isinstance(item, (TextContent, ImageContent)):
            return item.model_dump()
        elif isinstance(item, EmbeddedResource):
            type = item.type
            resource = {}
            for key, val in item.resource.model_dump().items():
                if isinstance(val, AnyUrl):
                    resource[key] = str(val)
                else:
                    resource[key] = val
            annotations = item.annotations.model_dump() if item.annotations else None
            return {"type": type, "resource": resource, "annotations": annotations}
        else:
            return {}

    return json.dumps([serialize_item(item) for item in value], ensure_ascil=False)

@ekzhu
Copy link
Collaborator

ekzhu commented May 13, 2025

Looks like a serialization issue. Do you specifically do not want unicode encoding? I can see scenarios when this is useful though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants