Skip to content

Commit bb81817

Browse files
committed
feat(langgraph): new thread metadata
1 parent 323aa18 commit bb81817

File tree

1 file changed

+7
-3
lines changed
  • typescript-sdk/integrations/langgraph/src

1 file changed

+7
-3
lines changed

typescript-sdk/integrations/langgraph/src/index.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ type RunAgentExtendedInput<
9393
> = Omit<RunAgentInput, "forwardedProps"> & {
9494
forwardedProps?: Omit<RunsStreamPayload<TStreamMode, TSubgraphs>, "input"> & {
9595
nodeName?: string;
96+
threadMetadata?: Record<string, any>;
9697
};
9798
};
9899

@@ -166,7 +167,7 @@ export class LangGraphAgent extends AbstractAgent {
166167
this.assistant = await this.getAssistant();
167168
}
168169

169-
const thread = await this.getOrCreateThread(threadId);
170+
const thread = await this.getOrCreateThread(threadId, forwardedProps?.threadMetadata);
170171
this.activeRun!.threadId = thread.thread_id;
171172
const agentState = await this.client.threads.getState(thread.thread_id) ?? { values: {} } as ThreadState
172173

@@ -673,13 +674,16 @@ export class LangGraphAgent extends AbstractAgent {
673674
return state;
674675
}
675676

676-
async getOrCreateThread(threadId: string): Promise<Thread> {
677+
async getOrCreateThread(threadId: string, threadMetadata?: Record<string, any>): Promise<Thread> {
677678
let thread: Thread;
678679
try {
679680
try {
680681
thread = await this.getThread(threadId);
681682
} catch (error) {
682-
thread = await this.createThread({ threadId });
683+
thread = await this.createThread({
684+
threadId,
685+
metadata: threadMetadata
686+
});
683687
}
684688
} catch (error: unknown) {
685689
throw new Error(`Failed to create thread: ${(error as Error).message}`);

0 commit comments

Comments
 (0)