- Spec files
pypi-langgraph-sdk
Describes: pkg:pypi/langgraph-sdk@0.2.x
- Description
- Python SDK for interacting with the LangGraph Platform REST API to build and manage AI assistants and conversational workflows
- Author
- tessl
- Last updated
assistant-management.md docs/
1# Assistant Management23Create, configure, and manage AI assistants based on registered graphs. Assistants serve as the execution engines for conversational workflows, with support for versioning, configuration, and metadata management.45## Capabilities67### Assistant CRUD Operations89Core operations for creating, reading, updating, and deleting assistants with comprehensive configuration and metadata support.1011```python { .api }12from collections.abc import Mapping13from langgraph_sdk.schema import (14Assistant, AssistantSelectField, Config, Context, Json,15OnConflictBehavior, QueryParamTypes16)1718# Via client.assistants19async def get(20assistant_id: str,21*,22headers: Mapping[str, str] | None = None,23params: QueryParamTypes | None = None,24) -> Assistant:25"""26Get an assistant by ID.2728Args:29assistant_id: The ID of the assistant to get.30headers: Optional custom headers to include with the request.31params: Optional query parameters to include with the request.3233Returns:34Assistant: Assistant Object.35"""3637async def create(38graph_id: str | None,39config: Config | None = None,40*,41context: Context | None = None,42metadata: Json = None,43assistant_id: str | None = None,44if_exists: OnConflictBehavior | None = None,45name: str | None = None,46headers: Mapping[str, str] | None = None,47params: QueryParamTypes | None = None,48) -> Assistant:49"""50Create a new assistant.5152Args:53graph_id: The ID of the graph to create an assistant for.54config: Configuration to merge with the assistant.55context: Context to apply when running the assistant.56metadata: Metadata to merge with the assistant.57assistant_id: ID of the assistant. If None, ID will be a UUID.58if_exists: How to handle duplicate creates. Defaults to "create".59name: The name of the assistant. Defaults to Untitled.60headers: Optional custom headers to include with the request.61params: Optional query parameters to include with the request.6263Returns:64Assistant: The created assistant.65"""6667async def update(68assistant_id: str,69*,70graph_id: str | None = None,71config: Config | None = None,72context: Context | None = None,73metadata: Json = None,74name: str | None = None,75headers: Mapping[str, str] | None = None,76description: str | None = None,77params: QueryParamTypes | None = None,78) -> Assistant:79"""80Update an assistant.8182Args:83assistant_id: The ID of the assistant to update.84graph_id: The ID of the graph to assign to the assistant.85config: Configuration to merge with the assistant.86context: Context to apply when running the assistant.87metadata: Metadata to merge with the assistant.88name: The name of the assistant.89headers: Optional custom headers to include with the request.90description: The description of the assistant.91params: Optional query parameters to include with the request.9293Returns:94Assistant: The updated assistant.95"""9697async def delete(98assistant_id: str,99*,100headers: Mapping[str, str] | None = None,101params: QueryParamTypes | None = None,102) -> None:103"""104Delete an assistant.105106Args:107assistant_id: The assistant ID to delete.108headers: Optional custom headers to include with the request.109params: Optional query parameters to include with the request.110"""111```112113### Assistant Discovery & Search114115Search and enumerate assistants with filtering, pagination, and sorting capabilities.116117```python { .api }118from langgraph_sdk.schema import (119Assistant, AssistantSelectField, AssistantSortBy, SortOrder, Json, QueryParamTypes120)121122async def search(123*,124metadata: Json = None,125graph_id: str | None = None,126limit: int = 10,127offset: int = 0,128sort_by: AssistantSortBy | None = None,129sort_order: SortOrder | None = None,130select: list[AssistantSelectField] | None = None,131headers: Mapping[str, str] | None = None,132params: QueryParamTypes | None = None,133) -> list[Assistant]:134"""135List assistants from the store.136137Args:138metadata: Metadata to filter by. Exact match filter for each KV pair.139graph_id: ID of a graph to filter by.140limit: Limit the number of assistants to return.141offset: Offset to start from.142sort_by: Field to sort by. Options are "created_at" and "updated_at".143sort_order: Order to sort by. Options are "asc" and "desc".144select: Fields to include in the response.145headers: Optional custom headers to include with the request.146params: Optional query parameters to include with the request.147148Returns:149list[Assistant]: List of assistants.150"""151152async def count(153*,154metadata: Json = None,155graph_id: str | None = None,156headers: Mapping[str, str] | None = None,157params: QueryParamTypes | None = None,158) -> int:159"""160Count assistants.161162Args:163metadata: Metadata to filter by. Exact match filter for each KV pair.164graph_id: ID of a graph to filter by.165headers: Optional custom headers to include with the request.166params: Optional query parameters to include with the request.167168Returns:169int: Number of assistants that match the query.170"""171```172173### Graph Schema & Structure174175Retrieve graph definitions, schemas, and subgraph structures associated with assistants.176177```python { .api }178from typing import Any179from langgraph_sdk.schema import Subgraphs, QueryParamTypes180181async def get_graph(182assistant_id: str,183*,184xray: int | bool = False,185headers: Mapping[str, str] | None = None,186params: QueryParamTypes | None = None,187) -> dict[str, list[dict[str, Any]]]:188"""189Get the graph of an assistant by ID.190191Args:192assistant_id: The ID of the assistant to get the graph of.193xray: Include graph representation of subgraphs. If an integer value is provided,194only subgraphs with a depth less than or equal to the value will be included.195headers: Optional custom headers to include with the request.196params: Optional query parameters to include with the request.197198Returns:199Graph: The graph information for the assistant in JSON format.200"""201202async def get_schemas(203assistant_id: str,204*,205headers: Mapping[str, str] | None = None,206params: QueryParamTypes | None = None,207) -> dict[str, Any]:208"""209Get the schemas of an assistant by ID.210211Args:212assistant_id: The ID of the assistant to get the schema of.213headers: Optional custom headers to include with the request.214params: Optional query parameters to include with the request.215216Returns:217Graph: The graph schema for the assistant in JSON format.218"""219220async def get_subgraphs(221assistant_id: str,222namespace: str | None = None,223recurse: bool = False,224*,225headers: Mapping[str, str] | None = None,226params: QueryParamTypes | None = None,227) -> Subgraphs:228"""229Get the subgraphs of an assistant by ID.230231Args:232assistant_id: The ID of the assistant to get the subgraphs of.233namespace: Optional namespace to filter by.234recurse: Whether to recursively get subgraphs.235headers: Optional custom headers to include with the request.236params: Optional query parameters to include with the request.237238Returns:239Subgraphs: A mapping of subgraph names to their definitions.240"""241```242243### Version Management244245Manage assistant versions and control which version is active for execution.246247```python { .api }248from langgraph_sdk.schema import AssistantVersion, Json, QueryParamTypes249250async def get_versions(251assistant_id: str,252metadata: Json = None,253limit: int = 10,254offset: int = 0,255*,256headers: Mapping[str, str] | None = None,257params: QueryParamTypes | None = None,258) -> list[AssistantVersion]:259"""260List all versions of an assistant.261262Args:263assistant_id: The assistant ID to get versions for.264metadata: Metadata to filter versions by. Exact match filter for each KV pair.265limit: The maximum number of versions to return.266offset: The number of versions to skip.267headers: Optional custom headers to include with the request.268params: Optional query parameters to include with the request.269270Returns:271list[AssistantVersion]: A list of assistant versions.272"""273274async def set_latest(275assistant_id: str,276version: int,277*,278headers: Mapping[str, str] | None = None,279params: QueryParamTypes | None = None,280) -> AssistantVersion:281"""282Set the latest version of an assistant.283284Args:285assistant_id: The assistant ID to set the version for.286version: The version to set as the latest.287headers: Optional custom headers to include with the request.288params: Optional query parameters to include with the request.289290Returns:291AssistantVersion: The updated assistant version.292"""293```294295## Types296297```python { .api }298class Assistant(TypedDict):299"""Assistant definition and configuration."""300assistant_id: str301graph_id: str302config: Config303created_at: str304updated_at: str305metadata: dict306version: int307308class AssistantVersion(TypedDict):309"""Versioned assistant information."""310assistant_id: str311version: int312config: Config313created_at: str314metadata: dict315316class GraphSchema(TypedDict):317"""Graph structure definition."""318graph_id: str319input_schema: dict320output_schema: dict321state_schema: dict322config_schema: dict323324AssistantSelectField = Literal[325"assistant_id", "graph_id", "config", "created_at",326"updated_at", "metadata", "version"327]328329AssistantSortBy = Literal["created_at", "updated_at", "assistant_id"]330331IfNotExists = Literal["create", "reject"]332333Subgraphs = dict[str, GraphSchema]334```335336## Usage Examples337338### Creating and Managing Assistants339340```python341# Create an assistant from a registered graph342assistant = await client.assistants.create(343graph_id="my-chatbot-graph",344config={"max_turns": 10, "temperature": 0.7},345metadata={"environment": "production", "owner": "team-ai"}346)347348# Get assistant details349assistant = await client.assistants.get("assistant-123")350351# Update assistant configuration352updated = await client.assistants.update(353"assistant-123",354config={"max_turns": 20},355metadata={"last_updated_by": "admin"}356)357```358359### Searching and Discovery360361```python362# Search assistants by metadata363production_assistants = await client.assistants.search(364metadata={"environment": "production"},365limit=50366)367368# Get assistants for a specific graph369graph_assistants = await client.assistants.search(370graph_id="my-graph",371sort_by="updated_at",372order_by="desc"373)374375# Count total assistants376total = await client.assistants.count()377```378379### Graph Inspection380381```python382# Get graph structure383graph = await client.assistants.get_graph("assistant-123")384print(f"Graph has {len(graph['nodes'])} nodes")385386# Get input/output schemas387schemas = await client.assistants.get_schemas("assistant-123")388input_schema = schemas["input_schema"]389390# Get subgraphs391subgraphs = await client.assistants.get_subgraphs("assistant-123")392```393394### Version Control395396```python397# Get all versions of an assistant398versions = await client.assistants.get_versions("assistant-123")399400# Set specific version as active401await client.assistants.set_latest("assistant-123", version=5)402```