JS/TS SDK
@langchain/langgraph-sdk¶
Classes¶
Interfaces¶
Functions¶
@langchain/langgraph-sdk
@langchain/langgraph-sdk/auth¶
Classes¶
Interfaces¶
Type Aliases¶
@langchain/langgraph-sdk / Auth
Class: Auth\<TExtra, TAuthReturn, TUser>¶
Defined in: src/auth/index.ts:11
Type Parameters¶
• TExtra = {}
• TAuthReturn extends BaseAuthReturn = BaseAuthReturn
• TUser extends BaseUser = ToUserLike\<TAuthReturn>
Constructors¶
new Auth()¶
new Auth\<
TExtra,TAuthReturn,TUser>():Auth\<TExtra,TAuthReturn,TUser>
Returns¶
Auth\<TExtra, TAuthReturn, TUser>
Methods¶
authenticate()¶
authenticate\<
T>(cb):Auth\<TExtra,T>
Defined in: src/auth/index.ts:25
Type Parameters¶
• T extends BaseAuthReturn
Parameters¶
cb¶
AuthenticateCallback\<T>
Returns¶
Auth\<TExtra, T>
on()¶
on\<
T>(event,callback):this
Defined in: src/auth/index.ts:32
Type Parameters¶
• T extends CallbackEvent
Parameters¶
event¶
T
callback¶
OnCallback\<T, TUser>
Returns¶
this
@langchain/langgraph-sdk / HTTPException
Class: HTTPException¶
Defined in: src/auth/error.ts:66
Extends¶
Error
Constructors¶
new HTTPException()¶
new HTTPException(
status,options?):HTTPException
Defined in: src/auth/error.ts:70
Parameters¶
status¶
number
options?¶
# cause?¶
unknown
# headers?¶
HeadersInit
# message?¶
string
Returns¶
Overrides¶
Error.constructor
Properties¶
cause?¶
optionalcause:unknown
Defined in: node_modules/typescript/lib/lib.es2022.error.d.ts:24
Inherited from¶
Error.cause
headers¶
headers:
HeadersInit
Defined in: src/auth/error.ts:68
message¶
message:
string
Defined in: node_modules/typescript/lib/lib.es5.d.ts:1077
Inherited from¶
Error.message
name¶
name:
string
Defined in: node_modules/typescript/lib/lib.es5.d.ts:1076
Inherited from¶
Error.name
stack?¶
optionalstack:string
Defined in: node_modules/typescript/lib/lib.es5.d.ts:1078
Inherited from¶
Error.stack
status¶
status:
number
Defined in: src/auth/error.ts:67
prepareStackTrace()?¶
staticoptionalprepareStackTrace: (err,stackTraces) =>any
Defined in: node_modules/@types/node/globals.d.ts:28
Optional override for formatting stack traces
Parameters¶
err¶
Error
stackTraces¶
CallSite[]
Returns¶
any
See¶
https://v8.dev/docs/stack-trace-api#customizing-stack-traces
Inherited from¶
Error.prepareStackTrace
stackTraceLimit¶
staticstackTraceLimit:number
Defined in: node_modules/@types/node/globals.d.ts:30
Inherited from¶
Error.stackTraceLimit
Methods¶
captureStackTrace()¶
staticcaptureStackTrace(targetObject,constructorOpt?):void
Defined in: node_modules/@types/node/globals.d.ts:21
Create .stack property on a target object
Parameters¶
targetObject¶
object
constructorOpt?¶
Function
Returns¶
void
Inherited from¶
Error.captureStackTrace
@langchain/langgraph-sdk / AuthEventValueMap
Interface: AuthEventValueMap¶
Defined in: src/auth/types.ts:218
Properties¶
assistants:create¶
assistants:create:
object
Defined in: src/auth/types.ts:226
assistant_id?¶
optionalassistant_id:Maybe\<string>
config?¶
optionalconfig:Maybe\<AssistantConfig>
graph_id¶
graph_id:
string
if_exists?¶
optionalif_exists:Maybe\<"raise"|"do_nothing">
metadata?¶
optionalmetadata:Maybe\<Record\<string,unknown>>
name?¶
optionalname:Maybe\<string>
assistants:delete¶
assistants:delete:
object
Defined in: src/auth/types.ts:229
assistant_id¶
assistant_id:
string
assistants:read¶
assistants:read:
object
Defined in: src/auth/types.ts:227
assistant_id¶
assistant_id:
string
metadata?¶
optionalmetadata:Maybe\<Record\<string,unknown>>
assistants:search¶
assistants:search:
object
Defined in: src/auth/types.ts:230
graph_id?¶
optionalgraph_id:Maybe\<string>
limit?¶
optionallimit:Maybe\<number>
metadata?¶
optionalmetadata:Maybe\<Record\<string,unknown>>
offset?¶
optionaloffset:Maybe\<number>
assistants:update¶
assistants:update:
object
Defined in: src/auth/types.ts:228
assistant_id¶
assistant_id:
string
config?¶
optionalconfig:Maybe\<AssistantConfig>
graph_id?¶
optionalgraph_id:Maybe\<string>
metadata?¶
optionalmetadata:Maybe\<Record\<string,unknown>>
name?¶
optionalname:Maybe\<string>
version?¶
optionalversion:Maybe\<number>
crons:create¶
crons:create:
object
Defined in: src/auth/types.ts:232
cron_id?¶
optionalcron_id:Maybe\<string>
end_time?¶
optionalend_time:Maybe\<string>
payload?¶
optionalpayload:Maybe\<Record\<string,unknown>>
schedule¶
schedule:
string
thread_id?¶
optionalthread_id:Maybe\<string>
user_id?¶
optionaluser_id:Maybe\<string>
crons:delete¶
crons:delete:
object
Defined in: src/auth/types.ts:235
cron_id¶
cron_id:
string
crons:read¶
crons:read:
object
Defined in: src/auth/types.ts:233
cron_id¶
cron_id:
string
crons:search¶
crons:search:
object
Defined in: src/auth/types.ts:236
assistant_id?¶
optionalassistant_id:Maybe\<string>
limit?¶
optionallimit:Maybe\<number>
offset?¶
optionaloffset:Maybe\<number>
thread_id?¶
optionalthread_id:Maybe\<string>
crons:update¶
crons:update:
object
Defined in: src/auth/types.ts:234
cron_id¶
cron_id:
string
payload?¶
optionalpayload:Maybe\<Record\<string,unknown>>
schedule?¶
optionalschedule:Maybe\<string>
store:delete¶
store:delete:
object
Defined in: src/auth/types.ts:242
key¶
key:
string
namespace?¶
optionalnamespace:Maybe\<string[]>
store:get¶
store:get:
object
Defined in: src/auth/types.ts:239
key¶
key:
string
namespace¶
namespace:
Maybe\<string[]>
store:list_namespaces¶
store:list_namespaces:
object
Defined in: src/auth/types.ts:241
limit?¶
optionallimit:Maybe\<number>
max_depth?¶
optionalmax_depth:Maybe\<number>
namespace?¶
optionalnamespace:Maybe\<string[]>
offset?¶
optionaloffset:Maybe\<number>
suffix?¶
optionalsuffix:Maybe\<string[]>
store:put¶
store:put:
object
Defined in: src/auth/types.ts:238
key¶
key:
string
namespace¶
namespace:
string[]
value¶
value:
Record\<string,unknown>
store:search¶
store:search:
object
Defined in: src/auth/types.ts:240
filter?¶
optionalfilter:Maybe\<Record\<string,unknown>>
limit?¶
optionallimit:Maybe\<number>
namespace?¶
optionalnamespace:Maybe\<string[]>
offset?¶
optionaloffset:Maybe\<number>
query?¶
optionalquery:Maybe\<string>
threads:create¶
threads:create:
object
Defined in: src/auth/types.ts:219
if_exists?¶
optionalif_exists:Maybe\<"raise"|"do_nothing">
metadata?¶
optionalmetadata:Maybe\<Record\<string,unknown>>
thread_id?¶
optionalthread_id:Maybe\<string>
threads:create_run¶
threads:create_run:
object
Defined in: src/auth/types.ts:224
after_seconds?¶
optionalafter_seconds:Maybe\<number>
assistant_id¶
assistant_id:
string
if_not_exists?¶
optionalif_not_exists:Maybe\<"reject"|"create">
kwargs¶
kwargs:
Record\<string,unknown>
metadata?¶
optionalmetadata:Maybe\<Record\<string,unknown>>
multitask_strategy?¶
optionalmultitask_strategy:Maybe\<"reject"|"interrupt"|"rollback"|"enqueue">
prevent_insert_if_inflight?¶
optionalprevent_insert_if_inflight:Maybe\<boolean>
run_id¶
run_id:
string
status¶
status:
Maybe\<"pending"|"running"|"error"|"success"|"timeout"|"interrupted">
thread_id?¶
optionalthread_id:Maybe\<string>
threads:delete¶
threads:delete:
object
Defined in: src/auth/types.ts:222
run_id?¶
optionalrun_id:Maybe\<string>
thread_id?¶
optionalthread_id:Maybe\<string>
threads:read¶
threads:read:
object
Defined in: src/auth/types.ts:220
thread_id?¶
optionalthread_id:Maybe\<string>
threads:search¶
threads:search:
object
Defined in: src/auth/types.ts:223
limit?¶
optionallimit:Maybe\<number>
metadata?¶
optionalmetadata:Maybe\<Record\<string,unknown>>
offset?¶
optionaloffset:Maybe\<number>
status?¶
optionalstatus:Maybe\<"error"|"interrupted"|"idle"|"busy"|string&object>
thread_id?¶
optionalthread_id:Maybe\<string>
values?¶
optionalvalues:Maybe\<Record\<string,unknown>>
threads:update¶
threads:update:
object
Defined in: src/auth/types.ts:221
action?¶
optionalaction:Maybe\<"interrupt"|"rollback">
metadata?¶
optionalmetadata:Maybe\<Record\<string,unknown>>
thread_id?¶
optionalthread_id:Maybe\<string>
@langchain/langgraph-sdk / AuthFilters
Type Alias: AuthFilters\<TKey>¶
AuthFilters\<
TKey>: { [key in TKey]: string | { [op in "\(contains" \| "\)eq"]?: string } }
Defined in: src/auth/types.ts:367
Type Parameters¶
• TKey extends string | number | symbol
@langchain/langgraph-sdk / AssistantsClient
Class: AssistantsClient¶
Defined in: client.ts:294
Extends¶
BaseClient
Constructors¶
new AssistantsClient()¶
new AssistantsClient(
config?):AssistantsClient
Defined in: client.ts:88
Parameters¶
config?¶
Returns¶
Inherited from¶
BaseClient.constructor
Methods¶
create()¶
create(
payload):Promise\<Assistant>
Defined in: client.ts:359
Create a new assistant.
Parameters¶
payload¶
Payload for creating an assistant.
# assistantId?¶
string
# config?¶
Config
# description?¶
string
# graphId¶
string
# ifExists?¶
OnConflictBehavior
# metadata?¶
Metadata
# name?¶
string
Returns¶
Promise\<Assistant>
The created assistant.
delete()¶
delete(
assistantId):Promise\<void>
Defined in: client.ts:415
Delete an assistant.
Parameters¶
assistantId¶
string
ID of the assistant.
Returns¶
Promise\<void>
get()¶
get(
assistantId):Promise\<Assistant>
Defined in: client.ts:301
Get an assistant by ID.
Parameters¶
assistantId¶
string
The ID of the assistant.
Returns¶
Promise\<Assistant>
Assistant
getGraph()¶
getGraph(
assistantId,options?):Promise\<AssistantGraph>
Defined in: client.ts:311
Get the JSON representation of the graph assigned to a runnable
Parameters¶
assistantId¶
string
The ID of the assistant.
options?¶
# xray?¶
number | boolean
是否在序列化图表示中包含子图。如果提供了整数值,则仅包含深度小于或等于该值的子图。
Returns¶
Promise\<AssistantGraph>
Serialized graph
getSchemas()¶
getSchemas(
assistantId):Promise\<GraphSchema>
Defined in: client.ts:325
Get the state and config schema of the graph assigned to a runnable
Parameters¶
assistantId¶
string
The ID of the assistant.
Returns¶
Promise\<GraphSchema>
Graph schema
getSubgraphs()¶
getSubgraphs(
assistantId,options?):Promise\<Subgraphs>
Defined in: client.ts:336
Get the schemas of an assistant by ID.
Parameters¶
assistantId¶
string
要获取其架构的助手的 ID。
options?¶
获取子图的附加选项,例如命名空间或递归提取。
# namespace?¶
string
# recurse?¶
boolean
Returns¶
Promise\<Subgraphs>
The subgraphs of the assistant.
getVersions()¶
getVersions(
assistantId,payload?):Promise\<AssistantVersion[]>
Defined in: client.ts:453
List all versions of an assistant.
Parameters¶
assistantId¶
string
ID of the assistant.
payload?¶
# limit?¶
number
# metadata?¶
Metadata
# offset?¶
number
Returns¶
Promise\<AssistantVersion[]>
List of assistant versions.
search()¶
search(
query?):Promise\<Assistant[]>
Defined in: client.ts:426
List assistants.
Parameters¶
query?¶
Query options.
# graphId?¶
string
# limit?¶
number
# metadata?¶
Metadata
# offset?¶
number
# sortBy?¶
AssistantSortBy
# sortOrder?¶
SortOrder
Returns¶
Promise\<Assistant[]>
List of assistants.
setLatest()¶
setLatest(
assistantId,version):Promise\<Assistant>
Defined in: client.ts:481
Change the version of an assistant.
Parameters¶
assistantId¶
string
ID of the assistant.
version¶
number
The version to change to.
Returns¶
Promise\<Assistant>
The updated assistant.
update()¶
update(
assistantId,payload):Promise\<Assistant>
Defined in: client.ts:388
Update an assistant.
Parameters¶
assistantId¶
string
ID of the assistant.
payload¶
Payload for updating the assistant.
# config?¶
Config
# description?¶
string
# graphId?¶
string
# metadata?¶
Metadata
# name?¶
string
Returns¶
Promise\<Assistant>
The updated assistant.
@langchain/langgraph-sdk / Client
Class: Client\<TStateType, TUpdateType, TCustomEventType>¶
Defined in: client.ts:1448
Type Parameters¶
• TStateType = DefaultValues
• TUpdateType = TStateType
• TCustomEventType = unknown
Constructors¶
new Client()¶
new Client\<
TStateType,TUpdateType,TCustomEventType>(config?):Client\<TStateType,TUpdateType,TCustomEventType>
Defined in: client.ts:1484
Parameters¶
config?¶
Returns¶
Client\<TStateType, TUpdateType, TCustomEventType>
Properties¶
~ui¶
~ui:
UiClient
Defined in: client.ts:1482
Internal
The client for interacting with the UI. Used by LoadExternalComponent and the API might change in the future.
assistants¶
assistants:
AssistantsClient
Defined in: client.ts:1456
The client for interacting with assistants.
crons¶
crons:
CronsClient
Defined in: client.ts:1471
The client for interacting with cron runs.
runs¶
runs:
RunsClient\<TStateType,TUpdateType,TCustomEventType>
Defined in: client.ts:1466
The client for interacting with runs.
store¶
store:
StoreClient
Defined in: client.ts:1476
The client for interacting with the KV store.
threads¶
threads:
ThreadsClient\<TStateType,TUpdateType>
Defined in: client.ts:1461
The client for interacting with threads.
@langchain/langgraph-sdk / CronsClient
Class: CronsClient¶
Defined in: client.ts:197
Extends¶
BaseClient
Constructors¶
new CronsClient()¶
new CronsClient(
config?):CronsClient
Defined in: client.ts:88
Parameters¶
config?¶
Returns¶
Inherited from¶
BaseClient.constructor
Methods¶
create()¶
create(
assistantId,payload?):Promise\<CronCreateResponse>
Defined in: client.ts:238
Parameters¶
assistantId¶
string
Assistant ID to use for this cron job.
payload?¶
CronsCreatePayload
Payload for creating a cron job.
Returns¶
Promise\<CronCreateResponse>
createForThread()¶
createForThread(
threadId,assistantId,payload?):Promise\<CronCreateForThreadResponse>
Defined in: client.ts:205
Parameters¶
threadId¶
string
The ID of the thread.
assistantId¶
string
Assistant ID to use for this cron job.
payload?¶
CronsCreatePayload
Payload for creating a cron job.
Returns¶
Promise\<CronCreateForThreadResponse>
The created background run.
delete()¶
delete(
cronId):Promise\<void>
Defined in: client.ts:265
Parameters¶
cronId¶
string
Cron ID of Cron job to delete.
Returns¶
Promise\<void>
search()¶
search(
query?):Promise\<Cron[]>
Defined in: client.ts:276
Parameters¶
query?¶
Query options.
# assistantId?¶
string
# limit?¶
number
# offset?¶
number
# threadId?¶
string
Returns¶
Promise\<Cron[]>
List of crons.
@langchain/langgraph-sdk / RunsClient
Class: RunsClient\<TStateType, TUpdateType, TCustomEventType>¶
Defined in: client.ts:776
Extends¶
BaseClient
Type Parameters¶
• TStateType = DefaultValues
• TUpdateType = TStateType
• TCustomEventType = unknown
Constructors¶
new RunsClient()¶
new RunsClient\<
TStateType,TUpdateType,TCustomEventType>(config?):RunsClient\<TStateType,TUpdateType,TCustomEventType>
Defined in: client.ts:88
Parameters¶
config?¶
Returns¶
RunsClient\<TStateType, TUpdateType, TCustomEventType>
Inherited from¶
BaseClient.constructor
Methods¶
cancel()¶
cancel(
threadId,runId,wait,action):Promise\<void>
Defined in: client.ts:1063
Cancel a run.
Parameters¶
threadId¶
string
The ID of the thread.
runId¶
string
The ID of the run.
wait¶
boolean = false
Whether to block when canceling
action¶
CancelAction = "interrupt"
取消运行时要采取的操作。可能的值为 interrupt 或 rollback。默认值为 interrupt。
Returns¶
Promise\<void>
create()¶
create(
threadId,assistantId,payload?):Promise\<Run>
Defined in: client.ts:885
Create a run.
Parameters¶
threadId¶
string
The ID of the thread.
assistantId¶
string
Assistant ID to use for this run.
payload?¶
RunsCreatePayload
Payload for creating a run.
Returns¶
Promise\<Run>
The created run.
createBatch()¶
createBatch(
payloads):Promise\<Run[]>
Defined in: client.ts:921
Create a batch of stateless background runs.
Parameters¶
payloads¶
RunsCreatePayload & object[]
An array of payloads for creating runs.
Returns¶
Promise\<Run[]>
An array of created runs.
delete()¶
delete(
threadId,runId):Promise\<void>
Defined in: client.ts:1157
Delete a run.
Parameters¶
threadId¶
string
The ID of the thread.
runId¶
string
The ID of the run.
Returns¶
Promise\<void>
get()¶
get(
threadId,runId):Promise\<Run>
Defined in: client.ts:1050
Get a run by ID.
Parameters¶
threadId¶
string
The ID of the thread.
runId¶
string
The ID of the run.
Returns¶
Promise\<Run>
The run.
join()¶
join(
threadId,runId,options?):Promise\<void>
Defined in: client.ts:1085
Block until a run is done.
Parameters¶
threadId¶
string
The ID of the thread.
runId¶
string
The ID of the run.
options?¶
# signal?¶
AbortSignal
Returns¶
Promise\<void>
joinStream()¶
joinStream(
threadId,runId,options?):AsyncGenerator\<{data:any;event:StreamEvent; }>
Defined in: client.ts:1111
实时流式传输运行的输出,直到运行完成。 输出不被缓冲,因此在此调用之前产生的任何输出都不会 在此处接收。
Parameters¶
threadId¶
string
The ID of the thread.
runId¶
string
The ID of the run.
options?¶
控制流行为的附加选项: - signal: 可用于取消流请求的 AbortSignal - cancelOnDisconnect: 当为 true 时,如果客户端断开与流的连接,则自动取消运行 - streamMode: 控制从流接收哪些类型的事件(可以是单个模式或模式数组) 必须是创建运行时传递的流模式的子集。后台运行默认启用所有 流模式的并集。
AbortSignal | { cancelOnDisconnect: boolean; signal: AbortSignal; streamMode: StreamMode | StreamMode[]; }
Returns¶
AsyncGenerator\<{ data: any; event: StreamEvent; }>
An async generator yielding stream parts.
list()¶
list(
threadId,options?):Promise\<Run[]>
Defined in: client.ts:1013
List all runs for a thread.
Parameters¶
threadId¶
string
The ID of the thread.
options?¶
Filtering and pagination options.
# limit?¶
number
Maximum number of runs to return. Defaults to 10
# offset?¶
number
Offset to start from. Defaults to 0.
# status?¶
RunStatus
Status of the run to filter by.
Returns¶
Promise\<Run[]>
List of runs.
stream()¶
Create a run and stream the results.
Param¶
The ID of the thread.
Param¶
Assistant ID to use for this run.
Param¶
Payload for creating a run.
Call Signature¶
stream\<
TStreamMode,TSubgraphs>(threadId,assistantId,payload?):TypedAsyncGenerator\<TStreamMode,TSubgraphs,TStateType,TUpdateType,TCustomEventType>
Defined in: client.ts:781
Type Parameters¶
• TStreamMode extends StreamMode | StreamMode[] = StreamMode
• TSubgraphs extends boolean = false
Parameters¶
# threadId¶
null
# assistantId¶
string
# payload?¶
Omit\<RunsStreamPayload\<TStreamMode, TSubgraphs>, "multitaskStrategy" | "onCompletion">
Returns¶
TypedAsyncGenerator\<TStreamMode, TSubgraphs, TStateType, TUpdateType, TCustomEventType>
Call Signature¶
stream\<
TStreamMode,TSubgraphs>(threadId,assistantId,payload?):TypedAsyncGenerator\<TStreamMode,TSubgraphs,TStateType,TUpdateType,TCustomEventType>
Defined in: client.ts:799
Type Parameters¶
• TStreamMode extends StreamMode | StreamMode[] = StreamMode
• TSubgraphs extends boolean = false
Parameters¶
# threadId¶
string
# assistantId¶
string
# payload?¶
RunsStreamPayload\<TStreamMode, TSubgraphs>
Returns¶
TypedAsyncGenerator\<TStreamMode, TSubgraphs, TStateType, TUpdateType, TCustomEventType>
wait()¶
Create a run and wait for it to complete.
Param¶
The ID of the thread.
Param¶
Assistant ID to use for this run.
Param¶
Payload for creating a run.
Call Signature¶
wait(
threadId,assistantId,payload?):Promise\<DefaultValues>
Defined in: client.ts:938
Parameters¶
# threadId¶
null
# assistantId¶
string
# payload?¶
Omit\<RunsWaitPayload, "multitaskStrategy" | "onCompletion">
Returns¶
Promise\<DefaultValues>
Call Signature¶
wait(
threadId,assistantId,payload?):Promise\<DefaultValues>
Defined in: client.ts:944
Parameters¶
# threadId¶
string
# assistantId¶
string
# payload?¶
RunsWaitPayload
Returns¶
Promise\<DefaultValues>
@langchain/langgraph-sdk / StoreClient
Class: StoreClient¶
Defined in: client.ts:1175
Extends¶
BaseClient
Constructors¶
new StoreClient()¶
new StoreClient(
config?):StoreClient
Defined in: client.ts:88
Parameters¶
config?¶
Returns¶
Inherited from¶
BaseClient.constructor
Methods¶
deleteItem()¶
deleteItem(
namespace,key):Promise\<void>
Defined in: client.ts:1296
Delete an item.
Parameters¶
namespace¶
string[]
A list of strings representing the namespace path.
key¶
string
The unique identifier for the item.
Returns¶
Promise\<void>
Promise
getItem()¶
getItem(
namespace,key,options?):Promise\<null|Item>
Defined in: client.ts:1252
Retrieve a single item.
Parameters¶
namespace¶
string[]
A list of strings representing the namespace path.
key¶
string
The unique identifier for the item.
options?¶
# refreshTtl?¶
null | boolean
是否在此读取操作上刷新 TTL。如果为 null,则使用存储的默认行为。
Returns¶
Promise\<null | Item>
Promise
Example¶
const item = await client.store.getItem(
["documents", "user123"],
"item456",
{ refreshTtl: true }
);
console.log(item);
// {
// namespace: ["documents", "user123"],
// key: "item456",
// value: { title: "My Document", content: "Hello World" },
// createdAt: "2024-07-30T12:00:00Z",
// updatedAt: "2024-07-30T12:00:00Z"
// }
listNamespaces()¶
listNamespaces(
options?):Promise\<ListNamespaceResponse>
Defined in: client.ts:1392
List namespaces with optional match conditions.
Parameters¶
options?¶
# limit?¶
number
Maximum number of namespaces to return (default is 100).
# maxDepth?¶
number
Optional integer specifying the maximum depth of namespaces to return.
# offset?¶
number
Number of namespaces to skip before returning results (default is 0).
# prefix?¶
string[]
Optional list of strings representing the prefix to filter namespaces.
# suffix?¶
string[]
Optional list of strings representing the suffix to filter namespaces.
Returns¶
Promise\<ListNamespaceResponse>
Promise
putItem()¶
putItem(
namespace,key,value,options?):Promise\<void>
Defined in: client.ts:1196
Store or update an item.
Parameters¶
namespace¶
string[]
A list of strings representing the namespace path.
key¶
string
The unique identifier for the item within the namespace.
value¶
Record\<string, any>
包含项目数据的字典。
options?¶
# index?¶
null | false | string[]
控制搜索索引 - null(使用默认值)、false(禁用)或要索引的字段路径列表。
# ttl?¶
null | number
项目的可选生存时间(以分钟为单位),或为 null 表示无过期时间。
Returns¶
Promise\<void>
Promise
Example¶
await client.store.putItem(
["documents", "user123"],
"item456",
{ title: "My Document", content: "Hello World" },
{ ttl: 60 } // expires in 60 minutes
);
searchItems()¶
searchItems(
namespacePrefix,options?):Promise\<SearchItemsResponse>
Defined in: client.ts:1347
Search for items within a namespace prefix.
Parameters¶
namespacePrefix¶
string[]
List of strings representing the namespace prefix.
options?¶
# filter?¶
Record\<string, any>
Optional dictionary of key-value pairs to filter results.
# limit?¶
number
Maximum number of items to return (default is 10).
# offset?¶
number
Number of items to skip before returning results (default is 0).
# query?¶
string
Optional search query.
# refreshTtl?¶
null | boolean
是否在此搜索返回的项目上刷新 TTL。如果为 null,则使用存储的默认行为。
Returns¶
Promise\<SearchItemsResponse>
Promise
Example¶
const results = await client.store.searchItems(
["documents"],
{
filter: { author: "John Doe" },
limit: 5,
refreshTtl: true
}
);
console.log(results);
// {
// items: [
// {
// namespace: ["documents", "user123"],
// key: "item789",
// value: { title: "Another Document", author: "John Doe" },
// createdAt: "2024-07-30T12:00:00Z",
// updatedAt: "2024-07-30T12:00:00Z"
// },
// // ... additional items ...
// ]
// }
@langchain/langgraph-sdk / ThreadsClient
Class: ThreadsClient\<TStateType, TUpdateType>¶
Defined in: client.ts:489
Extends¶
BaseClient
Type Parameters¶
• TStateType = DefaultValues
• TUpdateType = TStateType
Constructors¶
new ThreadsClient()¶
new ThreadsClient\<
TStateType,TUpdateType>(config?):ThreadsClient\<TStateType,TUpdateType>
Defined in: client.ts:88
Parameters¶
config?¶
Returns¶
ThreadsClient\<TStateType, TUpdateType>
Inherited from¶
BaseClient.constructor
Methods¶
copy()¶
copy(
threadId):Promise\<Thread\<TStateType>>
Defined in: client.ts:566
Copy an existing thread
Parameters¶
threadId¶
string
ID of the thread to be copied
Returns¶
Promise\<Thread\<TStateType>>
Newly copied thread
create()¶
create(
payload?):Promise\<Thread\<TStateType>>
Defined in: client.ts:511
Create a new thread.
Parameters¶
payload?¶
Payload for creating a thread.
# graphId?¶
string
Graph ID to associate with the thread.
# ifExists?¶
OnConflictBehavior
How to handle duplicate creation.
Default
# metadata?¶
Metadata
Metadata for the thread.
# supersteps?¶
object[]
Apply a list of supersteps when creating a thread, each containing a sequence of updates.
Used for copying a thread between deployments.
# threadId?¶
string
要创建的线程的 ID。
如果未提供,将生成一个随机 UUID。
Returns¶
Promise\<Thread\<TStateType>>
The created thread.
delete()¶
delete(
threadId):Promise\<void>
Defined in: client.ts:599
Delete a thread.
Parameters¶
threadId¶
string
ID of the thread.
Returns¶
Promise\<void>
get()¶
get\<
ValuesType>(threadId):Promise\<Thread\<ValuesType>>
Defined in: client.ts:499
Get a thread by ID.
Type Parameters¶
• ValuesType = TStateType
Parameters¶
threadId¶
string
ID of the thread.
Returns¶
Promise\<Thread\<ValuesType>>
The thread.
getHistory()¶
getHistory\<
ValuesType>(threadId,options?):Promise\<ThreadState\<ValuesType>[]>
Defined in: client.ts:752
Get all past states for a thread.
Type Parameters¶
• ValuesType = TStateType
Parameters¶
threadId¶
string
ID of the thread.
options?¶
Additional options.
# before?¶
Config
# checkpoint?¶
Partial\<Omit\<Checkpoint, "thread_id">>
# limit?¶
number
# metadata?¶
Metadata
Returns¶
Promise\<ThreadState\<ValuesType>[]>
List of thread states.
getState()¶
getState\<
ValuesType>(threadId,checkpoint?,options?):Promise\<ThreadState\<ValuesType>>
Defined in: client.ts:659
Get state for a thread.
Type Parameters¶
• ValuesType = TStateType
Parameters¶
threadId¶
string
ID of the thread.
checkpoint?¶
string | Checkpoint
options?¶
# subgraphs?¶
boolean
Returns¶
Promise\<ThreadState\<ValuesType>>
Thread state.
patchState()¶
patchState(
threadIdOrConfig,metadata):Promise\<void>
Defined in: client.ts:722
Patch the metadata of a thread.
Parameters¶
threadIdOrConfig¶
Thread ID or config to patch the state of.
string | Config
metadata¶
Metadata
Metadata to patch the state with.
Returns¶
Promise\<void>
search()¶
search\<
ValuesType>(query?):Promise\<Thread\<ValuesType>[]>
Defined in: client.ts:611
List threads
Type Parameters¶
• ValuesType = TStateType
Parameters¶
query?¶
Query options
# limit?¶
number
Maximum number of threads to return. Defaults to 10
# metadata?¶
Metadata
Metadata to filter threads by.
# offset?¶
number
Offset to start from.
# sortBy?¶
ThreadSortBy
Sort by.
# sortOrder?¶
SortOrder
排序顺序。 必须是 'asc' 或 'desc' 之一。
# status?¶
ThreadStatus
要过滤的线程状态。 必须是 'idle'、'busy'、'interrupted' 或 'error' 之一。
Returns¶
Promise\<Thread\<ValuesType>[]>
List of threads
update()¶
update(
threadId,payload?):Promise\<Thread\<DefaultValues>>
Defined in: client.ts:579
Update a thread.
Parameters¶
threadId¶
string
ID of the thread.
payload?¶
Payload for updating the thread.
# metadata?¶
Metadata
Metadata for the thread.
Returns¶
Promise\<Thread\<DefaultValues>>
The updated thread.
updateState()¶
updateState\<
ValuesType>(threadId,options):Promise\<Pick\<Config,"configurable">>
Defined in: client.ts:693
Add state to a thread.
Type Parameters¶
• ValuesType = TUpdateType
Parameters¶
threadId¶
string
The ID of the thread.
options¶
# asNode?¶
string
# checkpoint?¶
Checkpoint
# checkpointId?¶
string
# values¶
ValuesType
Returns¶
Promise\<Pick\<Config, "configurable">>
@langchain/langgraph-sdk / getApiKey
Function: getApiKey()¶
getApiKey(
apiKey?):undefined|string
Defined in: client.ts:53
Get the API key from the environment. Precedence: 1. explicit argument 2. LANGGRAPH_API_KEY 3. LANGSMITH_API_KEY 4. LANGCHAIN_API_KEY
Parameters¶
apiKey?¶
string
Optional API key provided as an argument
Returns¶
undefined | string
如果找到则返回 API 密钥,否则返回 undefined
@langchain/langgraph-sdk / ClientConfig
Interface: ClientConfig¶
Defined in: client.ts:71
Properties¶
apiKey?¶
optionalapiKey:string
Defined in: client.ts:73
apiUrl?¶
optionalapiUrl:string
Defined in: client.ts:72
callerOptions?¶
optionalcallerOptions:AsyncCallerParams
Defined in: client.ts:74
defaultHeaders?¶
optionaldefaultHeaders:Record\<string,undefined|null|string>
Defined in: client.ts:76
timeoutMs?¶
optionaltimeoutMs:number
Defined in: client.ts:75
@langchain/langgraph-sdk
@langchain/langgraph-sdk/react¶
Interfaces¶
Type Aliases¶
Functions¶
@langchain/langgraph-sdk / useStream
Function: useStream()¶
useStream\<
StateType,Bag>(options):UseStream\<StateType,Bag>
Defined in: react/stream.tsx:618
Type Parameters¶
• StateType extends Record\<string, unknown> = Record\<string, unknown>
• Bag extends object = BagTemplate
Parameters¶
options¶
UseStreamOptions\<StateType, Bag>
Returns¶
UseStream\<StateType, Bag>
@langchain/langgraph-sdk / UseStream
Interface: UseStream\<StateType, Bag>¶
Defined in: react/stream.tsx:507
Type Parameters¶
• StateType extends Record\<string, unknown> = Record\<string, unknown>
• Bag extends BagTemplate = BagTemplate
Properties¶
assistantId¶
assistantId:
string
Defined in: react/stream.tsx:592
The ID of the assistant to use.
branch¶
branch:
string
Defined in: react/stream.tsx:542
The current branch of the thread.
client¶
client:
Client
Defined in: react/stream.tsx:587
LangGraph SDK client used to send request and receive responses.
error¶
error:
unknown
Defined in: react/stream.tsx:519
Last seen error from the thread or during streaming.
experimental_branchTree¶
experimental_branchTree:
Sequence\<StateType>
Defined in: react/stream.tsx:558
Experimental
Tree of all branches for the thread.
getMessagesMetadata()¶
getMessagesMetadata: (
message,index?) =>undefined|MessageMetadata\<StateType>
Defined in: react/stream.tsx:579
获取消息的元数据,例如首次在其中看到该消息的线程状态 和分支信息。
Parameters¶
message¶
Message
The message to get the metadata for.
index?¶
number
The index of the message in the thread.
Returns¶
undefined | MessageMetadata\<StateType>
The metadata for the message.
history¶
history:
ThreadState\<StateType>[]
Defined in: react/stream.tsx:552
Flattened history of thread states of a thread.
interrupt¶
interrupt:
undefined|Interrupt\<GetInterruptType\<Bag>>
Defined in: react/stream.tsx:563
Get the interrupt value for the stream if interrupted.
isLoading¶
isLoading:
boolean
Defined in: react/stream.tsx:524
Whether the stream is currently running.
messages¶
messages:
Message[]
Defined in: react/stream.tsx:569
Messages inferred from the thread. Will automatically update with incoming message chunks.
setBranch()¶
setBranch: (
branch) =>void
Defined in: react/stream.tsx:547
Set the branch of the thread.
Parameters¶
branch¶
string
Returns¶
void
stop()¶
stop: () =>
void
Defined in: react/stream.tsx:529
Stops the stream.
Returns¶
void
submit()¶
submit: (
values,options?) =>void
Defined in: react/stream.tsx:534
Create and stream a run to the thread.
Parameters¶
values¶
undefined | null | GetUpdateType\<Bag, StateType>
options?¶
SubmitOptions\<StateType, GetConfigurableType\<Bag>>
Returns¶
void
values¶
values:
StateType
Defined in: react/stream.tsx:514
The current values of the thread.
@langchain/langgraph-sdk / UseStreamOptions
Interface: UseStreamOptions\<StateType, Bag>¶
Defined in: react/stream.tsx:408
Type Parameters¶
• StateType extends Record\<string, unknown> = Record\<string, unknown>
• Bag extends BagTemplate = BagTemplate
Properties¶
apiKey?¶
optionalapiKey:string
Defined in: react/stream.tsx:430
The API key to use.
apiUrl?¶
optionalapiUrl:string
Defined in: react/stream.tsx:425
The URL of the API to use.
assistantId¶
assistantId:
string
Defined in: react/stream.tsx:415
The ID of the assistant to use.
callerOptions?¶
optionalcallerOptions:AsyncCallerParams
Defined in: react/stream.tsx:435
Custom call options, such as custom fetch implementation.
client?¶
optionalclient:Client\<DefaultValues,DefaultValues,unknown>
Defined in: react/stream.tsx:420
Client used to send requests.
defaultHeaders?¶
optionaldefaultHeaders:Record\<string,undefined|null|string>
Defined in: react/stream.tsx:440
Default headers to send with requests.
messagesKey?¶
optionalmessagesKey:string
Defined in: react/stream.tsx:448
Specify the key within the state that contains messages. Defaults to "messages".
Default¶
onCustomEvent()?¶
optionalonCustomEvent: (data,options) =>void
Defined in: react/stream.tsx:470
Callback that is called when a custom event is received.
Parameters¶
data¶
GetCustomEventType\<Bag>
options¶
# mutate¶
(update) => void
Returns¶
void
onDebugEvent()?¶
optionalonDebugEvent: (data) =>void
Defined in: react/stream.tsx:494
Internal
Callback that is called when a debug event is received. This API is experimental and subject to change.
Parameters¶
data¶
unknown
Returns¶
void
onError()?¶
optionalonError: (error) =>void
Defined in: react/stream.tsx:453
Callback that is called when an error occurs.
Parameters¶
error¶
unknown
Returns¶
void
onFinish()?¶
optionalonFinish: (state) =>void
Defined in: react/stream.tsx:458
Callback that is called when the stream is finished.
Parameters¶
state¶
ThreadState\<StateType>
Returns¶
void
onLangChainEvent()?¶
optionalonLangChainEvent: (data) =>void
Defined in: react/stream.tsx:488
Callback that is called when a LangChain event is received.
Parameters¶
data¶
# data¶
unknown
# event¶
string & object | "on_tool_start" | "on_tool_stream" | "on_tool_end" | "on_chat_model_start" | "on_chat_model_stream" | "on_chat_model_end" | "on_llm_start" | "on_llm_stream" | "on_llm_end" | "on_chain_start" | "on_chain_stream" | "on_chain_end" | "on_retriever_start" | "on_retriever_stream" | "on_retriever_end" | "on_prompt_start" | "on_prompt_stream" | "on_prompt_end"
# metadata¶
Record\<string, unknown>
# name¶
string
# parent_ids¶
string[]
# run_id¶
string
# tags¶
string[]
Returns¶
void
See¶
https://langchain-ai.github.io/langgraph/cloud/how-tos/stream_events/#stream-graph-in-events-mode for more details.
onMetadataEvent()?¶
optionalonMetadataEvent: (data) =>void
Defined in: react/stream.tsx:482
Callback that is called when a metadata event is received.
Parameters¶
data¶
# run_id¶
string
# thread_id¶
string
Returns¶
void
onThreadId()?¶
optionalonThreadId: (threadId) =>void
Defined in: react/stream.tsx:504
当线程 ID 更新时调用的回调(即创建新线程时)。
Parameters¶
threadId¶
string
Returns¶
void
onUpdateEvent()?¶
optionalonUpdateEvent: (data) =>void
Defined in: react/stream.tsx:463
Callback that is called when an update event is received.
Parameters¶
data¶
Returns¶
void
threadId?¶
optionalthreadId:null|string
Defined in: react/stream.tsx:499
The ID of the thread to fetch history and current values from.
@langchain/langgraph-sdk / MessageMetadata
Type Alias: MessageMetadata\<StateType>¶
MessageMetadata\<
StateType>:object
Defined in: react/stream.tsx:169
Type Parameters¶
• StateType extends Record\<string, unknown>
Type declaration¶
branch¶
branch:
string|undefined
The branch of the message.
branchOptions¶
branchOptions:
string[] |undefined
The list of branches this message is part of. This is useful for displaying branching controls.
firstSeenState¶
firstSeenState:
ThreadState\<StateType> |undefined
The first thread state the message was seen in.
messageId¶
messageId:
string
The ID of the message used.