mirror of
https://github.com/microsoft/autogen.git
synced 2025-06-26 22:30:10 +00:00
Add guide for workbench and mcp & bug fixes for create_mcp_server_session (#6392)
Add user guide for workbench and mcp *Also fixed a bug in create_mcp_server_session that included "type" in the parameters Resolves: #6392
This commit is contained in:
parent
f059262b6d
commit
cbd8745f2b
File diff suppressed because one or more lines are too long
@ -48,6 +48,7 @@ framework/component-config
|
|||||||
components/model-clients
|
components/model-clients
|
||||||
components/model-context
|
components/model-context
|
||||||
components/tools
|
components/tools
|
||||||
|
components/workbench
|
||||||
components/command-line-code-executors
|
components/command-line-code-executors
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -52,6 +52,28 @@ class ToolResult(BaseModel):
|
|||||||
is_error: bool = False
|
is_error: bool = False
|
||||||
"""Whether the tool execution resulted in an error."""
|
"""Whether the tool execution resulted in an error."""
|
||||||
|
|
||||||
|
def to_text(self, replace_image: str | None = None) -> str:
|
||||||
|
"""
|
||||||
|
Convert the result to a text string.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
replace_image (str | None): The string to replace the image content with.
|
||||||
|
If None, the image content will be included in the text as base64 string.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
str: The text representation of the result.
|
||||||
|
"""
|
||||||
|
parts: List[str] = []
|
||||||
|
for content in self.result:
|
||||||
|
if isinstance(content, TextResultContent):
|
||||||
|
parts.append(content.content)
|
||||||
|
elif isinstance(content, ImageResultContent):
|
||||||
|
if replace_image is not None:
|
||||||
|
parts.append(replace_image)
|
||||||
|
else:
|
||||||
|
parts.append(f"[Image: {content.content.to_base64()}]")
|
||||||
|
return "\n".join(parts)
|
||||||
|
|
||||||
|
|
||||||
class Workbench(ABC, ComponentBase[BaseModel]):
|
class Workbench(ABC, ComponentBase[BaseModel]):
|
||||||
"""
|
"""
|
||||||
|
@ -57,6 +57,7 @@ async def test_static_workbench() -> None:
|
|||||||
assert result_1.name == "test_tool_1"
|
assert result_1.name == "test_tool_1"
|
||||||
assert result_1.result[0].type == "TextResultContent"
|
assert result_1.result[0].type == "TextResultContent"
|
||||||
assert result_1.result[0].content == "10"
|
assert result_1.result[0].content == "10"
|
||||||
|
assert result_1.to_text() == "10"
|
||||||
assert result_1.is_error is False
|
assert result_1.is_error is False
|
||||||
|
|
||||||
# Call tool with error
|
# Call tool with error
|
||||||
@ -64,6 +65,7 @@ async def test_static_workbench() -> None:
|
|||||||
assert result_2.name == "test_tool_2"
|
assert result_2.name == "test_tool_2"
|
||||||
assert result_2.result[0].type == "TextResultContent"
|
assert result_2.result[0].type == "TextResultContent"
|
||||||
assert result_2.result[0].content == "This is a test error"
|
assert result_2.result[0].content == "This is a test error"
|
||||||
|
assert result_2.to_text() == "This is a test error"
|
||||||
assert result_2.is_error is True
|
assert result_2.is_error is True
|
||||||
|
|
||||||
# Save state.
|
# Save state.
|
||||||
@ -109,6 +111,7 @@ async def test_static_workbench() -> None:
|
|||||||
assert result_1.name == "test_tool_1"
|
assert result_1.name == "test_tool_1"
|
||||||
assert result_1.result[0].type == "TextResultContent"
|
assert result_1.result[0].type == "TextResultContent"
|
||||||
assert result_1.result[0].content == "10"
|
assert result_1.result[0].content == "10"
|
||||||
|
assert result_1.to_text() == "10"
|
||||||
assert result_1.is_error is False
|
assert result_1.is_error is False
|
||||||
|
|
||||||
# Call tool with error
|
# Call tool with error
|
||||||
@ -116,4 +119,5 @@ async def test_static_workbench() -> None:
|
|||||||
assert result_2.name == "test_tool_2"
|
assert result_2.name == "test_tool_2"
|
||||||
assert result_2.result[0].type == "TextResultContent"
|
assert result_2.result[0].type == "TextResultContent"
|
||||||
assert result_2.result[0].content == "This is a test error"
|
assert result_2.result[0].content == "This is a test error"
|
||||||
|
assert result_2.to_text() == "This is a test error"
|
||||||
assert result_2.is_error is True
|
assert result_2.is_error is True
|
||||||
|
@ -23,6 +23,6 @@ async def create_mcp_server_session(
|
|||||||
) as session:
|
) as session:
|
||||||
yield session
|
yield session
|
||||||
elif isinstance(server_params, SseServerParams):
|
elif isinstance(server_params, SseServerParams):
|
||||||
async with sse_client(**server_params.model_dump()) as (read, write):
|
async with sse_client(**server_params.model_dump(exclude={"type"})) as (read, write):
|
||||||
async with ClientSession(read_stream=read, write_stream=write) as session:
|
async with ClientSession(read_stream=read, write_stream=write) as session:
|
||||||
yield session
|
yield session
|
||||||
|
Loading…
x
Reference in New Issue
Block a user