ResponseFormat
@JsonInclude(JsonInclude.Include.NON_NULL) public class ResponseFormat
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.
io/agentscope/core/formatter/ResponseFormat.java:59方法详情Method Detail
text
public static ResponseFormat text()
返回文本。
Create a plain text response format.
ResponseFormatio/agentscope/core/formatter/ResponseFormat.java:71–73jsonObject
public static ResponseFormat jsonObject()
创建JSON 对象响应格式。
Create a JSON object response format.
ResponseFormatio/agentscope/core/formatter/ResponseFormat.java:83–85jsonSchema
public static ResponseFormat jsonSchema(JsonSchema schema)
创建JSON 模式响应格式使用结构化输出校验。
Create a JSON Schema response format with structured output validation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
schema | JsonSchema | 模式定义(类型 `JsonSchema`)。The JSON Schema defining the expected structure |
ResponseFormatio/agentscope/core/formatter/ResponseFormat.java:97–99getType
public String getType()
获取类型。
Returns the type.
Stringio/agentscope/core/formatter/ResponseFormat.java:101–103setType
public void setType(String type)
设置类型。
Sets the type.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
type | String | 类型(类型 `String`)。The type. |
io/agentscope/core/formatter/ResponseFormat.java:105–107getJsonSchema
public JsonSchema getJsonSchema()
获取JSON 模式。
Returns the json schema.
JsonSchemaio/agentscope/core/formatter/ResponseFormat.java:109–111setJsonSchema
public void setJsonSchema(JsonSchema jsonSchema)
设置JSON 模式。
Sets the json schema.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
jsonSchema | JsonSchema | JSON 模式(类型 `JsonSchema`)。The json schema. |
io/agentscope/core/formatter/ResponseFormat.java:113–115builder
public static Builder builder()
返回构建器实例。
Returns the builder.
Builderio/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.