会話間での長期メモリーの共有
memory_subject_idメタデータ・パラメータを使用して、会話間で長期的なメモリー情報を共有できます。
memory_subject_id isメタデータ・パラメータは、メモリーのプロジェクト・スコープの一意の識別子です。同じmemory_subject_idで作成されたすべての会話は、同じ長期間のメモリー領域を共有します。
サンプル・コード:
# first conversation
conversation1 = client.conversations.create(
metadata={ "memory_subject_id": "user_123456" },
)
# a turn on first conversation
response = client.responses.create(
model="openai.gpt-4.1",
input="I like Fish. I don't like Shrimp.",
conversation=conversation1.id
)
print(response.output_text)
# delay for long-term memory processing
time.sleep(10)
# second conversation
conversation2 = client.conversations.create(
metadata={ "memory_subject_id": "user_123456" },
)
# a turn on second conversation
response = client.responses.create(
model="openai.gpt-4.1",
input="What do I like",
conversation=conversation2.id
)
print(response.output_text)