-
Notifications
You must be signed in to change notification settings - Fork 834
Add per-thread TTL configuration #1316
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,7 +1,9 @@ | ||||||
| --- | ||||||
| title: How to add TTLs to your application | ||||||
| sidebarTitle: Add TTLs to your application | ||||||
|
|
||||||
| --- | ||||||
|
|
||||||
| <Tip> | ||||||
| **Prerequisites** | ||||||
| This guide assumes familiarity with [LangSmith](/langsmith/home), [Persistence](/oss/langgraph/persistence), and [Cross-thread persistence](/oss/langgraph/persistence#memory-store) concepts. | ||||||
|
|
@@ -11,6 +13,8 @@ LangSmith persists both [checkpoints](/oss/langgraph/persistence#checkpoints) (t | |||||
|
|
||||||
| ## Configuring checkpoint TTL | ||||||
|
|
||||||
|
|
||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
|
||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| Checkpoints capture the state of conversation threads. Setting a TTL ensures old checkpoints and threads are automatically deleted. | ||||||
|
|
||||||
| Add a `checkpointer.ttl` configuration to your `langgraph.json` file: | ||||||
|
|
@@ -22,7 +26,7 @@ Add a `checkpointer.ttl` configuration to your `langgraph.json` file: | |||||
| "agent": "./agent.py:graph" | ||||||
| }, | ||||||
| "checkpointer": { | ||||||
| "ttl": { | ||||||
| "ttl": {c | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| "strategy": "delete", | ||||||
| "sweep_interval_minutes": 60, | ||||||
| "default_ttl": 43200 | ||||||
|
|
@@ -88,6 +92,21 @@ You can configure TTLs for both checkpoints and store items in the same `langgra | |||||
| } | ||||||
| ``` | ||||||
|
|
||||||
| ## Configuring Per-Thread TTL | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
|
||||||
| From `langgraph-api` [v0.4.11](https://docs.langchain.com/langsmith/agent-server-changelog#v0-4-11) you are now able to apply TTL configurations per-thread via thread updates. Here is an example: | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
|
||||||
| ```python | ||||||
| thread = await client.threads.create( | ||||||
| ttl={ | ||||||
| "strategy": "delete", | ||||||
| "ttl": 43200 # 30 days in minutes | ||||||
| } | ||||||
| ) | ||||||
| ``` | ||||||
|
|
||||||
|
|
||||||
|
|
||||||
| ## Runtime overrides | ||||||
|
|
||||||
| The default `store.ttl` settings from `langgraph.json` can be overridden at runtime by providing specific TTL values in SDK method calls like `get`, `put`, and `search`. | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.