Files
docs/build/snippets/python/code-samples/sql-agent-run-agent-js.mdx
T
2026-07-29 10:28:19 +00:00

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;
```