MCPcopy Create free account
hub / github.com/AI45Lab/Code / main

Function main

sdk/node/examples/streaming/reasoning_delta_test.ts:9–78  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

7import { Agent } from '../../index.js';
8
9async function main(): Promise<void> {
10 const configPath = '/Users/roylin/Desktop/code/a3s/crates/code/sdk/node/examples/streaming/test_config3.acl';
11 console.log(`Using config: ${configPath}\n`);
12
13 const agent = await Agent.create(configPath);
14 const session = agent.session('.', {
15 permissionPolicy: { defaultDecision: 'allow' }, // maxToolRounds: 0, // Don't limit - we need LLM call to test reasoning_delta
16 });
17
18 const prompt = 'Why is the sky blue? Answer in 2 sentences.';
19 console.log(`Streaming with prompt: "${prompt}"\n`);
20
21 const stream = await session.stream(prompt);
22
23 let eventCount = 0;
24 let textDeltaCount = 0;
25 let reasoningDeltaCount = 0;
26 let totalText = '';
27 let totalReasoning = '';
28 const eventTypes = new Map<string, number>();
29
30 while (true) {
31 const result = await stream.next();
32 if (!result.value || result.done) break;
33
34 const event = result.value;
35 eventCount++;
36
37 // Count event types
38 const type = event.type || 'unknown';
39 eventTypes.set(type, (eventTypes.get(type) || 0) + 1);
40
41 if (type === 'text_delta' && event.text) {
42 textDeltaCount++;
43 totalText += event.text;
44 } else if (type === 'reasoning_delta' && event.text) {
45 reasoningDeltaCount++;
46 totalReasoning += event.text;
47 }
48
49 console.log(`[${eventCount}] type="${type}"` +
50 (event.text ? ` text="${event.text.slice(0, 60)}"` : '') +
51 (event.data ? ` data="${event.data?.slice(0, 60)}"` : '')
52 );
53 }
54
55 console.log('\n' + '='.repeat(80));
56 console.log('Summary:');
57 console.log(`Total events: ${eventCount}`);
58 console.log(`Event type distribution:`);
59 for (const [type, count] of eventTypes) {
60 console.log(` - ${type}: ${count}`);
61 }
62 console.log(`\nTextDelta events: ${textDeltaCount}`);
63 console.log(`Text content length: ${totalText.length}`);
64 console.log(`ReasoningDelta events: ${reasoningDeltaCount}`);
65 console.log(`Reasoning content length: ${totalReasoning.length}`);
66

Callers 1

Calls 7

logMethod · 0.45
createMethod · 0.45
sessionMethod · 0.45
streamMethod · 0.45
nextMethod · 0.45
setMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected