mirror of
https://github.com/langchain-ai/docs.git
synced 2026-08-28 05:10:00 -04:00
26 lines
653 B
Plaintext
26 lines
653 B
Plaintext
```ts
|
|
let question = "Which genre, on average, has the longest tracks?";
|
|
|
|
const stream = await agent.streamEvents(
|
|
{ messages: [{ role: "user", content: question }] },
|
|
{ version: "v3" },
|
|
);
|
|
await Promise.all([
|
|
(async () => {
|
|
for await (const message of stream.messages) {
|
|
for await (const token of message.text) {
|
|
process.stdout.write(token);
|
|
}
|
|
}
|
|
})(),
|
|
(async () => {
|
|
for await (const call of stream.toolCalls) {
|
|
console.log(`\nTool call: ${call.name}(${JSON.stringify(call.input)})`);
|
|
console.log(`Tool result: ${await call.output}`);
|
|
}
|
|
})(),
|
|
]);
|
|
|
|
const finalState = await stream.output;
|
|
```
|