Skip to content

非公式本サイトは非公式の日本語ドキュメントであり、Cloudflare 公式サイトではありません。最新情報はdevelopers.cloudflare.comをご確認ください。

HTTP API

最終更新 Markdown で表示Agent セットアップ

Cloudflare Workers の外で動くサービスから Agent Memory を呼び出すには、HTTP API を使います。Workers アプリケーションでは、agent_memory バインディング経由で Workers API を使います。

HTTP API では、名前空間(namespace)とプロファイル(profile)を使います。名前空間はアプリケーションのプロファイルを区切り、各プロファイルは独立したメモリストアです。プロファイルは、初めて書き込んだときに自動で作成されます。

認証

すべてのリクエストには、適切な Agent Memory 権限を持つ API トークン が必要です。

API トークンは Authorization ヘッダーに含めます。

Authorization: Bearer <API_TOKEN>

Cloudflare API の呼び出し方法は、API を呼び出す を参照してください。

名前空間の管理

名前空間 は、アプリケーションのメモリプロファイルを区切る最上位のコンテナです。

名前空間を作成する

指定したアカウントに新しい名前空間を作成します。

curl -X POST "https://api.cloudflare.com/client/v4/accounts/<ACCOUNT_ID>/agent-memory/namespaces" \
  -H "Authorization: Bearer <API_TOKEN>" \
  -H "Content-Type: application/json" \
  -d '{"name": "support-agent"}'

レスポンスには、Workers のバインディングと HTTP API 呼び出しで使う名前空間名が含まれます。

{
	"result": {
		"id": "01JSGCEXAMPLE000000000000",
		"name": "support-agent",
		"created_at": "2026-04-21T00:00:00.000Z",
		"updated_at": "2026-04-21T00:00:00.000Z"
	},
	"success": true,
	"errors": [],
	"messages": []
}

名前空間を一覧する

指定したアカウントの名前空間をすべて一覧します。結果はページ分割されます。

curl "https://api.cloudflare.com/client/v4/accounts/<ACCOUNT_ID>/agent-memory/namespaces?per_page=50" \
  -H "Authorization: Bearer <API_TOKEN>"
{
	"result": [
		{
			"id": "01JSGCEXAMPLE000000000000",
			"name": "support-agent",
			"created_at": "2026-04-21T00:00:00.000Z",
			"updated_at": "2026-04-21T00:00:00.000Z"
		}
	],
	"success": true,
	"errors": [],
	"messages": [],
	"result_info": {
		"cursor": "next-cursor",
		"per_page": 50,
		"count": 1
	}
}

名前空間を取得する

名前で名前空間を 1 件取得します。

curl "https://api.cloudflare.com/client/v4/accounts/<ACCOUNT_ID>/agent-memory/namespaces/<NAMESPACE_NAME>" \
  -H "Authorization: Bearer <API_TOKEN>"
{
	"result": {
		"id": "01JSGCEXAMPLE000000000000",
		"name": "support-agent",
		"created_at": "2026-04-21T00:00:00.000Z",
		"updated_at": "2026-04-21T00:00:00.000Z"
	},
	"success": true,
	"errors": [],
	"messages": []
}

名前空間を削除する

名前空間を削除対象としてマークします。削除後、その名前空間名は再利用できるようになります。

curl -X DELETE "https://api.cloudflare.com/client/v4/accounts/<ACCOUNT_ID>/agent-memory/namespaces/<NAMESPACE_NAME>" \
  -H "Authorization: Bearer <API_TOKEN>"
{
	"result": null,
	"success": true,
	"errors": [],
	"messages": []
}

プロファイル

プロファイルのエンドポイントで、名前付きプロファイルとその中のメモリを操作します。プロファイルは、初めて書き込んだときに自動で作成されます。

プロファイルを削除する

プロファイルと、その中のメモリおよびメッセージをすべて削除対象としてマークします。

curl -X DELETE "https://api.cloudflare.com/client/v4/accounts/<ACCOUNT_ID>/agent-memory/namespaces/<NAMESPACE_NAME>/profiles/<PROFILE_NAME>" \
  -H "Authorization: Bearer <API_TOKEN>"
{
	"result": null,
	"success": true,
	"errors": [],
	"messages": []
}

セッションを削除する

指定したセッション ID が付いた、プロファイル内のメモリとメッセージをすべて削除対象としてマークします。同じプロファイル内の他のセッションの行は変更しません。べき等です。該当する行がないセッション ID を削除しても、何も起こりません。

curl -X DELETE "https://api.cloudflare.com/client/v4/accounts/<ACCOUNT_ID>/agent-memory/namespaces/<NAMESPACE_NAME>/profiles/<PROFILE_NAME>/sessions/<SESSION_ID>" \
  -H "Authorization: Bearer <API_TOKEN>"
{
	"result": null,
	"success": true,
	"errors": [],
	"messages": []
}

メッセージを取り込む

会話を処理し、構造化したメモリを抽出します。Agent Memory が事実、イベント、指示、タスクを自動で識別するため、何を覚えるかを指定する必要はありません。

curl -X POST "https://api.cloudflare.com/client/v4/accounts/<ACCOUNT_ID>/agent-memory/namespaces/<NAMESPACE_NAME>/profiles/<PROFILE_NAME>/ingest" \
  -H "Authorization: Bearer <API_TOKEN>" \
  -H "Content-Type: application/json" \
  -d '{
    "messages": [
      {
        "role": "user",
        "content": "I prefer concise answers.",
        "timestamp": "2026-04-21T00:00:00.000Z"
      }
    ],
    "sessionId": "chat-2026-04-21"
  }'
{
	"result": null,
	"success": true,
	"errors": [],
	"messages": []
}

ingest はべき等です。同じ会話を再度取り込んでも、重複したメモリは作成されません。

メモリを記憶する

メモリを 1 件、明示的に保存します。アプリケーションやエージェントが保存すべき内容をすでに把握している場合は remember を使います。

curl -X POST "https://api.cloudflare.com/client/v4/accounts/<ACCOUNT_ID>/agent-memory/namespaces/<NAMESPACE_NAME>/profiles/<PROFILE_NAME>/remember" \
  -H "Authorization: Bearer <API_TOKEN>" \
  -H "Content-Type: application/json" \
  -d '{
    "content": "The user prefers concise answers.",
    "sessionId": "chat-2026-04-21"
  }'
{
	"result": {
		"id": "01JSGCEXAMPLE000000000000",
		"type": "instruction",
		"summary": "The user prefers concise answers.",
		"content": "The user prefers concise answers.",
		"sessionId": "chat-2026-04-21",
		"createdAt": "2026-04-21T00:00:00.000Z",
		"updatedAt": "2026-04-21T00:00:00.000Z"
	},
	"success": true,
	"errors": [],
	"messages": []
}

メモリを想起する

プロファイル内の保存済みメモリを検索し、保存済みの内容に基づいて合成した回答を返します。

curl -X POST "https://api.cloudflare.com/client/v4/accounts/<ACCOUNT_ID>/agent-memory/namespaces/<NAMESPACE_NAME>/profiles/<PROFILE_NAME>/recall" \
  -H "Authorization: Bearer <API_TOKEN>" \
  -H "Content-Type: application/json" \
  -d '{
    "query": "How should I answer this user?",
    "thinkingLevel": "low",
    "responseLength": "medium"
  }'
{
	"result": {
		"answer": "The user prefers concise answers.",
		"count": 1,
		"candidates": [
			{
				"id": "01JSGCEXAMPLE000000000000",
				"summary": "The user prefers concise answers.",
				"sessionId": "chat-2026-04-21",
				"score": 0.87
			}
		]
	},
	"success": true,
	"errors": [],
	"messages": []
}

クエリに一致するメモリがない場合、recall は空の回答を返します。

メモリを一覧する

プロファイルに保存されているメモリを一覧します。

curl "https://api.cloudflare.com/client/v4/accounts/<ACCOUNT_ID>/agent-memory/namespaces/<NAMESPACE_NAME>/profiles/<PROFILE_NAME>/memories?per_page=50" \
  -H "Authorization: Bearer <API_TOKEN>"
{
	"result": [
		{
			"id": "01JSGCEXAMPLE000000000000",
			"type": "instruction",
			"summary": "The user prefers concise answers.",
			"sessionId": "chat-2026-04-21",
			"createdAt": "2026-04-21T00:00:00.000Z",
			"updatedAt": "2026-04-21T00:00:00.000Z"
		}
	],
	"success": true,
	"errors": [],
	"messages": [],
	"result_info": {
		"cursor": "next-cursor",
		"per_page": 50,
		"count": 1
	}
}

一覧の各エントリには content は含まれません。メモリ全体を取得するには、メモリ取得エンドポイントを使います。

メモリを絞り込むには、session_idtype のクエリパラメーターを使います。

メモリを取得する

ID でメモリを 1 件取得します。

curl "https://api.cloudflare.com/client/v4/accounts/<ACCOUNT_ID>/agent-memory/namespaces/<NAMESPACE_NAME>/profiles/<PROFILE_NAME>/memories/<MEMORY_ID>" \
  -H "Authorization: Bearer <API_TOKEN>"
{
	"result": {
		"id": "01JSGCEXAMPLE000000000000",
		"type": "instruction",
		"summary": "The user prefers concise answers.",
		"content": "The user prefers concise answers.",
		"sessionId": "chat-2026-04-21",
		"createdAt": "2026-04-21T00:00:00.000Z",
		"updatedAt": "2026-04-21T00:00:00.000Z"
	},
	"success": true,
	"errors": [],
	"messages": []
}

メモリを削除する

ID でメモリを削除します。そのメモリと、紐づくソースメッセージを削除します。削除したメモリを返します。

curl -X DELETE "https://api.cloudflare.com/client/v4/accounts/<ACCOUNT_ID>/agent-memory/namespaces/<NAMESPACE_NAME>/profiles/<PROFILE_NAME>/memories/<MEMORY_ID>" \
  -H "Authorization: Bearer <API_TOKEN>"
{
	"result": {
		"id": "01JSGCEXAMPLE000000000000",
		"type": "instruction",
		"summary": "The user prefers concise answers.",
		"content": "The user prefers concise answers.",
		"sessionId": "chat-2026-04-21",
		"createdAt": "2026-04-21T00:00:00.000Z",
		"updatedAt": "2026-04-21T00:00:00.000Z"
	},
	"success": true,
	"errors": [],
	"messages": []
}

サマリーを取得する

メモリプロファイルに保存されている内容全体の、構造化した Markdown サマリーを生成します。Agent Memory がそのプロファイルについて覚えている内容を確認するときに使います。

curl -X POST "https://api.cloudflare.com/client/v4/accounts/<ACCOUNT_ID>/agent-memory/namespaces/<NAMESPACE_NAME>/profiles/<PROFILE_NAME>/summary" \
  -H "Authorization: Bearer <API_TOKEN>" \
  -H "Content-Type: application/json" \
  -d '{}'
{
	"result": {
		"summary": "## Summary\n\nThe user prefers concise answers."
	},
	"success": true,
	"errors": [],
	"messages": []
}

サマリーの 「Last Session」セクションの対象を絞るには、リクエストボディに sessionId フィールドを含めます。

エラーレスポンス

失敗時、すべてのエンドポイントは標準の Cloudflare V4 エラーレスポンスを返します。

{
	"result": null,
	"success": false,
	"errors": [
		{
			"code": 10008,
			"message": "Namespace name already exists"
		}
	],
	"messages": []
}

よくあるエラーの例は次のとおりです。

状況 HTTP ステータス
名前空間名の形式が不正 400
認証に失敗した 401
名前空間名がすでに存在する 409
名前空間が見つからない 404
プロファイルが見つからない 404

役に立ちましたか?