AS AgentScopeAPI 手册 / API Reference
类class agentscope.model

ChatResponse

@dataclass
class ChatResponse(DictMixin)
源码Source agentscope/model/_model_response.py:32–317

聊天模型的响应。位于 agentscope.model 包,继承自 DictMixin。核心成员包括 append_text、append_thinking、append_tool_call、append_data_block、append_chat_response。

The response of chat models. Declared in agentscope.model. Extends DictMixin.

属性摘要Attribute Summary

属性Attribute类型Type说明Description值Value
contentList[TextBlock | ToolCallBlock | ThinkingBlock | DataBlock]
内容字段。
—
is_lastbool
是最后字段。
—
idstr
标识字段。
field(default_factory=_generate_id)
created_atstr
已创建 at字段。
field(default_factory=_generate_timestamp)
typeLiteral['chat_response']
类型字段。
field(default_factory=lambda: 'chat_response')
usageChatUsage | None
用量字段。
field(default_factory=lambda: None)
finished_reasonFinishedReason
`finished_reason` 字段。
field(default_factory=lambda: FinishedReason.COMPLETED)
metadatadict[str, JSONSerializableObject]
元数据字段。
field(default_factory=lambda: {})

方法摘要Method Summary

方法Method说明Description
def append_text(text: str, block_id: str | None = None) -> Self
追加文本。
Append text to the current response.
def append_thinking(thinking: str, block_id: str | None = None, **extra_fields: Any) -> Self
追加 `append_thinking`。
Append thinking to the current response.
def append_tool_call(block_id: str, name: str, input: str, **extra_fields: Any) -> Self
追加工具调用。
Append tool call to the current response by tool call block ID.
def append_data_block(block_id: str, data: bytes, media_type: str, name: str | None = None) -> Self
追加数据块。
Append raw media bytes to the ``DataBlock`` with the given id.
def append_chat_response(chat_response: Self) -> Self
追加聊天响应。
Append chat response to the current response.

属性详情Attribute Detail

content

List[TextBlock | ToolCallBlock | ThinkingBlock | DataBlock]

内容字段。声明为 List[TextBlock | ToolCallBlock | ThinkingBlock | DataBlock]。

The content field.

源码Source agentscope/model/_model_response.py:35

is_last

bool

是最后字段。声明为 bool。

The is last field.

源码Source agentscope/model/_model_response.py:39

id

str = field(default_factory=_generate_id)

标识字段。声明为 str。

The id field.

源码Source agentscope/model/_model_response.py:43

created_at

str = field(default_factory=_generate_timestamp)

已创建 at字段。声明为 str。

The created at field.

源码Source agentscope/model/_model_response.py:46

type

Literal['chat_response'] = field(default_factory=lambda: 'chat_response')

类型字段。声明为 Literal['chat_response']。

The type field.

源码Source agentscope/model/_model_response.py:49

usage

ChatUsage | None = field(default_factory=lambda: None)

用量字段。声明为 ChatUsage | None。

The usage field.

源码Source agentscope/model/_model_response.py:54

finished_reason

FinishedReason = field(default_factory=lambda: FinishedReason.COMPLETED)

finished_reason 字段。声明为 FinishedReason。

The finished reason field.

源码Source agentscope/model/_model_response.py:57

metadata

dict[str, JSONSerializableObject] = field(default_factory=lambda: {})

元数据字段。声明为 dict[str, JSONSerializableObject]。

The metadata field.

源码Source agentscope/model/_model_response.py:63

方法详情Method Detail

append_text

def append_text(text: str, block_id: str | None = None) -> Self

追加文本。

Append text to the current response.

参数Parameters
名称Name类型Type说明Description
textstr文本(类型 `str`)。The text.
block_id默认default Nonestr | None块标识(类型 `str | None`)。The block id.
返回Returns Self
返回自身。Returns self.
源码Source agentscope/model/_model_response.py:68–82

append_thinking

def append_thinking(thinking: str, block_id: str | None = None, **extra_fields: Any) -> Self

追加 append_thinking。

Append thinking to the current response.

参数Parameters
名称Name类型Type说明Description
thinkingstrthinking(类型 `str`)。The thinking content to append.
block_id默认default Nonestr | None块标识(类型 `str | None`)。The id of the `ThinkingBlock` to accumulate into. If no matching block exists in `content`, a new one is appended.
extra_fieldsAnyextra fields(类型 `Any`)。The extra fields.
返回Returns Self
返回自身。Returns self.
源码Source agentscope/model/_model_response.py:84–121

append_tool_call

def append_tool_call(block_id: str, name: str, input: str, **extra_fields: Any) -> Self

追加工具调用。

Append tool call to the current response by tool call block ID.

参数Parameters
名称Name类型Type说明Description
block_idstr块标识(类型 `str`)。The id of the `ToolCallBlock` to accumulate into. If no matching block exists in `content`, a new one is appended.
namestr名称(类型 `str`)。The name of the tool being called.
inputstr输入消息(类型 `str`)。The incremental JSON string arguments to append.
extra_fieldsAnyextra fields(类型 `Any`)。The extra fields.
返回Returns Self
返回自身。Returns self.
源码Source agentscope/model/_model_response.py:123–164

append_data_block

def append_data_block(block_id: str, data: bytes, media_type: str, name: str | None = None) -> Self

追加数据块。

The accumulated bytes are stored base64-encoded in DataBlock.source.data (via a :class:Base64Source).

说明Notes

  • 注意:该行为受运行时配置或底层实现影响,建议结合对应源码与版本说明确认。Note: Byte-level delta accumulation only has a well-defined semantics for streaming media where chunks can be safely concatenated (currently `audio/*`). For non-streamable media types (e.g. `image/*`, `video/*`) each `DataBlock` should be treated as a complete file and passed atomically rather than accumulated through this method.
参数Parameters
名称Name类型Type说明Description
block_idstr块标识(类型 `str`)。The id of the `DataBlock` to accumulate into. If no matching block exists in `content`, a new one is appended.
databytes数据(类型 `bytes`)。The incremental raw media bytes to append.
media_typestrmedia 类型(类型 `str`)。The IANA media type of the raw bytes (e.g. `audio/pcm`, `audio/wav`). Used both to tag a newly-created block and to guard against accidentally mixing bytes from different media types under the same id.
name默认default Nonestr | None名称(类型 `str | None`)。The optional `name` field used when a new `DataBlock` needs to be created. Ignored when an existing block with `block_id` is found.
返回Returns Self
返回自身。`Self`:
源码Source agentscope/model/_model_response.py:166–238

append_chat_response

def append_chat_response(chat_response: Self) -> Self

追加聊天响应。

Append chat response to the current response.

参数Parameters
名称Name类型Type说明Description
chat_responseSelf聊天响应(类型 `Self`)。The chat response.
返回Returns Self
返回自身。Returns self.
源码Source agentscope/model/_model_response.py:240–317
基于官方固定版本源码静态生成Generated from pinned official sources · Python 2.0.11 · Java 2.0.4
签名与文档为静态抽取;如有疑问请以源码为准。Signatures and docs are extracted statically; verify against the source when in doubt.