Stream Agent
User Intent
Operation
TypeScript (Canonical)
import { Graphlit } from 'graphlit-client';
const graphlit = new Graphlit();
await graphlit.streamAgent(
'What are the key findings in the uploaded documents?', // prompt
async (event) => {
// Handle different event types
switch (event.type) {
case 'conversation_started':
console.log(`Conversation ID: ${event.conversationId}`);
break;
case 'message_update':
// Streaming message chunks
process.stdout.write(event.message.message);
if (!event.isStreaming) {
console.log('\n[Message complete]');
}
break;
case 'tool_update':
console.log(`Tool: ${event.toolCall.name} - ${event.status}`);
break;
case 'conversation_completed':
console.log(`\nTotal tokens: ${event.usage?.tokens || 0}`);
break;
}
},
undefined, // conversationId (optional - creates new if omitted)
undefined, // specification (optional - uses project default)
[], // tools (optional - for function calling)
{} // toolHandlers (optional - tool implementations)
);Parameters
streamAgent
Response (via Events)
conversation_started
message_update
tool_update
conversation_completed
Developer Hints
Streaming vs Non-Streaming
Feature
streamAgent
promptConversation
Event Handler Must Be Async
Message Streaming Pattern
🛠 Tool Calling Lifecycle
Variations
1. Basic Streaming Chat
2. Multi-Turn Streaming Conversation
3. Streaming with Tool Calling
4. Streaming with Custom Model
5. Collect Full Message from Stream
6. Track Streaming Metrics
Common Issues
Production Example
Last updated