Skip to content
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

checkpoint: support serde for SecretStr #1873

Merged
merged 1 commit into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions libs/checkpoint/langgraph/checkpoint/serde/jsonplus.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import dataclasses

Check notice on line 1 in libs/checkpoint/langgraph/checkpoint/serde/jsonplus.py

View workflow job for this annotation

GitHub Actions / benchmark

Benchmark results

......................................... fanout_to_subgraph_10x: Mean +- std dev: 59.5 ms +- 1.7 ms ......................................... WARNING: the benchmark result may be unstable * the standard deviation (6.46 ms) is 11% of the mean (56.7 ms) Try to rerun the benchmark with more runs, values and/or loops. Run 'python -m pyperf system tune' command to reduce the system jitter. Use pyperf stats, pyperf dump and pyperf hist to analyze results. Use --quiet option to hide these warnings. fanout_to_subgraph_10x_sync: Mean +- std dev: 56.7 ms +- 6.5 ms ......................................... fanout_to_subgraph_10x_checkpoint: Mean +- std dev: 76.8 ms +- 0.9 ms ......................................... fanout_to_subgraph_10x_checkpoint_sync: Mean +- std dev: 81.5 ms +- 1.0 ms ......................................... fanout_to_subgraph_100x: Mean +- std dev: 558 ms +- 10 ms ......................................... fanout_to_subgraph_100x_sync: Mean +- std dev: 504 ms +- 5 ms ......................................... fanout_to_subgraph_100x_checkpoint: Mean +- std dev: 774 ms +- 26 ms ......................................... fanout_to_subgraph_100x_checkpoint_sync: Mean +- std dev: 789 ms +- 6 ms ......................................... react_agent_10x: Mean +- std dev: 41.7 ms +- 3.3 ms ......................................... react_agent_10x_sync: Mean +- std dev: 29.8 ms +- 0.2 ms ......................................... react_agent_10x_checkpoint: Mean +- std dev: 52.8 ms +- 1.5 ms ......................................... react_agent_10x_checkpoint_sync: Mean +- std dev: 42.6 ms +- 3.2 ms ......................................... react_agent_100x: Mean +- std dev: 416 ms +- 9 ms ......................................... react_agent_100x_sync: Mean +- std dev: 331 ms +- 3 ms ......................................... react_agent_100x_checkpoint: Mean +- std dev: 921 ms +- 12 ms ......................................... react_agent_100x_checkpoint_sync: Mean +- std dev: 819 ms +- 9 ms ......................................... wide_state_25x300: Mean +- std dev: 20.5 ms +- 0.3 ms ......................................... wide_state_25x300_sync: Mean +- std dev: 12.8 ms +- 0.2 ms ......................................... wide_state_25x300_checkpoint: Mean +- std dev: 239 ms +- 8 ms ......................................... wide_state_25x300_checkpoint_sync: Mean +- std dev: 236 ms +- 14 ms ......................................... wide_state_15x600: Mean +- std dev: 23.7 ms +- 0.3 ms ......................................... wide_state_15x600_sync: Mean +- std dev: 14.8 ms +- 0.1 ms ......................................... wide_state_15x600_checkpoint: Mean +- std dev: 415 ms +- 13 ms ......................................... wide_state_15x600_checkpoint_sync: Mean +- std dev: 417 ms +- 18 ms ......................................... wide_state_9x1200: Mean +- std dev: 23.7 ms +- 0.3 ms ......................................... wide_state_9x1200_sync: Mean +- std dev: 14.8 ms +- 0.2 ms ......................................... wide_state_9x1200_checkpoint: Mean +- std dev: 267 ms +- 8 ms ......................................... wide_state_9x1200_checkpoint_sync: Mean +- std dev: 265 ms +- 15 ms

Check notice on line 1 in libs/checkpoint/langgraph/checkpoint/serde/jsonplus.py

View workflow job for this annotation

GitHub Actions / benchmark

Comparison against main

+------------------------------------+---------+-----------------------+ | Benchmark | main | changes | +====================================+=========+=======================+ | fanout_to_subgraph_100x_sync | 502 ms | 504 ms: 1.00x slower | +------------------------------------+---------+-----------------------+ | wide_state_25x300 | 20.4 ms | 20.5 ms: 1.00x slower | +------------------------------------+---------+-----------------------+ | fanout_to_subgraph_10x_checkpoint | 76.5 ms | 76.8 ms: 1.00x slower | +------------------------------------+---------+-----------------------+ | react_agent_100x_checkpoint_sync | 814 ms | 819 ms: 1.01x slower | +------------------------------------+---------+-----------------------+ | react_agent_100x | 412 ms | 416 ms: 1.01x slower | +------------------------------------+---------+-----------------------+ | react_agent_100x_checkpoint | 911 ms | 921 ms: 1.01x slower | +------------------------------------+---------+-----------------------+ | fanout_to_subgraph_100x | 544 ms | 558 ms: 1.02x slower | +------------------------------------+---------+-----------------------+ | fanout_to_subgraph_100x_checkpoint | 752 ms | 774 ms: 1.03x slower | +------------------------------------+---------+-----------------------+ | Geometric mean | (ref) | 1.00x slower | +------------------------------------+---------+-----------------------+ Benchmark hidden because not significant (20): wide_state_25x300_checkpoint_sync, react_agent_10x_checkpoint_sync, react_agent_10x_sync, wide_state_15x600_sync, wide_state_15x600_checkpoint, fanout_to_subgraph_10x_checkpoint_sync, react_agent_10x_checkpoint, react_agent_100x_sync, fanout_to_subgraph_100x_checkpoint_sync, wide_state_9x1200_checkpoint, wide_state_15x600, wide_state_9x1200_sync, wide_state_9x1200_checkpoint_sync, wide_state_25x300_sync, wide_state_9x1200, wide_state_25x300_checkpoint, fanout_to_subgraph_10x, react_agent_10x, wide_state_15x600_checkpoint_sync, fanout_to_subgraph_10x_sync
import decimal
import importlib
import json
Expand Down Expand Up @@ -233,6 +233,17 @@
),
),
)
elif hasattr(obj, "get_secret_value") and callable(obj.get_secret_value):
return msgpack.ExtType(
EXT_CONSTRUCTOR_SINGLE_ARG,
_msgpack_enc(
(
obj.__class__.__module__,
obj.__class__.__name__,
obj.get_secret_value(),
),
),
)
elif hasattr(obj, "dict") and callable(obj.dict): # pydantic v1
return msgpack.ExtType(
EXT_PYDANTIC_V1,
Expand Down
5 changes: 4 additions & 1 deletion libs/checkpoint/tests/test_jsonplus.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
from ipaddress import IPv4Address

import dataclasses_json
from pydantic import BaseModel
from pydantic import BaseModel, SecretStr
from pydantic.v1 import BaseModel as BaseModelV1
from pydantic.v1 import SecretStr as SecretStrV1
from zoneinfo import ZoneInfo

from langgraph.checkpoint.serde.jsonplus import JsonPlusSerializer
Expand Down Expand Up @@ -109,6 +110,8 @@ def test_serde_jsonplus() -> None:
"my_pydantic_v1": MyPydanticV1(
foo="foo", bar=1, inner=InnerPydanticV1(hello="hello")
),
"my_secret_str": SecretStr("meow"),
"my_secret_str_v1": SecretStrV1("meow"),
"person": Person(name="foo"),
"a_bool": True,
"a_none": None,
Expand Down
Loading