Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "agentscope-runtime"
version = "1.1.0b2"
version = "1.1.0b3"
description = "A production-ready runtime framework for agent applications, providing secure sandboxed execution environments and scalable deployment solutions with multi-framework support."
readme = "README.md"
requires-python = ">=3.10"
Expand Down
51 changes: 50 additions & 1 deletion src/agentscope_runtime/adapters/agentscope/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
import json

from collections import OrderedDict
from typing import Union, List, Callable, Optional, Dict
from typing import Union, List, Callable, Optional, Dict, Literal
from urllib.parse import urlparse
from typing_extensions import TypedDict, Required

from mcp.types import CallToolResult
from agentscope.message import (
Expand All @@ -28,6 +29,20 @@
)


# TODO: support in core framework
class FileBlock(TypedDict, total=False):
"""The file block"""

type: Required[Literal["file"]]
"""The type of the block"""

source: Required[Base64Source | URLSource]
"""The src of the file"""

filename: Optional[str]
"""Optional filename hint (e.g. `report.pdf`)"""
Comment thread
rayrayraykk marked this conversation as resolved.


def matches_typed_dict_structure(obj, typed_dict_cls):
if not isinstance(obj, dict):
return False
Expand Down Expand Up @@ -193,6 +208,7 @@ def is_valid_block(obj):
"audio": (AudioBlock, "data"),
"data": (TextBlock, "data"),
"video": (VideoBlock, "video_url"),
"file": (FileBlock, "file_url"),
}

msg_content = []
Expand Down Expand Up @@ -288,6 +304,39 @@ def is_valid_block(obj):
msg_content.append(
block_cls(type=cnt_type, source=url_source),
)
elif cnt_type == "file":
filename = cnt.filename
if (
value
and isinstance(value, str)
and value.startswith("data:")
):
mediatype_part = value.split(";")[0].replace(
"data:",
"",
)
base64_data = value.split(",")[1]
Comment thread
rayrayraykk marked this conversation as resolved.
base64_source = Base64Source(
type="base64",
media_type=mediatype_part,
data=base64_data,
)
msg_content.append(
block_cls(
type=cnt_type,
source=base64_source,
filename=filename,
),
)
else:
url_source = URLSource(type="url", url=value)
msg_content.append(
block_cls(
type=cnt_type,
source=url_source,
filename=filename,
),
)
Comment thread
rayrayraykk marked this conversation as resolved.
else:
# text & data
if isinstance(value, str):
Expand Down
43 changes: 43 additions & 0 deletions src/agentscope_runtime/adapters/agentscope/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
AudioContent,
VideoContent,
DataContent,
FileContent,
McpCall,
McpCallOutput,
FunctionCall,
Expand Down Expand Up @@ -602,6 +603,48 @@ async def adapt_agentscope_message_stream(
index=index,
**kwargs,
)
elif element.get("type") == "file":
kwargs = {
"filename": element.get("filename"),
}
if (
isinstance(element.get("source"), dict)
and element.get("source", {}).get(
"type",
)
== "url"
):
kwargs.update(
{
"file_url": element.get(
"source",
{},
).get("url"),
},
)

elif (
isinstance(element.get("source"), dict)
and element.get("source").get(
"type",
)
== "base64"
):
media_type = element.get("source", {}).get(
"media_type",
"application/octet-stream",
)
base64_data = element.get("source", {}).get(
"data",
"",
)
url = f"data:{media_type};base64,{base64_data}"
kwargs.update({"file_url": url})
Comment thread
rayrayraykk marked this conversation as resolved.
delta_content = FileContent(
delta=True,
index=index,
**kwargs,
)
else:
delta_content = TextContent(
delta=True,
Expand Down
2 changes: 1 addition & 1 deletion src/agentscope_runtime/version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# -*- coding: utf-8 -*-
__version__ = "v1.1.0b2"
__version__ = "v1.1.0b3"
Loading