-
-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathtest-parallel-direct.js
More file actions
155 lines (134 loc) · 4.82 KB
/
test-parallel-direct.js
File metadata and controls
155 lines (134 loc) · 4.82 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
const http = require('http');
console.log('========================================');
console.log('Direct Parallel Subagent Test');
console.log('========================================\n');
// Directly call the /v1/messages endpoint with tool_use blocks in assistant message
// This simulates what happens when the model returns multiple Task tool calls
const testPayload = {
model: "claude-3-5-sonnet-20241022",
max_tokens: 8000,
messages: [
{
role: "user",
content: "Please use three Explore agents in parallel to: 1) list files in src/config, 2) find test files, and 3) check what agents are defined."
},
{
role: "assistant",
content: [
{
type: "text",
text: "I'll execute these three exploration tasks in parallel."
},
{
type: "tool_use",
id: "task_001",
name: "Task",
input: {
subagent_type: "Explore",
description: "List config files",
prompt: "List all files in the src/config directory. Just show the file names."
}
},
{
type: "tool_use",
id: "task_002",
name: "Task",
input: {
subagent_type: "Explore",
description: "Find test files",
prompt: "Find all test files in the project (*.test.js, *.spec.js). List the file paths."
}
},
{
type: "tool_use",
id: "task_003",
name: "Task",
input: {
subagent_type: "Explore",
description: "Check agent definitions",
prompt: "Find where agent types are defined in the codebase. Look for agent definitions like Explore, Plan, Test, etc."
}
}
]
}
]
};
const options = {
hostname: 'localhost',
port: 8080,
path: '/v1/messages',
method: 'POST',
headers: {
'Content-Type': 'application/json'
}
};
console.log('Sending request with 3 Task tool calls...\n');
const startTime = Date.now();
const req = http.request(options, (res) => {
let data = '';
res.on('data', (chunk) => {
data += chunk;
});
res.on('end', () => {
const duration = Date.now() - startTime;
console.log(`Request completed in ${(duration / 1000).toFixed(1)} seconds\n`);
try {
const response = JSON.parse(data);
console.log('========================================');
console.log('Response Analysis:');
console.log('========================================\n');
console.log(`Content blocks: ${response.content?.length || 0}`);
if (response.content) {
response.content.forEach((block, i) => {
console.log(`\nBlock ${i + 1}:`);
console.log(` Type: ${block.type}`);
if (block.type === 'tool_result') {
console.log(` Tool Use ID: ${block.tool_use_id}`);
console.log(` Is Error: ${block.is_error || false}`);
console.log(` Content (first 200 chars): ${block.content?.substring(0, 200)}...`);
} else if (block.type === 'text') {
console.log(` Text (first 100 chars): ${block.text?.substring(0, 100)}...`);
}
});
}
console.log('\n========================================');
console.log('Log Analysis:');
console.log('========================================\n');
// Check logs for parallel execution
const { execSync } = require('child_process');
try {
const parallelStart = execSync('grep "Executing multiple Task tools in parallel" /tmp/lynkr.log | tail -1').toString().trim();
if (parallelStart) {
console.log('✅ Found parallel execution log entry');
const match = parallelStart.match(/"taskCount":\s*(\d+)/);
if (match) {
console.log(` Task count: ${match[1]}`);
}
} else {
console.log('❌ No parallel execution log found');
}
const parallelComplete = execSync('grep "Completed parallel Task execution" /tmp/lynkr.log | tail -1').toString().trim();
if (parallelComplete) {
console.log('✅ Found parallel completion log entry');
const match = parallelComplete.match(/"completedTasks":\s*(\d+)/);
if (match) {
console.log(` Completed tasks: ${match[1]}`);
}
}
} catch (e) {
console.log('⚠️ Could not read logs');
}
console.log('\n========================================');
console.log('Test Complete!');
console.log('========================================\n');
} catch (error) {
console.error('Error parsing response:', error.message);
console.log('Raw response:', data.substring(0, 500));
}
});
});
req.on('error', (error) => {
console.error('Request error:', error);
});
req.write(JSON.stringify(testPayload));
req.end();