AS AgentScopeAPI 手册 / API Reference

ResponseFormat

@JsonInclude(JsonInclude.Include.NON_NULL) public class ResponseFormat
源码Source io/agentscope/core/formatter/ResponseFormat.java:48–140

用于模型 APIs的响应格式配置。位于 io.agentscope.core.formatter 包。核心成员包括 text、jsonObject、jsonSchema、getType、setType、getJsonSchema。

Response format configuration for model APIs.

This class supports three response format types:

  • text: Plain text response (default)

  • json_object: Valid JSON object response

  • json_schema: Response conforming to a specific JSON Schema

Example usage:

`// Plain text
ResponseFormat format = ResponseFormat.text();

// JSON object
ResponseFormat format = ResponseFormat.jsonObject();

// JSON Schema with strict validation
JsonSchema schema = JsonSchema.builder()
.name("MathResponse")
.schema(Map.of("type", "object", ...))
.strict(true)
.build();
ResponseFormat format = ResponseFormat.jsonSchema(schema);
`

嵌套类摘要Nested Class Summary

类Class类型Kind说明Description
Builder类class
构建器,用于构建并配置目标实例。
A class in io.agentscope.core.formatter that carries structured messages and events between agents, models and UIs.

构造器摘要Constructor Summary

构造器Constructor说明Description
public ResponseFormat()
初始化 `ResponseFormat` 实例。
Creates a new instance.

方法摘要Method Summary

方法Method说明Description
public static ResponseFormat text()
static
返回文本。
Create a plain text response format.
public static ResponseFormat jsonObject()
static
创建JSON 对象响应格式。
Create a JSON object response format.
public static ResponseFormat jsonSchema(JsonSchema schema)
static
创建JSON 模式响应格式使用结构化输出校验。
Create a JSON Schema response format with structured output validation.
public String getType()
获取类型。
Returns the type.
public void setType(String type)
设置类型。
Sets the type.
public JsonSchema getJsonSchema()
获取JSON 模式。
Returns the json schema.
public void setJsonSchema(JsonSchema jsonSchema)
设置JSON 模式。
Sets the json schema.
public static Builder builder()
static
返回构建器实例。
Returns the builder.

构造器详情Constructor Detail

ResponseFormat

public ResponseFormat()

初始化 ResponseFormat 实例。

Creates a new instance.

源码Source io/agentscope/core/formatter/ResponseFormat.java:59

方法详情Method Detail

text

public static ResponseFormat text()
static

返回文本。

Create a plain text response format.

返回Returns ResponseFormat
返回ResponseFormat。ResponseFormat configured for plain text
源码Source io/agentscope/core/formatter/ResponseFormat.java:71–73

jsonObject

public static ResponseFormat jsonObject()
static

创建JSON 对象响应格式。

Create a JSON object response format.

返回Returns ResponseFormat
返回ResponseFormat。ResponseFormat configured for JSON object
源码Source io/agentscope/core/formatter/ResponseFormat.java:83–85

jsonSchema

public static ResponseFormat jsonSchema(JsonSchema schema)
static

创建JSON 模式响应格式使用结构化输出校验。

Create a JSON Schema response format with structured output validation.

参数Parameters
名称Name类型Type说明Description
schemaJsonSchema模式定义(类型 `JsonSchema`)。The JSON Schema defining the expected structure
返回Returns ResponseFormat
返回ResponseFormat。ResponseFormat configured for JSON Schema validation
源码Source io/agentscope/core/formatter/ResponseFormat.java:97–99

getType

public String getType()

获取类型。

Returns the type.

返回Returns String
返回字符串结果。Returns a string.
源码Source io/agentscope/core/formatter/ResponseFormat.java:101–103

setType

public void setType(String type)

设置类型。

Sets the type.

参数Parameters
名称Name类型Type说明Description
typeString类型(类型 `String`)。The type.
源码Source io/agentscope/core/formatter/ResponseFormat.java:105–107

getJsonSchema

public JsonSchema getJsonSchema()

获取JSON 模式。

Returns the json schema.

返回Returns JsonSchema
返回JsonSchema。Returns json schema.
源码Source io/agentscope/core/formatter/ResponseFormat.java:109–111

setJsonSchema

public void setJsonSchema(JsonSchema jsonSchema)

设置JSON 模式。

Sets the json schema.

参数Parameters
名称Name类型Type说明Description
jsonSchemaJsonSchemaJSON 模式(类型 `JsonSchema`)。The json schema.
源码Source io/agentscope/core/formatter/ResponseFormat.java:113–115

builder

public static Builder builder()
static

返回构建器实例。

Returns the builder.

返回Returns Builder
返回当前实例,以支持链式调用。Returns the current instance for chaining.
源码Source io/agentscope/core/formatter/ResponseFormat.java:117–119

嵌套类详情Nested Class Detail

Builder

public static class Builder

构建器,用于构建并配置目标实例。位于 io.agentscope.core.formatter 包。核心成员包括 type、jsonSchema、build。

A class in io.agentscope.core.formatter that carries structured messages and events between agents, models and UIs. Declared in io.agentscope.core.formatter.

基于官方固定版本源码静态生成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.