> For the complete documentation index, see [llms.txt](https://docs.maiagent.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.maiagent.ai/tech/ja/api-integration/endpoint-behaviors/chatbot-reply-mode-api.md).

# Agent の回答モードと構造化出力フィールド

Agent の回答モード（replyMode）と管理画面の名称の対応、および構造化出力フィールド outputMode、rawOutputFormat の組み合わせルールとレスポンスの形式を説明します。

`GET`／`PATCH /api/v1/chatbots/{id}/` の `replyMode`、`outputMode`、`rawOutputFormat` の3つのフィールドで、Agent の回答方法が決まります。フィールドの型は API ドキュメントの [AI アシスタント](https://docs.maiagent.ai/api/api-reference/ai-zhu-li) を参照してください。このページでは、各値の意味と組み合わせの制約を補足します。

## 回答モードの対応表 <a href="#reply-modes" id="reply-modes"></a>

管理画面の「回答モード設定」に表示される名称と API の `replyMode` の値は、以下のように対応します。`replyMode` はストリーミングか同期かの選択には関係しません。ストリーミングは `completions` リクエストの `isStreaming` で決まります。

| 管理画面の名称                     | `replyMode` | 動作                                                                                                          |
| --------------------------- | ----------- | ----------------------------------------------------------------------------------------------------------- |
| Agent モード（新しい Agent のデフォルト） | `agent`     | モデルが検索対象と呼び出すツールを自ら判断し、複数のステップを実行できます。ツール、Code Interpreter、データベース、スキル、MaiGPT コネクタ、Agent UI は、このモードでのみ利用できます |
| RAG 質疑応答                    | `normal`    | メッセージごとにナレッジベースを1回検索してから回答します。[RAG ナレッジベース検索システム](/tech/ja/quickstart/rag.md) を参照してください                     |
| テンプレート（その他のモード）             | `template`  | ナレッジベースと FAQ に基づいて分類別に回答し、モデルによる自由な生成は行いません                                                                 |
| ハイブリッド（その他のモード）             | `hybrid`    | 一部の内容はテンプレート形式で、それ以外は自由に回答します                                                                               |

従来の `workflow` 値は廃止されました。既存の Agent の扱いは、[組み込みワークフロー回答モードの廃止](/tech/ja/api-integration/endpoint-behaviors/workflow-reply-mode-retirement.md) を参照してください。各モードの設定方法は、ユーザーマニュアルの [Agent の作成：適切な回答モードの選択](https://docs.maiagent.ai/build/agent/setup#select-answer-mode-to-build-prompt) を参照してください。

## 構造化出力 <a href="#structured-output" id="structured-output"></a>

| フィールド             | 値                            | 説明                                                                                                                                |
| ----------------- | ---------------------------- | --------------------------------------------------------------------------------------------------------------------------------- |
| `outputMode`      | `text`（デフォルト）／`json_schema`  | `json_schema` は、すべての回答が `rawOutputFormat` に準拠した JSON になることを示します                                                                   |
| `rawOutputFormat` | JSON Schema オブジェクトまたは `null` | 回答が準拠すべき構造です。最上位に `"type": "object"` を指定し、各フィールドに `type` と `description` を記述します。保存時に有効な JSON Schema かどうかが検証され、無効な場合は `400` が返されます |

組み合わせの制約：

* `replyMode` が `normal`（RAG 質疑応答）の場合にのみ有効です。Agent モードでは、この2つのフィールドは無視されます。
* モデルが構造化出力に対応している必要があります。`GET /api/v1/large-language-models/` で返される各モデルの `outputMode` 配列には、対応する値が列挙されます。`json_schema` を含むモデルでのみ利用できます。管理画面に「出力形式」フィールドが表示されない場合は、現在のモデルまたは回答モードが対応していません。
* `outputMode` が `json_schema` の場合、`rawOutputFormat` を `null` にすることはできません。`text` に戻す場合は、既存のスキーマを保持できますが、そのスキーマは適用されません。

### レスポンスの形式 <a href="#structured-response" id="structured-response"></a>

構造化出力でも、レスポンスの外側の構造は変わりません。`completions` とメッセージオブジェクトの `content` は引き続き文字列で、その内容はスキーマに準拠した JSON テキストです。`JSON.parse` や `json.loads` で解析してください。回答全体の生成が完了してから検証する必要があるため、`isStreaming: true` の場合、SSE には `done: true` のイベントが1つだけ含まれ、`content` には完全な JSON が入ります。[ストリーミングにならないケース](/tech/ja/api-integration/dui-hua-yu-xun-xi-hui-fu-chuan-liu-tong-bu.md#non-streaming-cases) を参照してください。Web Chat はこの JSON をテキストとして表示するため、構造化出力を使用する Agent は通常 API 経由でのみ利用します。

```json
PATCH /api/v1/chatbots/{id}/
{
  "replyMode": "normal",
  "outputMode": "json_schema",
  "rawOutputFormat": {
    "type": "object",
    "properties": {
      "intent": {"type": "string", "description": "質問の分類：返品、問い合わせ、苦情、その他"},
      "orderId": {"type": "string", "description": "メッセージに記載された注文番号。記載がない場合は空文字列"}
    },
    "required": ["intent", "orderId"]
  }
}
```

モデルが生成した内容がスキーマに準拠していない場合（まれですが、多くはモデルの能力不足が原因です）も、回答はテキストとして送信され、プラットフォームはエラーコードを返しません。解析に失敗した場合は、プログラムで人による対応に切り替えるか、対応度の高いモデルに変更してください。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.maiagent.ai/tech/ja/api-integration/endpoint-behaviors/chatbot-reply-mode-api.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
