Skip to content

Commit a74f1c9

Browse files
committed
update docs
1 parent 537c7b9 commit a74f1c9

File tree

5 files changed

+156
-163
lines changed

5 files changed

+156
-163
lines changed

docs/src/content/docs/guides/sessions.mdx

Lines changed: 17 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -9,109 +9,80 @@ import manageHistory from '../../../../../examples/docs/sessions/manageHistory.t
99
import customSession from '../../../../../examples/docs/sessions/customSession.ts?raw';
1010
import sessionInputCallback from '../../../../../examples/docs/sessions/sessionInputCallback.ts?raw';
1111

12-
Sessions give the Agents SDK a **persistent memory layer**. All you need is any
13-
object that implements the `Session` interface—pass it to `Runner.run` and the
14-
SDK will handle the rest. When a session is present, the runner automatically:
12+
Sessions give the Agents SDK a **persistent memory layer**. Provide any object that implements the `Session` interface to `Runner.run`, and the SDK handles the rest. When a session is present, the runner automatically:
1513

1614
1. Fetches previously stored conversation items and prepends them to the next turn.
1715
2. Persists new user input and assistant output after each run completes.
18-
3. Keeps the session available for future turns, whether you call the runner with
19-
new user text or resume from an interrupted `RunState`.
16+
3. Keeps the session available for future turns, whether you call the runner with new user text or resume from an interrupted `RunState`.
2017

21-
This removes the need to manually call `toInputList()` or stitch history together
22-
between turns. The TypeScript SDK currently ships with one ready-to-use
23-
`OpenAIConversationsSession`, and the same `Session` interface lets you bring your
24-
own storage. For inspiration beyond the OpenAI Conversations API, browse the
25-
sample session backends under `examples/memory/` (Prisma, file-backed, and more).
18+
This removes the need to manually call `toInputList()` or stitch history between turns. The TypeScript SDK ships with two implementations: `OpenAIConversationsSession` for the Conversations API and `MemorySession`, which is intended for local development. Because they share the `Session` interface, you can plug in your own storage backend. For inspiration beyond the Conversations API, explore the sample session backends under `examples/memory/` (Prisma, file-backed, and more).
2619

27-
> Tip: To run the `OpenAIConversationsSession` examples on this page, set the
28-
> `OPENAI_API_KEY` environment variable (or provide an `apiKey` when constructing
29-
> the session) so the SDK can call the Conversations API.
20+
> Tip: To run the `OpenAIConversationsSession` examples on this page, set the `OPENAI_API_KEY` environment variable (or provide an `apiKey` when constructing the session) so the SDK can call the Conversations API.
3021
3122
---
3223

3324
## Quick start
3425

35-
Use an `OpenAIConversationsSession` (or any other `Session` implementation) to sync memory with the
36-
[Conversations API](https://platform.openai.com/docs/api-reference/conversations).
26+
Use `OpenAIConversationsSession` to sync memory with the [Conversations API](https://platform.openai.com/docs/api-reference/conversations), or swap in any other `Session` implementation.
3727

3828
<Code
3929
lang="typescript"
4030
code={sessionsQuickstart}
4131
title="Use the Conversations API as session memory"
4232
/>
4333

44-
When you reuse the same session instance, the agent receives the full conversation
45-
history before every turn and writes new items back automatically.
46-
47-
Swap `OpenAIConversationsSession` with any other `Session` implementation—no other
48-
code changes are required.
34+
Reusing the same session instance ensures the agent receives the full conversation history before every turn and automatically persists new items. Switching to a different `Session` implementation requires no other code changes.
4935

5036
---
5137

5238
## How the runner uses sessions
5339

54-
- **Before each run** the runner retrieves the session history, merges it with the
55-
new turn’s input, and passes the combined list to your agent.
56-
- **After a non-streaming run** a single call to `session.addItems()` persists both
57-
the original user input and the model outputs from the latest turn.
58-
- **For streaming runs** the runner writes the user input up front and appends
59-
streamed outputs once the turn completes.
60-
- **When resuming from `RunResult.state`** (for approval flows or other interruptions)
61-
continue passing the same `session`. The resumed turn is added to memory without
62-
re-preparing the input.
40+
- **Before each run** it retrieves the session history, merges it with the new turn's input, and passes the combined list to your agent.
41+
- **After a non-streaming run** one call to `session.addItems()` persists both the original user input and the model outputs from the latest turn.
42+
- **For streaming runs** it writes the user input first and appends streamed outputs once the turn completes.
43+
- **When resuming from `RunResult.state`** (for approvals or other interruptions) keep passing the same `session`. The resumed turn is added to memory without re-preparing the input.
6344

6445
---
6546

6647
## Inspecting and editing history
6748

68-
Sessions expose simple CRUD helpers so you can build “undo”, “clear chat”, or audit
69-
features.
49+
Sessions expose simple CRUD helpers so you can build "undo", "clear chat", or audit features.
7050

7151
<Code
7252
lang="typescript"
7353
code={manageHistory}
7454
title="Read and edit stored items"
7555
/>
7656

77-
`session.getItems()` returns the stored `AgentInputItem[]`. Call `popItem()` to
78-
remove the last entry—useful for user corrections before you rerun the agent.
57+
`session.getItems()` returns the stored `AgentInputItem[]`. Call `popItem()` to remove the last entry—useful for user corrections before you rerun the agent.
7958

8059
---
8160

8261
## Bring your own storage
8362

84-
Implement the `Session` interface to back memory with Redis, DynamoDB,
85-
SQLite, or another datastore. Only five asynchronous methods are required.
63+
Implement the `Session` interface to back memory with Redis, DynamoDB, SQLite, or another datastore. Only five asynchronous methods are required.
8664

8765
<Code
8866
lang="typescript"
8967
code={customSession}
9068
title="Custom in-memory session implementation"
9169
/>
9270

93-
Custom sessions let you enforce retention policies, add encryption, or attach
94-
metadata to each conversation turn before persisting it.
71+
Custom sessions let you enforce retention policies, add encryption, or attach metadata to each conversation turn before persisting it.
9572

9673
---
9774

9875
## Control how history and new items merge
9976

100-
When you pass an array of `AgentInputItem`s as the run input, provide a
101-
`sessionInputCallback` to merge them with stored history deterministically.
102-
The runner loads the existing history, calls your callback **before the model
103-
invocation**, and hands the returned array to the model as the turn’s complete
104-
input. This hook is ideal for trimming old items, deduplicating tool results, or
105-
highlighting only the context you want the model to see.
77+
When you pass an array of `AgentInputItem`s as the run input, provide a `sessionInputCallback` to merge them with stored history deterministically. The runner loads the existing history, calls your callback **before the model invocation**, and hands the returned array to the model as the turn’s complete input. This hook is ideal for trimming old items, deduplicating tool results, or highlighting only the context you want the model to see.
10678

10779
<Code
10880
lang="typescript"
10981
code={sessionInputCallback}
11082
title="Truncate history with sessionInputCallback"
11183
/>
11284

113-
For string inputs the runner can merge history automatically, so you can omit the
114-
callback.
85+
For string inputs the runner merges history automatically, so the callback is optional.
11586

11687
---
11788

@@ -132,8 +103,4 @@ if (result.requiresApproval) {
132103
}
133104
```
134105

135-
Because sessions now work when resuming from a previous `RunState`, the continued
136-
turn is appended to the same memory record, maintaining a single coherent history
137-
for the conversation. This keeps human-in-the-loop (HITL) flows fully compatible—
138-
your approval checkpoints continue to round-trip through `RunState` while the
139-
session keeps the transcript complete.
106+
When you resume from a previous `RunState`, the new turn is appended to the same memory record to preserve a single conversation history. Human-in-the-loop (HITL) flows stay fully compatible—approval checkpoints still round-trip through `RunState` while the session keeps the transcript complete.

docs/src/content/docs/ja/guides/sessions.mdx

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,90 +9,86 @@ import manageHistory from '../../../../../../examples/docs/sessions/manageHistor
99
import customSession from '../../../../../../examples/docs/sessions/customSession.ts?raw';
1010
import sessionInputCallback from '../../../../../../examples/docs/sessions/sessionInputCallback.ts?raw';
1111

12-
セッションは Agents SDK **永続的なメモリ層**を与えます`Session` インターフェースを実装した任意のオブジェクトを用意し、それを `Runner.run` に渡すだけで、あとは SDK が処理します。セッションがある場合、ランナーは自動的に次を行います
12+
セッションは Agents SDK による **永続的なメモリレイヤー** を提供します`Session` インターフェースを実装する任意のオブジェクトを `Runner.run` に渡すだけで、残りは SDK が処理します。セッションがある場合、ランナーは自動的に次を行います:
1313

14-
1. 以前に保存された会話アイテムを取得し、次のターンの先頭に追加する
15-
2. 各実行完了後に新しいユーザー入力とアシスタント出力を永続化する
16-
3. 新しいユーザーのテキストでランナーを呼び出す場合でも、中断した `RunState` から再開する場合でも、将来のターンのためにセッションを利用可能な状態に保つ
14+
1. 以前に保存された会話アイテムを取得し、次のターンの先頭に付加します
15+
2. 各実行完了後に、新しいユーザー入力とアシスタント出力を永続化します
16+
3. 新しいユーザーのテキストでランナーを呼び出す場合でも、中断された `RunState` から再開する場合でも、将来のターンにセッションを利用可能に保ちます
1717

18-
これにより、ターン間で手動で `toInputList()` を呼び出したり、履歴をつなぎ合わせたりする必要がなくなります。TypeScript SDK には、すぐに使える `OpenAIConversationsSession` が同梱されています。同じ `Session` インターフェースを使えば、独自のストレージを持ち込むこともできます。OpenAI Conversations API 以外の発想については`examples/memory/` 配下のサンプルセッションバックエンド(Prisma、ファイルバックエンドなど)を参照してください。
18+
これにより、手動で `toInputList()` を呼び出したり、ターン間で履歴をつなぎ合わせたりする必要がなくなります。TypeScript SDK には 2 つの実装が同梱されています: Conversations API 用の `OpenAIConversationsSession` と、ローカル開発向けの `MemorySession` です。両者は `Session` インターフェースを共有するため、独自のストレージバックエンドを差し替えできます。Conversations API 以外のアイデアについては`examples/memory/` 配下のサンプルセッションバックエンド(Prisma、ファイル永続など)を参照してください。
1919

20-
> Tip: このページの `OpenAIConversationsSession` の例を実行するには、`OPENAI_API_KEY` 環境変数を設定する(またはセッション構築時に `apiKey` を指定する)ことで、SDK が Conversations API を呼び出せるようにしてください。
20+
> ヒント: このページの `OpenAIConversationsSession` の例を実行するには、`OPENAI_API_KEY` 環境変数を設定する(またはセッション構築時に `apiKey` を指定する)ことで、SDK が Conversations API を呼び出せるようにしてください。
2121
2222
---
2323

2424
## クイックスタート
2525

26-
`OpenAIConversationsSession`(または他の任意の `Session` 実装)を使用してメモリを
27-
[Conversations API](https://platform.openai.com/docs/api-reference/conversations)
28-
と同期します。
26+
`OpenAIConversationsSession` を使用して [Conversations API](https://platform.openai.com/docs/api-reference/conversations) とメモリを同期するか、他の任意の `Session` 実装に差し替えます。
2927

3028
<Code
3129
lang="typescript"
3230
code={sessionsQuickstart}
33-
title="Use the Conversations API as session memory"
31+
title="Conversations API をセッションメモリとして使用"
3432
/>
3533

36-
同じセッションインスタンスを再利用すると、エージェントは毎ターンの前に会話履歴全体を受け取り、新しいアイテムを書き戻します。
37-
38-
`OpenAIConversationsSession` を他の任意の `Session` 実装に差し替えても、他のコード変更は不要です。
34+
同じセッションインスタンスを再利用すると、各ターンの前にエージェントが完全な会話履歴を受け取り、新しいアイテムが自動的に永続化されます。別の `Session` 実装への切り替えでも、他のコード変更は不要です。
3935

4036
---
4137

42-
## ランナーによるセッションの利用方法
38+
## ランナーによるセッションの使用方法
4339

44-
- **各実行の前に** ランナーはセッション履歴を取得し、新しいターンの入力とマージして、その結合リストをエージェントに渡します
45-
- **非ストリーミング実行の後に** `session.addItems()` を 1 回呼び出して、元のユーザー入力と直近ターンのモデル出力の両方を永続化します
46-
- **ストリーミング実行では** ユーザー入力を先に書き込み、ターンが完了したらストリーミング出力を追記します
47-
- **`RunResult.state` から再開する場合**承認フローやその他の中断)同じ `session` を渡し続けます。再開したターンは入力の再準備なしにメモリへ追加されます
40+
- **各実行前に** セッション履歴を取得し、新しいターンの入力とマージして、結合リストをエージェントに渡します
41+
- **非ストリーミング実行後に** 1 回の `session.addItems()` 呼び出しで、直近ターンの元のユーザー入力とモデル出力の両方を永続化します
42+
- **ストリーミング実行では** まずユーザー入力を書き込み、ターン完了時にストリーム出力を追記します
43+
- **`RunResult.state` から再開する場合**承認やその他の中断)も同じ `session` を渡し続けます。再開したターンは、入力を再準備せずにメモリへ追加されます
4844

4945
---
5046

5147
## 履歴の確認と編集
5248

53-
セッションはシンプルな CRUD ヘルパーを公開しているため、「元に戻す」「チャットをクリア」「監査」といった機能を構築できます
49+
セッションはシンプルな CRUD ヘルパーを公開しているため、「取り消し」「チャットのクリア」や監査機能を構築できます
5450

5551
<Code
5652
lang="typescript"
5753
code={manageHistory}
58-
title="Read and edit stored items"
54+
title="保存済みアイテムの読み取りと編集"
5955
/>
6056

61-
`session.getItems()` は保存済みの `AgentInputItem[]` を返します。`popItem()` を呼び出して最後のエントリを削除できます。これは、エージェントを再実行する前のユーザー修正に便利です。
57+
`session.getItems()` は保存された `AgentInputItem[]` を返します。`popItem()` を呼び出して最後のエントリを削除できます。エージェントを再実行する前のユーザー修正に便利です。
6258

6359
---
6460

6561
## 独自ストレージの持ち込み
6662

67-
`Session` インターフェースを実装して、Redis、DynamoDB、SQLite などのデータストアでメモリを裏付けできます。必要なのは 5 つの非同期メソッドだけです。
63+
`Session` インターフェースを実装して、Redis、DynamoDB、SQLite などのデータストアでメモリを支えることができます。必要なのは 5 つの非同期メソッドだけです。
6864

6965
<Code
7066
lang="typescript"
7167
code={customSession}
72-
title="Custom in-memory session implementation"
68+
title="カスタムのインメモリセッション実装"
7369
/>
7470

75-
カスタムセッションを使うことで、保持ポリシーの適用、暗号化の追加、または永続化前に各会話ターンへメタデータを付与できます
71+
カスタムセッションにより、保持ポリシーの適用、暗号化の追加、各会話ターンにメタデータを付与してから永続化することが可能になります
7672

7773
---
7874

7975
## 履歴と新規アイテムのマージ方法の制御
8076

81-
実行入力として `AgentInputItem` の配列を渡すときは、保存済み履歴と決定論的にマージするために `sessionInputCallback` を指定します。ランナーは既存の履歴を読み込み**モデル呼び出しの前に** コールバックを呼び出し、返された配列をそのターンの完全な入力としてモデルに渡します。このフックは、古いアイテムの切り詰め、ツール結果の重複排除、またはモデルに見せたいコンテキストだけを強調表示するのに最適です
77+
実行入力として `AgentInputItem` の配列を渡す場合、`sessionInputCallback` を指定して、保存済み履歴とのマージを決定的に行えます。ランナーは既存履歴を読み込み**モデル呼び出し前に** コールバックを呼び出し、返された配列を当該ターンの完全な入力としてモデルに渡します。このフックは、古いアイテムのトリミング、ツール結果の重複排除、モデルに見せたいコンテキストのみを強調する用途に最適です
8278

8379
<Code
8480
lang="typescript"
8581
code={sessionInputCallback}
86-
title="Truncate history with sessionInputCallback"
82+
title="sessionInputCallback で履歴を切り詰め"
8783
/>
8884

89-
文字列入力の場合、ランナーは履歴を自動的にマージできるため、コールバックを省略できます
85+
文字列入力ではランナーが自動で履歴をマージするため、コールバックは任意です
9086

9187
---
9288

9389
## 承認と再開可能な実行の取り扱い
9490

95-
Human in the loop (人間の介入) フローでは、承認待ちのために実行を一時停止することがよくあります。
91+
Human-in-the-loop フローでは、承認待ちのために実行を一時停止することがあります:
9692

9793
```typescript
9894
const result = await runner.run(agent, 'Search the itinerary', {
@@ -107,4 +103,4 @@ if (result.requiresApproval) {
107103
}
108104
```
109105

110-
セッションは以前の `RunState` からの再開時にも機能するため、継続したターンは同じメモリレコードに追加され、会話の一貫した単一の履歴が維持されます。これにより Human in the loop (人間の介入) (HITL) フローとの完全な互換性が保たれます。承認チェックポイントは引き続き `RunState` を往復しつつ、セッションが全文書を完全に保ちます
106+
以前の `RunState` から再開する場合、新しいターンは同じメモリレコードに追記され、単一の会話履歴が維持されます。Human in the loop (人間の介入)HITL)フローとの互換性は完全に保たれ、承認チェックポイントは引き続き `RunState` を経由して往復しつつ、セッションが完全なトランスクリプトを保持します

0 commit comments

Comments
 (0)