Skip to content

Commit

Permalink
Add data model section
Browse files Browse the repository at this point in the history
  • Loading branch information
hinthornw committed Oct 2, 2024
1 parent c3af74f commit 462df99
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 9 deletions.
6 changes: 5 additions & 1 deletion docs/docs/cloud/reference/sdk/python_sdk_ref.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# Python SDK Reference

Check notice on line 1 in docs/docs/cloud/reference/sdk/python_sdk_ref.md

View workflow job for this annotation

GitHub Actions / benchmark

Benchmark results

......................................... fanout_to_subgraph_10x: Mean +- std dev: 51.1 ms +- 0.9 ms ......................................... fanout_to_subgraph_10x_sync: Mean +- std dev: 44.4 ms +- 0.7 ms ......................................... fanout_to_subgraph_10x_checkpoint: Mean +- std dev: 69.8 ms +- 1.4 ms ......................................... fanout_to_subgraph_10x_checkpoint_sync: Mean +- std dev: 73.3 ms +- 0.9 ms ......................................... fanout_to_subgraph_100x: Mean +- std dev: 487 ms +- 16 ms ......................................... fanout_to_subgraph_100x_sync: Mean +- std dev: 427 ms +- 5 ms ......................................... fanout_to_subgraph_100x_checkpoint: Mean +- std dev: 700 ms +- 28 ms ......................................... fanout_to_subgraph_100x_checkpoint_sync: Mean +- std dev: 711 ms +- 8 ms ......................................... react_agent_10x: Mean +- std dev: 37.1 ms +- 0.8 ms ......................................... react_agent_10x_sync: Mean +- std dev: 27.9 ms +- 0.2 ms ......................................... react_agent_10x_checkpoint: Mean +- std dev: 50.8 ms +- 1.5 ms ......................................... react_agent_10x_checkpoint_sync: Mean +- std dev: 41.1 ms +- 3.5 ms ......................................... react_agent_100x: Mean +- std dev: 394 ms +- 8 ms ......................................... react_agent_100x_sync: Mean +- std dev: 314 ms +- 3 ms ......................................... react_agent_100x_checkpoint: Mean +- std dev: 909 ms +- 15 ms ......................................... react_agent_100x_checkpoint_sync: Mean +- std dev: 813 ms +- 15 ms ......................................... wide_state_25x300: Mean +- std dev: 18.8 ms +- 0.4 ms ......................................... wide_state_25x300_sync: Mean +- std dev: 11.1 ms +- 0.1 ms ......................................... wide_state_25x300_checkpoint: Mean +- std dev: 236 ms +- 6 ms ......................................... wide_state_25x300_checkpoint_sync: Mean +- std dev: 238 ms +- 14 ms ......................................... wide_state_15x600: Mean +- std dev: 21.8 ms +- 0.4 ms ......................................... wide_state_15x600_sync: Mean +- std dev: 12.9 ms +- 0.2 ms ......................................... wide_state_15x600_checkpoint: Mean +- std dev: 416 ms +- 13 ms ......................................... wide_state_15x600_checkpoint_sync: Mean +- std dev: 418 ms +- 16 ms ......................................... wide_state_9x1200: Mean +- std dev: 21.7 ms +- 0.4 ms ......................................... wide_state_9x1200_sync: Mean +- std dev: 12.8 ms +- 0.2 ms ......................................... wide_state_9x1200_checkpoint: Mean +- std dev: 266 ms +- 8 ms ......................................... wide_state_9x1200_checkpoint_sync: Mean +- std dev: 266 ms +- 15 ms

Check notice on line 1 in docs/docs/cloud/reference/sdk/python_sdk_ref.md

View workflow job for this annotation

GitHub Actions / benchmark

Comparison against main

+----------------------------------------+---------+-----------------------+ | Benchmark | main | changes | +========================================+=========+=======================+ | react_agent_100x_checkpoint_sync | 841 ms | 813 ms: 1.03x faster | +----------------------------------------+---------+-----------------------+ | fanout_to_subgraph_100x | 501 ms | 487 ms: 1.03x faster | +----------------------------------------+---------+-----------------------+ | react_agent_100x_checkpoint | 931 ms | 909 ms: 1.02x faster | +----------------------------------------+---------+-----------------------+ | fanout_to_subgraph_100x_checkpoint | 716 ms | 700 ms: 1.02x faster | +----------------------------------------+---------+-----------------------+ | wide_state_9x1200_checkpoint | 271 ms | 266 ms: 1.02x faster | +----------------------------------------+---------+-----------------------+ | wide_state_15x600_checkpoint | 425 ms | 416 ms: 1.02x faster | +----------------------------------------+---------+-----------------------+ | wide_state_25x300_checkpoint | 240 ms | 236 ms: 1.02x faster | +----------------------------------------+---------+-----------------------+ | wide_state_9x1200_sync | 13.0 ms | 12.8 ms: 1.02x faster | +----------------------------------------+---------+-----------------------+ | react_agent_10x_sync | 28.2 ms | 27.9 ms: 1.01x faster | +----------------------------------------+---------+-----------------------+ | wide_state_15x600_sync | 13.0 ms | 12.9 ms: 1.01x faster | +----------------------------------------+---------+-----------------------+ | react_agent_100x_sync | 317 ms | 314 ms: 1.01x faster | +----------------------------------------+---------+-----------------------+ | fanout_to_subgraph_10x_checkpoint_sync | 74.0 ms | 73.3 ms: 1.01x faster | +----------------------------------------+---------+-----------------------+ | wide_state_25x300_sync | 11.2 ms | 11.1 ms: 1.01x faster | +----------------------------------------+---------+-----------------------+ | react_agent_100x | 397 ms | 394 ms: 1.01x faster | +----------------------------------------+---------+-----------------------+ | wide_state_9x1200 | 21.8 ms | 21.7 ms: 1.01x faster | +----------------------------------------+---------+-----------------------+ | fanout_to_subgraph_10x_checkpoint | 69.4 ms | 69.8 ms: 1.01x slower | +----------------------------------------+---------+-----------------------+ | fanout_to_subgraph_10x | 49.4 ms | 51.1 ms: 1.04x slower | +----------------------------------------+---------+-----------------------+ | Geometric mean | (ref) | 1.01x faster | +----------------------------------------+---------+-----------------------+ Benchmark hidden because not significant (11): wide_state_9x1200_checkpoint_sync, wide_state_25x300_checkpoint_sync, wide_state_15x600_checkpoint_sync, wide_state_25x300, react_agent_10x, react_agent_10x_checkpoint, fanout_to_subgraph_10x_sync, wide_state_15x600, fanout_to_subgraph_100x_sync, fanout_to_subgraph_100x_checkpoint_sync, react_agent_10x_checkpoint_sync

::: langgraph_sdk.client
handler: python
handler: python


::: langgraph_sdk.schema
handler: python
106 changes: 98 additions & 8 deletions libs/sdk-py/langgraph_sdk/schema.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,77 @@
"""Data models for interacting with the LangGraph API."""

from datetime import datetime
from typing import Any, Literal, NamedTuple, Optional, Sequence, TypedDict, Union

Json = Optional[dict[str, Any]]
"""Represents a JSON-like structure, which can be None or a dictionary with string keys and any values."""

RunStatus = Literal["pending", "running", "error", "success", "timeout", "interrupted"]
"""
Represents the status of a run:
- "pending": The run is waiting to start.
- "running": The run is currently in progress.
- "error": The run encountered an error and stopped.
- "success": The run completed successfully.
- "timeout": The run exceeded its time limit.
- "interrupted": The run was manually stopped or interrupted.
"""

ThreadStatus = Literal["idle", "busy", "interrupted"]
"""
Represents the status of a thread:
- "idle": The thread is not currently processing any task.
- "busy": The thread is actively processing a task.
- "interrupted": The thread's execution was interrupted.
"""

StreamMode = Literal["values", "messages", "updates", "events", "debug"]
"""
Defines the mode of streaming:
- "values": Stream only the values.
- "messages": Stream complete messages.
- "updates": Stream updates to the state.
- "events": Stream events occurring during execution.
- "debug": Stream detailed debug information.
"""

DisconnectMode = Literal["cancel", "continue"]
"""
Specifies behavior on disconnection:
- "cancel": Cancel the operation on disconnection.
- "continue": Continue the operation even if disconnected.
"""

MultitaskStrategy = Literal["reject", "interrupt", "rollback", "enqueue"]
"""
Defines how to handle multiple tasks:
- "reject": Reject new tasks when busy.
- "interrupt": Interrupt current task for new ones.
- "rollback": Roll back current task and start new one.
- "enqueue": Queue new tasks for later execution.
"""

OnConflictBehavior = Literal["raise", "do_nothing"]
"""
Specifies behavior on conflict:
- "raise": Raise an exception when a conflict occurs.
- "do_nothing": Ignore conflicts and proceed.
"""

OnCompletionBehavior = Literal["delete", "keep"]
"""
Defines action after completion:
- "delete": Delete resources after completion.
- "keep": Retain resources after completion.
"""

All = Literal["*"]
"""Represents a wildcard or 'all' selector."""


class Config(TypedDict, total=False):
"""Configuration options for a call."""

tags: list[str]
"""
Tags for this call and any sub-calls (eg. a Chain calling an LLM).
Expand All @@ -42,16 +93,20 @@ class Config(TypedDict, total=False):


class Checkpoint(TypedDict):
"""Checkpoint model."""
"""Represents a checkpoint in the execution process."""

thread_id: str
"""Unique identifier for the thread associated with this checkpoint."""
checkpoint_ns: str
"""Namespace for the checkpoint, used for organization and retrieval."""
checkpoint_id: Optional[str]
"""Optional unique identifier for the checkpoint itself."""
checkpoint_map: Optional[dict[str, Any]]
"""Optional dictionary containing checkpoint-specific data."""


class GraphSchema(TypedDict):
"""Graph model."""
"""Defines the structure and properties of a graph."""

graph_id: str
"""The ID of the graph."""
Expand All @@ -73,7 +128,7 @@ class GraphSchema(TypedDict):


class AssistantBase(TypedDict):
"""Assistant base model."""
"""Base model for an assistant."""

assistant_id: str
"""The ID of the assistant."""
Expand All @@ -90,13 +145,13 @@ class AssistantBase(TypedDict):


class AssistantVersion(AssistantBase):
"""Assistant version model."""
"""Represents a specific version of an assistant."""

pass


class Assistant(AssistantBase):
"""Assistant model."""
"""Represents an assistant with additional properties."""

updated_at: datetime
"""The last time the assistant was updated."""
Expand All @@ -105,6 +160,8 @@ class Assistant(AssistantBase):


class Thread(TypedDict):
"""Represents a conversation thread."""

thread_id: str
"""The ID of the thread."""
created_at: datetime
Expand All @@ -120,6 +177,8 @@ class Thread(TypedDict):


class ThreadTask(TypedDict):
"""Represents a task within a thread."""

id: str
name: str
error: Optional[str]
Expand All @@ -129,6 +188,8 @@ class ThreadTask(TypedDict):


class ThreadState(TypedDict):
"""Represents the state of a thread."""

values: Union[list[dict], dict[str, Any]]
"""The state values."""
next: Sequence[str]
Expand All @@ -147,6 +208,8 @@ class ThreadState(TypedDict):


class Run(TypedDict):
"""Represents a single execution run."""

run_id: str
"""The ID of the run."""
thread_id: str
Expand All @@ -166,6 +229,8 @@ class Run(TypedDict):


class Cron(TypedDict):
"""Represents a scheduled task."""

cron_id: str
"""The ID of the cron."""
thread_id: Optional[str]
Expand All @@ -183,27 +248,42 @@ class Cron(TypedDict):


class RunCreate(TypedDict):
"""Payload for creating a background run."""
"""Defines the parameters for initiating a background run."""

thread_id: Optional[str]
"""The identifier of the thread to run. If not provided, the run is stateless."""
assistant_id: str
"""The identifier of the assistant to use for this run."""
input: Optional[dict]
"""Initial input data for the run."""
metadata: Optional[dict]
"""Additional metadata to associate with the run."""
config: Optional[Config]
"""Configuration options for the run."""
checkpoint_id: Optional[str]
"""The identifier of a checkpoint to resume from."""
interrupt_before: Optional[list[str]]
"""List of node names to interrupt execution before."""
interrupt_after: Optional[list[str]]
"""List of node names to interrupt execution after."""
webhook: Optional[str]
"""URL to send webhook notifications about the run's progress."""
multitask_strategy: Optional[MultitaskStrategy]
"""Strategy for handling concurrent runs on the same thread."""


class Item(TypedDict):
"""Represents a single document or data entry in the graph's Store.
Items are used to store cross-thread memories.
"""

namespace: list[str]
"""The namespace of the item."""
"""The namespace of the item. A namespace is analogous to a document's directory."""
key: str
"""The unique identifier of the item within its namespace.
In general, keys are not globally unique.
In general, keys needn't be globally unique.
"""
value: dict[str, Any]
"""The value stored in the item. This is the document itself."""
Expand All @@ -214,13 +294,23 @@ class Item(TypedDict):


class ListNamespaceResponse(TypedDict):
"""Response structure for listing namespaces."""

namespaces: list[list[str]]
"""A list of namespace paths, where each path is a list of strings."""


class SearchItemsResponse(TypedDict):
"""Response structure for searching items."""

items: list[Item]
"""A list of items matching the search criteria."""


class StreamPart(NamedTuple):
"""Represents a part of a stream response."""

event: str
"""The type of event for this stream part."""
data: dict
"""The data payload associated with the event."""

0 comments on commit 462df99

Please sign in to comment.