Spaces:
Running
Running
File size: 1,372 Bytes
372531f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
import { Client } from "@langchain/langgraph-sdk";
import { task } from '../../config/task';
export async function startLanggraphResearch(newQuestion, report_source, langgraphHostUrl) {
// Update the task query with the new question
task.task.query = newQuestion;
task.task.source = report_source;
const host = langgraphHostUrl;
// Add your Langgraph Cloud Authentication token here
const authToken = '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';
const client = new Client({
apiUrl: host,
defaultHeaders: {
'Content-Type': 'application/json',
'X-Api-Key': authToken
}
});
// List all assistants
const assistants = await client.assistants.search({
metadata: null,
offset: 0,
limit: 10,
});
console.log('assistants: ', assistants);
// We auto-create an assistant for each graph you register in config.
const agent = assistants[0];
// Start a new thread
const thread = await client.threads.create();
// Start a streaming run
const input = task;
const streamResponse = client.runs.stream(
thread["thread_id"],
agent["assistant_id"],
{
input,
},
);
return {streamResponse, host, thread_id: thread["thread_id"]};
} |