1+ const codebolt = require ( '@codebolt/codeboltjs' ) ;
2+
3+ async function testAgent ( ) {
4+ console . log ( '🤖 Testing Agent Module' ) ;
5+ console . log ( '=======================' ) ;
6+
7+ try {
8+ await codebolt . waitForConnection ( ) ;
9+
10+ console . log ( '\n1. Testing agent list retrieval...' ) ;
11+ try {
12+ const agentsListResult = await codebolt . agent . getAgentsList ( 'downloaded' ) ;
13+ console . log ( '✅ Agents list result:' , agentsListResult ) ;
14+ console . log ( ' - Type:' , agentsListResult ?. type ) ;
15+ console . log ( ' - Agents count:' , agentsListResult ?. agents ?. length || 0 ) ;
16+ if ( agentsListResult ?. agents ?. length > 0 ) {
17+ console . log ( ' - First agent:' , agentsListResult . agents [ 0 ] ) ;
18+ }
19+ } catch ( error ) {
20+ console . log ( '⚠️ Agent list retrieval failed:' , error . message ) ;
21+ }
22+
23+ console . log ( '\n2. Testing all agents list...' ) ;
24+ try {
25+ const allAgentsResult = await codebolt . agent . getAgentsList ( 'all' ) ;
26+ console . log ( '✅ All agents result:' , allAgentsResult ) ;
27+ console . log ( ' - Type:' , allAgentsResult ?. type ) ;
28+ console . log ( ' - Total agents count:' , allAgentsResult ?. agents ?. length || 0 ) ;
29+ } catch ( error ) {
30+ console . log ( '⚠️ All agents list failed:' , error . message ) ;
31+ }
32+
33+ console . log ( '\n3. Testing local agents list...' ) ;
34+ try {
35+ const localAgentsResult = await codebolt . agent . getAgentsList ( 'local' ) ;
36+ console . log ( '✅ Local agents result:' , localAgentsResult ) ;
37+ console . log ( ' - Type:' , localAgentsResult ?. type ) ;
38+ console . log ( ' - Local agents count:' , localAgentsResult ?. agents ?. length || 0 ) ;
39+ } catch ( error ) {
40+ console . log ( '⚠️ Local agents list failed:' , error . message ) ;
41+ }
42+
43+ // console.log('\n4. Testing agent details retrieval...');
44+ // try {
45+ // // First get some agents to get details for
46+ // const agentsList = await codebolt.agent.getAgentsList('downloaded');
47+ // if (agentsList?.agents && agentsList.agents.length > 0) {
48+ // const agentIds = agentsList.agents.slice(0, 2).map(agent => agent.function?.name || agent.id || agent.name);
49+ // console.log(' - Agent IDs to get details for:', agentIds);
50+ // const agentsDetailResult = await codebolt.agent.getAgentsDetail(agentIds);
51+ // console.log('✅ Agents detail result:', agentsDetailResult);
52+ // console.log(' - Details count:', agentsDetailResult?.agents?.length || 0);
53+ // } else {
54+ // console.log('⚠️ No agents available for detail retrieval');
55+ // }
56+ // } catch (error) {
57+ // console.log('⚠️ Agent details retrieval failed:', error.message);
58+ // }
59+
60+ console . log ( '\n5. Testing agent finding by task...' ) ;
61+ const testTask = 'Generate JavaScript code for a simple calculator' ;
62+ try {
63+ const findAgentResult = await codebolt . agent . findAgent (
64+ testTask ,
65+ 3 , // maxResult
66+ [ ] , // agents filter
67+ 'all' , // agentLocation
68+ 'use_vector_db' // getFrom
69+ ) ;
70+ console . log ( '✅ Find agent result:' , findAgentResult ) ;
71+ console . log ( ' - Task:' , testTask ) ;
72+ console . log ( ' - Found agents count:' , findAgentResult ?. agents ?. length || 0 ) ;
73+ if ( findAgentResult ?. agents ?. length > 0 ) {
74+ console . log ( ' - Best match:' , findAgentResult . agents [ 0 ] ) ;
75+ }
76+ } catch ( error ) {
77+ console . log ( '⚠️ Agent finding failed:' , error . message ) ;
78+ }
79+
80+ console . log ( '\n6. Testing agent finding with different parameters...' ) ;
81+ const analysisTask = 'Analyze data and provide insights' ;
82+ try {
83+ const findAnalysisAgentResult = await codebolt . agent . findAgent (
84+ analysisTask ,
85+ 1 , // maxResult
86+ [ ] , // agents filter
87+ 'local_only' , // agentLocation
88+ 'use_ai' // getFrom
89+ ) ;
90+ console . log ( '✅ Find analysis agent result:' , findAnalysisAgentResult ) ;
91+ console . log ( ' - Task:' , analysisTask ) ;
92+ console . log ( ' - Location filter:' , 'local_only' ) ;
93+ console . log ( ' - Found agents count:' , findAnalysisAgentResult ?. agents ?. length || 0 ) ;
94+ } catch ( error ) {
95+ console . log ( '⚠️ Analysis agent finding failed:' , error . message ) ;
96+ }
97+
98+ console . log ( '\n7. Testing agent starting...' ) ;
99+ try {
100+ // First find an agent
101+ const findResult = await codebolt . agent . findAgent ( 'Documentation Agent' , 1 ) ;
102+ if ( findResult ?. agents && findResult . agents . length > 0 ) {
103+ const agentId = findResult . agents [ 0 ] . function ?. name || findResult . agents [ 0 ] . id || findResult . agents [ 0 ] . name ;
104+ const startTask = 'Create a simple hello world function' ;
105+
106+ const startAgentResult = await codebolt . agent . startAgent ( agentId , startTask ) ;
107+ console . log ( '✅ Start agent result:' , startAgentResult ) ;
108+ console . log ( ' - Agent ID:' , agentId ) ;
109+ console . log ( ' - Task:' , startTask ) ;
110+ console . log ( ' - Status:' , startAgentResult ?. status ) ;
111+ console . log ( ' - Response type:' , startAgentResult ?. type ) ;
112+ } else {
113+ console . log ( '⚠️ No agents found to start' ) ;
114+ }
115+ } catch ( error ) {
116+ console . log ( '⚠️ Agent starting failed:' , error . message ) ;
117+ }
118+
119+ console . log ( '\n8. Testing agent finding with specific agent filter...' ) ;
120+ try {
121+ // Get some agent names first
122+ const agentsList = await codebolt . agent . getAgentsList ( 'downloaded' ) ;
123+ if ( agentsList ?. agents && agentsList . agents . length > 0 ) {
124+ const agentNames = agentsList . agents . slice ( 0 , 2 ) . map ( agent => agent . function ?. name || agent . name || agent . id ) ;
125+
126+ const filteredFindResult = await codebolt . agent . findAgent (
127+ 'Code generation task' ,
128+ 2 ,
129+ agentNames , // filter by specific agents
130+ 'all' ,
131+ 'use_both'
132+ ) ;
133+ console . log ( '✅ Filtered find result:' , filteredFindResult ) ;
134+ console . log ( ' - Filter agents:' , agentNames ) ;
135+ console . log ( ' - Found agents count:' , filteredFindResult ?. agents ?. length || 0 ) ;
136+ } else {
137+ console . log ( '⚠️ No agents available for filtering' ) ;
138+ }
139+ } catch ( error ) {
140+ console . log ( '⚠️ Filtered agent finding failed:' , error . message ) ;
141+ }
142+
143+ console . log ( '\n9. Testing agent finding with remote only location...' ) ;
144+ try {
145+ const remoteAgentResult = await codebolt . agent . findAgent (
146+ 'Complex data processing task' ,
147+ 5 ,
148+ [ ] ,
149+ 'remote_only' ,
150+ 'use_vector_db'
151+ ) ;
152+ console . log ( '✅ Remote agent result:' , remoteAgentResult ) ;
153+ console . log ( ' - Location filter:' , 'remote_only' ) ;
154+ console . log ( ' - Found agents count:' , remoteAgentResult ?. agents ?. length || 0 ) ;
155+ } catch ( error ) {
156+ console . log ( '⚠️ Remote agent finding failed:' , error . message ) ;
157+ }
158+
159+ console . log ( '\n10. Testing comprehensive agent workflow...' ) ;
160+ try {
161+ const workflowTask = 'Build a React component for user authentication' ;
162+
163+ // Step 1: Find suitable agents
164+ const foundAgents = await codebolt . agent . findAgent ( workflowTask , 3 ) ;
165+ console . log ( ' - Found agents for workflow:' , foundAgents ?. agents ?. length || 0 ) ;
166+
167+ if ( foundAgents ?. agents && foundAgents . agents . length > 0 ) {
168+ // Step 2: Get detailed information about the best agent
169+ const bestAgent = foundAgents . agents [ 0 ] ;
170+ const agentId = bestAgent . function ?. name || bestAgent . id || bestAgent . name ;
171+ const agentDetails = await codebolt . agent . getAgentsDetail ( [ agentId ] ) ;
172+ console . log ( ' - Agent details retrieved:' , agentDetails ?. agents ?. length || 0 ) ;
173+
174+ // Step 3: Start the agent with the task
175+ const workflowResult = await codebolt . agent . startAgent ( agentId , workflowTask ) ;
176+ console . log ( '✅ Workflow completion:' , workflowResult ?. type ) ;
177+ } else {
178+ console . log ( '⚠️ No suitable agents found for workflow' ) ;
179+ }
180+ } catch ( error ) {
181+ console . log ( '⚠️ Agent workflow failed:' , error . message ) ;
182+ }
183+
184+ console . log ( '\n🎉 All agent tests completed successfully!' ) ;
185+ console . log ( 'Note: Some tests may show warnings if no agents are available or configured' ) ;
186+
187+ } catch ( error ) {
188+ console . error ( '❌ Agent test error:' , error . message ) ;
189+ console . error ( 'Stack trace:' , error . stack ) ;
190+ }
191+ }
192+
193+ testAgent ( ) . catch ( console . error ) ;
0 commit comments