jiva-core 0.2.2 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.dockerignore +53 -0
- package/.gcloudignore +49 -0
- package/CONTRIBUTING.md +92 -0
- package/Dockerfile +63 -0
- package/LICENSE +21 -0
- package/README.md +248 -102
- package/cloud-run-deploy.yaml +135 -0
- package/cloud-run.yaml +135 -0
- package/cloud-run.yaml.template +143 -0
- package/deploy.sh +107 -0
- package/dist/core/agent-spawner.d.ts +89 -0
- package/dist/core/agent-spawner.d.ts.map +1 -0
- package/dist/core/agent-spawner.js +195 -0
- package/dist/core/agent-spawner.js.map +1 -0
- package/dist/core/client-agent.d.ts +82 -0
- package/dist/core/client-agent.d.ts.map +1 -0
- package/dist/core/client-agent.js +406 -0
- package/dist/core/client-agent.js.map +1 -0
- package/dist/core/config.d.ts +59 -10
- package/dist/core/config.d.ts.map +1 -1
- package/dist/core/config.js +19 -2
- package/dist/core/config.js.map +1 -1
- package/dist/core/conversation-manager.d.ts +10 -18
- package/dist/core/conversation-manager.d.ts.map +1 -1
- package/dist/core/conversation-manager.js +28 -60
- package/dist/core/conversation-manager.js.map +1 -1
- package/dist/core/dual-agent.d.ts +24 -3
- package/dist/core/dual-agent.d.ts.map +1 -1
- package/dist/core/dual-agent.js +112 -19
- package/dist/core/dual-agent.js.map +1 -1
- package/dist/core/manager-agent.d.ts +3 -1
- package/dist/core/manager-agent.d.ts.map +1 -1
- package/dist/core/manager-agent.js +66 -14
- package/dist/core/manager-agent.js.map +1 -1
- package/dist/core/worker-agent.d.ts +15 -1
- package/dist/core/worker-agent.d.ts.map +1 -1
- package/dist/core/worker-agent.js +244 -11
- package/dist/core/worker-agent.js.map +1 -1
- package/dist/core/workspace.d.ts +5 -0
- package/dist/core/workspace.d.ts.map +1 -1
- package/dist/core/workspace.js +47 -7
- package/dist/core/workspace.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/interfaces/cli/index.js +376 -44
- package/dist/interfaces/cli/index.js.map +1 -1
- package/dist/interfaces/cli/repl.d.ts.map +1 -1
- package/dist/interfaces/cli/repl.js +6 -0
- package/dist/interfaces/cli/repl.js.map +1 -1
- package/dist/interfaces/http/index.d.ts +22 -0
- package/dist/interfaces/http/index.d.ts.map +1 -0
- package/dist/interfaces/http/index.js +135 -0
- package/dist/interfaces/http/index.js.map +1 -0
- package/dist/interfaces/http/middleware/auth.d.ts +32 -0
- package/dist/interfaces/http/middleware/auth.d.ts.map +1 -0
- package/dist/interfaces/http/middleware/auth.js +176 -0
- package/dist/interfaces/http/middleware/auth.js.map +1 -0
- package/dist/interfaces/http/routes/chat.d.ts +7 -0
- package/dist/interfaces/http/routes/chat.d.ts.map +1 -0
- package/dist/interfaces/http/routes/chat.js +144 -0
- package/dist/interfaces/http/routes/chat.js.map +1 -0
- package/dist/interfaces/http/routes/health.d.ts +6 -0
- package/dist/interfaces/http/routes/health.d.ts.map +1 -0
- package/dist/interfaces/http/routes/health.js +25 -0
- package/dist/interfaces/http/routes/health.js.map +1 -0
- package/dist/interfaces/http/routes/session.d.ts +7 -0
- package/dist/interfaces/http/routes/session.d.ts.map +1 -0
- package/dist/interfaces/http/routes/session.js +114 -0
- package/dist/interfaces/http/routes/session.js.map +1 -0
- package/dist/interfaces/http/session-manager.d.ts +76 -0
- package/dist/interfaces/http/session-manager.d.ts.map +1 -0
- package/dist/interfaces/http/session-manager.js +339 -0
- package/dist/interfaces/http/session-manager.js.map +1 -0
- package/dist/interfaces/http/websocket-handler.d.ts +18 -0
- package/dist/interfaces/http/websocket-handler.d.ts.map +1 -0
- package/dist/interfaces/http/websocket-handler.js +146 -0
- package/dist/interfaces/http/websocket-handler.js.map +1 -0
- package/dist/mcp/client.d.ts +11 -2
- package/dist/mcp/client.d.ts.map +1 -1
- package/dist/mcp/client.js +44 -19
- package/dist/mcp/client.js.map +1 -1
- package/dist/mcp/server-manager.d.ts +1 -1
- package/dist/mcp/server-manager.d.ts.map +1 -1
- package/dist/mcp/server-manager.js +12 -2
- package/dist/mcp/server-manager.js.map +1 -1
- package/dist/personas/index.d.ts +13 -0
- package/dist/personas/index.d.ts.map +1 -0
- package/dist/personas/index.js +13 -0
- package/dist/personas/index.js.map +1 -0
- package/dist/personas/persona-loader.d.ts +30 -0
- package/dist/personas/persona-loader.d.ts.map +1 -0
- package/dist/personas/persona-loader.js +246 -0
- package/dist/personas/persona-loader.js.map +1 -0
- package/dist/personas/persona-manager.d.ts +82 -0
- package/dist/personas/persona-manager.d.ts.map +1 -0
- package/dist/personas/persona-manager.js +211 -0
- package/dist/personas/persona-manager.js.map +1 -0
- package/dist/personas/skill-loader.d.ts +35 -0
- package/dist/personas/skill-loader.d.ts.map +1 -0
- package/dist/personas/skill-loader.js +144 -0
- package/dist/personas/skill-loader.js.map +1 -0
- package/dist/personas/skill-packager.d.ts +25 -0
- package/dist/personas/skill-packager.d.ts.map +1 -0
- package/dist/personas/skill-packager.js +233 -0
- package/dist/personas/skill-packager.js.map +1 -0
- package/dist/personas/types.d.ts +134 -0
- package/dist/personas/types.d.ts.map +1 -0
- package/dist/personas/types.js +7 -0
- package/dist/personas/types.js.map +1 -0
- package/dist/personas/validator.d.ts +22 -0
- package/dist/personas/validator.d.ts.map +1 -0
- package/dist/personas/validator.js +144 -0
- package/dist/personas/validator.js.map +1 -0
- package/dist/storage/factory.d.ts +51 -0
- package/dist/storage/factory.d.ts.map +1 -0
- package/dist/storage/factory.js +154 -0
- package/dist/storage/factory.js.map +1 -0
- package/dist/storage/gcp-bucket-provider.d.ts +59 -0
- package/dist/storage/gcp-bucket-provider.d.ts.map +1 -0
- package/dist/storage/gcp-bucket-provider.js +275 -0
- package/dist/storage/gcp-bucket-provider.js.map +1 -0
- package/dist/storage/index.d.ts +33 -0
- package/dist/storage/index.d.ts.map +1 -0
- package/dist/storage/index.js +37 -0
- package/dist/storage/index.js.map +1 -0
- package/dist/storage/local-provider.d.ts +36 -0
- package/dist/storage/local-provider.d.ts.map +1 -0
- package/dist/storage/local-provider.js +219 -0
- package/dist/storage/local-provider.js.map +1 -0
- package/dist/storage/provider.d.ts +137 -0
- package/dist/storage/provider.d.ts.map +1 -0
- package/dist/storage/provider.js +136 -0
- package/dist/storage/provider.js.map +1 -0
- package/dist/storage/types.d.ts +78 -0
- package/dist/storage/types.d.ts.map +1 -0
- package/dist/storage/types.js +14 -0
- package/dist/storage/types.js.map +1 -0
- package/dist/utils/orchestration-logger.d.ts +36 -0
- package/dist/utils/orchestration-logger.d.ts.map +1 -0
- package/dist/utils/orchestration-logger.js +224 -0
- package/dist/utils/orchestration-logger.js.map +1 -0
- package/jiva-new-demo.gif +0 -0
- package/package.json +30 -2
- package/.fluen/cache/state.json +0 -7
- package/actions/action_registry.py +0 -75
- package/actions/python_coder.py +0 -470
- package/api/main.py +0 -269
- package/downloaded_image.avif +0 -0
- package/downloads/snipping_tool.avif +0 -0
- package/image.avif +0 -0
- package/ms_image.avif +0 -0
- package/screenshot.png +0 -0
- package/snipping_tool.avif +0 -0
- package/tmp_image.avif +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dual-agent.js","sourceRoot":"","sources":["../../src/core/dual-agent.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"dual-agent.js","sourceRoot":"","sources":["../../src/core/dual-agent.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAOH,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AA0B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estrator.js';
|
|
13
13
|
import { WorkspaceManager } from './workspace.js';
|
|
14
|
+
import { PersonaManager } from '../personas/persona-manager.js';
|
|
14
15
|
import { Message } from '../models/base.js';
|
|
15
16
|
export interface ManagerTask {
|
|
16
17
|
userRequest: string;
|
|
@@ -28,8 +29,9 @@ export interface ManagerDecision {
|
|
|
28
29
|
export declare class ManagerAgent {
|
|
29
30
|
private orchestrator;
|
|
30
31
|
private workspace;
|
|
32
|
+
private personaManager?;
|
|
31
33
|
private conversationHistory;
|
|
32
|
-
constructor(orchestrator: ModelOrchestrator, workspace: WorkspaceManager);
|
|
34
|
+
constructor(orchestrator: ModelOrchestrator, workspace: WorkspaceManager, personaManager?: PersonaManager);
|
|
33
35
|
private initializeSystemPrompt;
|
|
34
36
|
/**
|
|
35
37
|
* Create a plan for handling the user's request
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"manager-agent.d.ts","sourceRoot":"","sources":["../../src/core/manager-agent.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"manager-agent.d.ts","sourceRoot":"","sources":["../../src/core/manager-agent.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAChE,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAI5C,MAAM,WAAW,WAAW;IAC1B,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,WAAW;IAC1B,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,eAAe;IAC9B,UAAU,EAAE,OAAO,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,qBAAa,YAAY;IACvB,OAAO,CAAC,YAAY,CAAoB;IACxC,OAAO,CAAC,SAAS,CAAmB;IACpC,OAAO,CAAC,cAAc,CAAC,CAAiB;IACxC,OAAO,CAAC,mBAAmB,CAAiB;gBAEhC,YAAY,EAAE,iBAAiB,EAAE,SAAS,EAAE,gBAAgB,EAAE,cAAc,CAAC,EAAE,cAAc;IAOzG,OAAO,CAAC,sBAAsB;IA6C9B;;OAEG;IACG,UAAU,CAAC,IAAI,EAAE,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;IAmFzD;;OAEG;IACG,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC;IAoDpF;;OAEG;IACG,kBAAkB,CAAC,UAAU,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC;IAgC5F,OAAO,CAAC,cAAc;IAMtB,sBAAsB,IAAI,OAAO,EAAE;IAInC,iBAAiB;CAIlB"}
|
|
@@ -10,36 +10,50 @@
|
|
|
10
10
|
* - Format final response
|
|
11
11
|
*/
|
|
12
12
|
import { logger } from '../utils/logger.js';
|
|
13
|
+
import { orchestrationLogger } from '../utils/orchestration-logger.js';
|
|
13
14
|
export class ManagerAgent {
|
|
14
15
|
orchestrator;
|
|
15
16
|
workspace;
|
|
17
|
+
personaManager;
|
|
16
18
|
conversationHistory = [];
|
|
17
|
-
constructor(orchestrator, workspace) {
|
|
19
|
+
constructor(orchestrator, workspace, personaManager) {
|
|
18
20
|
this.orchestrator = orchestrator;
|
|
19
21
|
this.workspace = workspace;
|
|
22
|
+
this.personaManager = personaManager;
|
|
20
23
|
this.initializeSystemPrompt();
|
|
21
24
|
}
|
|
22
25
|
initializeSystemPrompt() {
|
|
23
26
|
const directivePrompt = this.workspace.getDirectivePrompt();
|
|
27
|
+
const personaPrompt = this.personaManager?.getSystemPromptAddition() || '';
|
|
24
28
|
let systemContent = `You are the Manager Agent in a two-agent system.
|
|
25
29
|
|
|
26
30
|
ROLE:
|
|
27
|
-
You plan and coordinate
|
|
31
|
+
You plan and coordinate at a HIGH LEVEL. You do NOT execute tools or create detailed implementation plans.
|
|
28
32
|
|
|
29
33
|
WORKFLOW:
|
|
30
34
|
1. Understand the user's request
|
|
31
|
-
2.
|
|
32
|
-
3. Delegate subtasks to the Worker agent
|
|
33
|
-
4. Review Worker's results
|
|
35
|
+
2. Create a MINIMAL, high-level plan (typically 1-3 subtasks)
|
|
36
|
+
3. Delegate subtasks to the capable Worker agent
|
|
37
|
+
4. Review Worker's final results
|
|
34
38
|
5. Decide if task is complete or more work needed
|
|
35
39
|
6. Format final response for user
|
|
36
40
|
|
|
41
|
+
CRITICAL PRINCIPLES:
|
|
42
|
+
- LESS IS MORE: Fewer, broader subtasks are better than many micro-tasks
|
|
43
|
+
- TRUST THE WORKER: Worker is highly capable and handles implementation details
|
|
44
|
+
- AVOID MICRO-MANAGEMENT: Don't break down tasks into tiny steps
|
|
45
|
+
- CODE TASKS = 1-2 SUBTASKS: File creation, editing, generation should be single subtasks
|
|
46
|
+
- INFO TASKS = 1-2 SUBTASKS: Reading, analyzing, listing should be single subtasks
|
|
47
|
+
|
|
37
48
|
IMPORTANT:
|
|
38
|
-
- Think
|
|
39
|
-
- Be specific in your subtask instructions
|
|
49
|
+
- Think strategically, not tactically
|
|
50
|
+
- Be specific but high-level in your subtask instructions
|
|
40
51
|
- Review Worker results critically
|
|
41
52
|
- Only mark complete when user's request is fully satisfied
|
|
42
53
|
`;
|
|
54
|
+
if (personaPrompt) {
|
|
55
|
+
systemContent += `\n${personaPrompt}\n`;
|
|
56
|
+
}
|
|
43
57
|
if (directivePrompt) {
|
|
44
58
|
systemContent += `\n${directivePrompt}`;
|
|
45
59
|
}
|
|
@@ -53,19 +67,52 @@ IMPORTANT:
|
|
|
53
67
|
*/
|
|
54
68
|
async createPlan(task) {
|
|
55
69
|
logger.info('[Manager] Creating plan...');
|
|
70
|
+
orchestrationLogger.logManagerCreatePlan(task.userRequest, task.context || '');
|
|
56
71
|
const planPrompt = `User Request: ${task.userRequest}
|
|
57
72
|
${task.context ? `\nContext: ${task.context}` : ''}
|
|
58
73
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
74
|
+
Create a HIGH-LEVEL plan with MINIMAL subtasks. Follow these guidelines:
|
|
75
|
+
|
|
76
|
+
CRITICAL - Subtask Granularity:
|
|
77
|
+
- Keep subtasks at a HIGH LEVEL - let Worker handle implementation details
|
|
78
|
+
- For code generation/file operations: 1-3 subtasks maximum
|
|
79
|
+
- For information gathering: 1-2 subtasks maximum
|
|
80
|
+
- Only create separate subtasks when they are truly independent or sequential dependencies exist
|
|
81
|
+
|
|
82
|
+
Examples:
|
|
83
|
+
BAD (too granular):
|
|
84
|
+
- Ask user for requirements
|
|
85
|
+
- Create HTML structure
|
|
86
|
+
- Add CSS styling
|
|
87
|
+
- Add JavaScript logic
|
|
88
|
+
- Test in browser
|
|
89
|
+
(This should be 1 subtask: "Create calculator app as calc.html")
|
|
90
|
+
|
|
91
|
+
GOOD (appropriate level):
|
|
92
|
+
- Create the calculator application
|
|
93
|
+
- Refine based on user feedback (if needed)
|
|
94
|
+
|
|
95
|
+
BAD (too granular):
|
|
96
|
+
- List directory contents
|
|
97
|
+
- Read package.json
|
|
98
|
+
- Identify dependencies
|
|
99
|
+
- Format output
|
|
100
|
+
(This should be 1 subtask: "List and analyze project dependencies")
|
|
101
|
+
|
|
102
|
+
GOOD (appropriate level):
|
|
103
|
+
- Analyze project dependencies and structure
|
|
104
|
+
|
|
105
|
+
Guidelines:
|
|
106
|
+
- Don't create subtasks for clarifying requirements - Worker can ask if needed
|
|
107
|
+
- Don't create subtasks for implementation details (styling, specific code structure)
|
|
108
|
+
- Don't create separate "test" or "verify" subtasks - Worker does this naturally
|
|
109
|
+
- Trust Worker to handle file operations, error checking, and iteration
|
|
63
110
|
|
|
64
111
|
Respond in this format:
|
|
65
|
-
REASONING: <your
|
|
112
|
+
REASONING: <brief explanation of your high-level approach>
|
|
66
113
|
SUBTASKS:
|
|
67
114
|
- <subtask 1>
|
|
68
|
-
- <subtask 2>
|
|
115
|
+
- <subtask 2> (only if truly necessary)
|
|
69
116
|
...`;
|
|
70
117
|
this.conversationHistory.push({
|
|
71
118
|
role: 'user',
|
|
@@ -89,6 +136,7 @@ SUBTASKS:
|
|
|
89
136
|
logger.info(`[Manager] Reasoning: ${reasoning}`);
|
|
90
137
|
logger.info(`[Manager] Plan: ${subtasks.length} subtasks`);
|
|
91
138
|
subtasks.forEach((task, i) => logger.info(` ${i + 1}. ${task}`));
|
|
139
|
+
orchestrationLogger.logManagerPlanCreated(subtasks, reasoning);
|
|
92
140
|
return { subtasks, reasoning };
|
|
93
141
|
}
|
|
94
142
|
/**
|
|
@@ -96,6 +144,7 @@ SUBTASKS:
|
|
|
96
144
|
*/
|
|
97
145
|
async reviewResults(subtask, workerResult) {
|
|
98
146
|
logger.info(`[Manager] Reviewing: "${subtask}"`);
|
|
147
|
+
orchestrationLogger.logManagerReview(subtask, workerResult);
|
|
99
148
|
const reviewPrompt = `The Worker completed this subtask:
|
|
100
149
|
Subtask: ${subtask}
|
|
101
150
|
|
|
@@ -128,8 +177,10 @@ NEXT_ACTION: <what to do next, if CONTINUE>`;
|
|
|
128
177
|
const nextAction = this.extractSection(response.content, 'NEXT_ACTION');
|
|
129
178
|
logger.info(`[Manager] Review: ${reasoning}`);
|
|
130
179
|
logger.info(`[Manager] Decision: ${decision}`);
|
|
180
|
+
const isComplete = decision.toUpperCase().includes('COMPLETE');
|
|
181
|
+
orchestrationLogger.logManagerDecision(isComplete, reasoning, nextAction || undefined);
|
|
131
182
|
return {
|
|
132
|
-
isComplete
|
|
183
|
+
isComplete,
|
|
133
184
|
reasoning,
|
|
134
185
|
nextAction: nextAction || undefined,
|
|
135
186
|
};
|
|
@@ -139,6 +190,7 @@ NEXT_ACTION: <what to do next, if CONTINUE>`;
|
|
|
139
190
|
*/
|
|
140
191
|
async synthesizeResponse(allResults) {
|
|
141
192
|
logger.info('[Manager] Synthesizing final response...');
|
|
193
|
+
orchestrationLogger.logManagerSynthesize(allResults.length);
|
|
142
194
|
const synthesisPrompt = `Based on all the work completed, create a final response for the user.
|
|
143
195
|
|
|
144
196
|
Completed Work:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"manager-agent.js","sourceRoot":"","sources":["../../src/core/manager-agent.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;
|
|
1
|
+
{"version":3,"file":"manager-agent.js","sourceRoot":"","sources":["../../src/core/manager-agent.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAMH,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AAkBvE,MAAM,OAAO,YAAY;IACf,YAAY,CAAoB;IAChC,SAAS,CAAmB;IAC5B,cAAc,CAAkB;IAChC,mBAAmB,GAAc,EAAE,CAAC;IAE5C,YAAY,YAA+B,EAAE,SAA2B,EAAE,cAA+B;QACvG,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;QACrC,IAAI,CAAC,sBAAsB,EAAE,CAAC;IAChC,CAAC;IAEO,sBAAsB;QAC5B,MAAM,eAAe,GAAG,IAAI,CAAC,SAAS,CAAC,kBAAkB,EAAE,CAAC;QAC5D,MAAM,aAAa,GAAG,IAA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from '../mcp/server-manager.js';
|
|
12
12
|
import { WorkspaceManager } from './workspace.js';
|
|
13
|
+
import { PersonaManager } from '../personas/persona-manager.js';
|
|
14
|
+
import { AgentSpawner } from './agent-spawner.js';
|
|
13
15
|
export interface WorkerSubtask {
|
|
14
16
|
instruction: string;
|
|
15
17
|
context?: string;
|
|
@@ -24,12 +26,24 @@ export declare class WorkerAgent {
|
|
|
24
26
|
private orchestrator;
|
|
25
27
|
private mcpManager;
|
|
26
28
|
private workspace;
|
|
29
|
+
private personaManager?;
|
|
30
|
+
private agentSpawner?;
|
|
27
31
|
private maxIterations;
|
|
28
|
-
|
|
32
|
+
private contextMemory;
|
|
33
|
+
constructor(orchestrator: ModelOrchestrator, mcpManager: MCPServerManager, workspace: WorkspaceManager, maxIterations?: number, personaManager?: PersonaManager);
|
|
34
|
+
/**
|
|
35
|
+
* Set agent spawner (enables sub-agent spawning)
|
|
36
|
+
*/
|
|
37
|
+
setAgentSpawner(spawner: AgentSpawner): void;
|
|
29
38
|
/**
|
|
30
39
|
* Execute a subtask assigned by Manager
|
|
31
40
|
*/
|
|
32
41
|
executeSubtask(subtask: WorkerSubtask): Promise<WorkerResult>;
|
|
33
42
|
private extractReasoning;
|
|
43
|
+
/**
|
|
44
|
+
* Determine if we should prompt Worker to check for completion
|
|
45
|
+
* This helps prevent over-iteration by asking Worker to confirm task is done
|
|
46
|
+
*/
|
|
47
|
+
private shouldPromptForCompletion;
|
|
34
48
|
}
|
|
35
49
|
//# sourceMappingURL=worker-agent.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker-agent.d.ts","sourceRoot":"","sources":["../../src/core/worker-agent.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;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|
|
@@ -9,27 +9,49 @@
|
|
|
9
9
|
*/
|
|
10
10
|
import { formatToolResult } from '../models/harmony.js';
|
|
11
11
|
import { logger } from '../utils/logger.js';
|
|
12
|
+
import { orchestrationLogger } from '../utils/orchestration-logger.js';
|
|
12
13
|
export class WorkerAgent {
|
|
13
14
|
orchestrator;
|
|
14
15
|
mcpManager;
|
|
15
16
|
workspace;
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
personaManager;
|
|
18
|
+
agentSpawner;
|
|
19
|
+
maxIterations;
|
|
20
|
+
contextMemory;
|
|
21
|
+
constructor(orchestrator, mcpManager, workspace, maxIterations = 5, personaManager) {
|
|
18
22
|
this.orchestrator = orchestrator;
|
|
19
23
|
this.mcpManager = mcpManager;
|
|
20
24
|
this.workspace = workspace;
|
|
25
|
+
this.personaManager = personaManager;
|
|
26
|
+
this.maxIterations = maxIterations;
|
|
27
|
+
this.contextMemory = {
|
|
28
|
+
recentFileReads: new Map(),
|
|
29
|
+
filesJustModified: new Set(),
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Set agent spawner (enables sub-agent spawning)
|
|
34
|
+
*/
|
|
35
|
+
setAgentSpawner(spawner) {
|
|
36
|
+
this.agentSpawner = spawner;
|
|
21
37
|
}
|
|
22
38
|
/**
|
|
23
39
|
* Execute a subtask assigned by Manager
|
|
24
40
|
*/
|
|
25
41
|
async executeSubtask(subtask) {
|
|
26
42
|
logger.info(`[Worker] Starting: "${subtask.instruction}"`);
|
|
43
|
+
orchestrationLogger.logWorkerStart(subtask.instruction, subtask.context || '');
|
|
44
|
+
// Reset context memory for new subtask
|
|
45
|
+
this.contextMemory = {
|
|
46
|
+
recentFileReads: new Map(),
|
|
47
|
+
filesJustModified: new Set(),
|
|
48
|
+
};
|
|
27
49
|
const conversationHistory = [];
|
|
28
50
|
const toolsUsed = [];
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
51
|
+
let iterationCount = 0;
|
|
52
|
+
// Build system prompt for Worker
|
|
53
|
+
const personaPrompt = this.personaManager?.getSystemPromptAddition() || '';
|
|
54
|
+
let systemContent = `You are the Worker Agent in a two-agent system.
|
|
33
55
|
|
|
34
56
|
ROLE:
|
|
35
57
|
You execute specific subtasks using available tools. You do NOT plan or make high-level decisions.
|
|
@@ -61,8 +83,42 @@ IMPORTANT:
|
|
|
61
83
|
- Explain what you did and what you found
|
|
62
84
|
- If you can't complete the task, explain why clearly
|
|
63
85
|
|
|
64
|
-
|
|
86
|
+
CRITICAL - Avoid Repetitive Actions:
|
|
87
|
+
- NEVER call the same tool with the same arguments more than once
|
|
88
|
+
- If a tool succeeds, move on to the next step - do NOT repeat it
|
|
89
|
+
- For browser tasks: open tab ONCE, then navigate ONCE to the URL
|
|
90
|
+
- If you've already created/opened something, don't create/open it again
|
|
91
|
+
|
|
92
|
+
BROWSER TASKS:
|
|
93
|
+
- To open a URL: First use playwright__browser_tabs to create a new tab, THEN use playwright__browser_navigate to go to the URL
|
|
94
|
+
- Both steps are required - creating a tab alone does NOT navigate to a URL
|
|
95
|
+
- After navigation succeeds, the task is COMPLETE - stop and report success
|
|
96
|
+
|
|
97
|
+
Available tools: ${this.mcpManager.getClient().getAllTools().map(t => t.name).join(', ')}${this.agentSpawner && this.agentSpawner.canSpawnMore() ? ', spawn_agent' : ''}`;
|
|
98
|
+
// Add spawn_agent documentation only if depth allows spawning
|
|
99
|
+
if (this.agentSpawner && this.agentSpawner.canSpawnMore()) {
|
|
100
|
+
const availablePersonas = this.agentSpawner.getAvailablePersonas();
|
|
101
|
+
systemContent += `\n\nAGENT SPAWNING:
|
|
102
|
+
- You can spawn sub-agents with specific personas to delegate complex tasks
|
|
103
|
+
- Use spawn_agent tool when you need specialized expertise or parallel work
|
|
104
|
+
- Tool: spawn_agent
|
|
105
|
+
- Parameters:
|
|
106
|
+
* persona (required): Persona name - ${availablePersonas.join(', ')}
|
|
107
|
+
* task (required): Specific task for the sub-agent
|
|
108
|
+
* context (optional): Additional context or background info
|
|
109
|
+
- Example: spawn_agent({ persona: "code-reviewer", task: "Review the authentication code in src/auth/", context: "Focus on security issues" })
|
|
110
|
+
- The sub-agent will complete the task and return results to you`;
|
|
111
|
+
}
|
|
112
|
+
if (personaPrompt) {
|
|
113
|
+
systemContent += `\n\n${personaPrompt}`;
|
|
114
|
+
}
|
|
115
|
+
// System prompt for Worker
|
|
116
|
+
// Use 'developer' role for Harmony format compatibility (will be converted to 'system' by model)
|
|
117
|
+
conversationHistory.push({
|
|
118
|
+
role: 'developer', // Harmony format requires 'developer' for tool injection
|
|
119
|
+
content: systemContent,
|
|
65
120
|
});
|
|
121
|
+
logger.debug(` [Worker] System prompt includes: Available tools: ${this.mcpManager.getClient().getAllTools().map(t => t.name).join(', ')}`);
|
|
66
122
|
// Add subtask instruction
|
|
67
123
|
conversationHistory.push({
|
|
68
124
|
role: 'user',
|
|
@@ -76,8 +132,48 @@ Please complete this subtask and report your findings.`,
|
|
|
76
132
|
let pendingImages = [];
|
|
77
133
|
// Worker execution loop
|
|
78
134
|
for (let iteration = 0; iteration < this.maxIterations; iteration++) {
|
|
135
|
+
iterationCount = iteration + 1;
|
|
79
136
|
logger.debug(` [Worker] Iteration ${iteration + 1}/${this.maxIterations}`);
|
|
80
|
-
|
|
137
|
+
orchestrationLogger.logWorkerIteration(iteration + 1, this.maxIterations);
|
|
138
|
+
const mcpTools = this.mcpManager.getClient().getAllTools();
|
|
139
|
+
// Add spawn_agent tool only if depth limit allows spawning
|
|
140
|
+
const tools = [...mcpTools];
|
|
141
|
+
if (this.agentSpawner && this.agentSpawner.canSpawnMore()) {
|
|
142
|
+
const spawnAgentTool = {
|
|
143
|
+
name: 'spawn_agent',
|
|
144
|
+
description: 'Spawn a sub-agent with a specific persona to delegate complex tasks',
|
|
145
|
+
parameters: {
|
|
146
|
+
type: 'object',
|
|
147
|
+
properties: {
|
|
148
|
+
persona: {
|
|
149
|
+
type: 'string',
|
|
150
|
+
description: 'The persona name for the sub-agent (e.g., "code-reviewer", "developer", "tester")',
|
|
151
|
+
},
|
|
152
|
+
task: {
|
|
153
|
+
type: 'string',
|
|
154
|
+
description: 'Specific task for the sub-agent to complete',
|
|
155
|
+
},
|
|
156
|
+
context: {
|
|
157
|
+
type: 'string',
|
|
158
|
+
description: 'Optional additional context or background information',
|
|
159
|
+
},
|
|
160
|
+
maxIterations: {
|
|
161
|
+
type: 'number',
|
|
162
|
+
description: 'Optional maximum iterations for the sub-agent (default: 10)',
|
|
163
|
+
},
|
|
164
|
+
},
|
|
165
|
+
required: ['persona', 'task'],
|
|
166
|
+
},
|
|
167
|
+
};
|
|
168
|
+
tools.push(spawnAgentTool);
|
|
169
|
+
}
|
|
170
|
+
logger.info(` [Worker] Tools available: ${tools.length}`);
|
|
171
|
+
if (tools.length > 0) {
|
|
172
|
+
logger.debug(` [Worker] Tool names: ${tools.map(t => t.name).join(', ')}`);
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
logger.warn(` [Worker] WARNING: No tools available! MCP servers may not be connected.`);
|
|
176
|
+
}
|
|
81
177
|
let response;
|
|
82
178
|
try {
|
|
83
179
|
response = await this.orchestrator.chat({
|
|
@@ -111,19 +207,75 @@ Please complete this subtask and report your findings.`,
|
|
|
111
207
|
// Check for tool calls
|
|
112
208
|
if (response.toolCalls && response.toolCalls.length > 0) {
|
|
113
209
|
logger.info(` [Worker] Using ${response.toolCalls.length} tool(s)`);
|
|
210
|
+
// Detect repetitive tool calls BEFORE executing
|
|
211
|
+
const proposedTools = response.toolCalls.map(tc => {
|
|
212
|
+
const args = JSON.parse(tc.function.arguments);
|
|
213
|
+
return `${tc.function.name}:${JSON.stringify(args)}`;
|
|
214
|
+
});
|
|
215
|
+
// Check if we're about to repeat the same tool call
|
|
216
|
+
const lastToolCalls = toolsUsed.slice(-2);
|
|
217
|
+
const isRepetitive = proposedTools.some(proposed => {
|
|
218
|
+
const toolName = proposed.split(':')[0];
|
|
219
|
+
return lastToolCalls.filter(t => t === toolName).length >= 2;
|
|
220
|
+
});
|
|
221
|
+
if (isRepetitive && iteration >= 2) {
|
|
222
|
+
logger.warn(` [Worker] Detected repetitive tool usage - interrupting loop`);
|
|
223
|
+
conversationHistory.push({
|
|
224
|
+
role: 'user',
|
|
225
|
+
content: `STOP: You are repeating the same action multiple times. This tool has already succeeded.
|
|
226
|
+
|
|
227
|
+
For browser tasks:
|
|
228
|
+
1. You already created a new tab - do NOT create another one
|
|
229
|
+
2. Now use playwright__browser_navigate to go to the actual URL
|
|
230
|
+
3. If navigation is already done, the task is COMPLETE - just provide your summary
|
|
231
|
+
|
|
232
|
+
Do NOT call the same tool again. Either move to the NEXT required step, or if the task is complete, provide your final summary WITHOUT any tool calls.`,
|
|
233
|
+
});
|
|
234
|
+
continue; // Skip executing the repetitive tools, let model reconsider
|
|
235
|
+
}
|
|
114
236
|
for (const toolCall of response.toolCalls) {
|
|
115
237
|
const toolName = toolCall.function.name;
|
|
116
238
|
logger.info(` [Worker] Tool: ${toolName}`);
|
|
117
239
|
try {
|
|
118
240
|
const args = JSON.parse(toolCall.function.arguments);
|
|
241
|
+
orchestrationLogger.logWorkerToolCall(toolName, args);
|
|
242
|
+
// Handle spawn_agent specially
|
|
243
|
+
if (toolName === 'spawn_agent') {
|
|
244
|
+
if (!this.agentSpawner) {
|
|
245
|
+
throw new Error('Agent spawning is not enabled');
|
|
246
|
+
}
|
|
247
|
+
logger.info(` [Worker] Spawning sub-agent with persona: ${args.persona}`);
|
|
248
|
+
const spawnResult = await this.agentSpawner.spawnAgent({
|
|
249
|
+
persona: args.persona,
|
|
250
|
+
task: args.task,
|
|
251
|
+
context: args.context,
|
|
252
|
+
maxIterations: args.maxIterations,
|
|
253
|
+
});
|
|
254
|
+
toolsUsed.push(toolName);
|
|
255
|
+
const resultText = `Sub-agent spawned with persona '${spawnResult.persona}' completed the task.
|
|
256
|
+
|
|
257
|
+
RESULT:
|
|
258
|
+
${spawnResult.result}
|
|
259
|
+
|
|
260
|
+
Iterations: ${spawnResult.iterations}
|
|
261
|
+
Tools used: ${spawnResult.toolsUsed.join(', ')}`;
|
|
262
|
+
orchestrationLogger.logWorkerToolResult(toolName, true, false);
|
|
263
|
+
const toolMessage = formatToolResult(toolCall.id, toolName, resultText);
|
|
264
|
+
conversationHistory.push(toolMessage);
|
|
265
|
+
logger.success(` ✓ [Worker] Sub-agent completed task`);
|
|
266
|
+
continue;
|
|
267
|
+
}
|
|
268
|
+
// Regular MCP tool execution
|
|
119
269
|
const result = await this.mcpManager.getClient().executeTool(toolName, args);
|
|
120
270
|
toolsUsed.push(toolName);
|
|
121
271
|
// Check if tool returned images (multimodal support)
|
|
122
272
|
let toolResultText;
|
|
273
|
+
let hasImages = false;
|
|
123
274
|
if (typeof result === 'object' && result !== null && 'images' in result) {
|
|
124
275
|
const typedResult = result;
|
|
125
276
|
toolResultText = typedResult.text;
|
|
126
277
|
if (typedResult.images && typedResult.images.length > 0) {
|
|
278
|
+
hasImages = true;
|
|
127
279
|
logger.info(` [Worker] Tool returned ${typedResult.images.length} image(s), will attach to next model call`);
|
|
128
280
|
pendingImages.push(...typedResult.images);
|
|
129
281
|
}
|
|
@@ -131,12 +283,14 @@ Please complete this subtask and report your findings.`,
|
|
|
131
283
|
else {
|
|
132
284
|
toolResultText = typeof result === 'string' ? result : JSON.stringify(result);
|
|
133
285
|
}
|
|
286
|
+
orchestrationLogger.logWorkerToolResult(toolName, true, hasImages);
|
|
134
287
|
const toolMessage = formatToolResult(toolCall.id, toolName, toolResultText);
|
|
135
288
|
conversationHistory.push(toolMessage);
|
|
136
289
|
logger.debug(` ✓ [Worker] Tool ${toolName} completed`);
|
|
137
290
|
}
|
|
138
291
|
catch (error) {
|
|
139
292
|
logger.error(` ✗ [Worker] Tool ${toolName} failed:`, error);
|
|
293
|
+
orchestrationLogger.logWorkerToolResult(toolName, false, false);
|
|
140
294
|
conversationHistory.push({
|
|
141
295
|
role: 'tool',
|
|
142
296
|
name: toolName,
|
|
@@ -167,6 +321,16 @@ Please complete this subtask and report your findings.`,
|
|
|
167
321
|
conversationHistory.push(imageMessage);
|
|
168
322
|
pendingImages = []; // Clear for next iteration
|
|
169
323
|
}
|
|
324
|
+
// After processing tool calls, check if we should prompt for completion
|
|
325
|
+
// This helps Worker recognize when task is done instead of over-iterating
|
|
326
|
+
const shouldPromptCompletion = this.shouldPromptForCompletion(subtask.instruction, toolsUsed, iteration);
|
|
327
|
+
if (shouldPromptCompletion) {
|
|
328
|
+
logger.debug(` [Worker] Prompting for task completion check`);
|
|
329
|
+
conversationHistory.push({
|
|
330
|
+
role: 'user',
|
|
331
|
+
content: `You have successfully executed the required tools. Please confirm if the subtask is now complete and provide a summary of what was accomplished. If complete, do not call any more tools - just respond with your summary.`,
|
|
332
|
+
});
|
|
333
|
+
}
|
|
170
334
|
// Continue to process tool results
|
|
171
335
|
continue;
|
|
172
336
|
}
|
|
@@ -178,11 +342,36 @@ Please complete this subtask and report your findings.`,
|
|
|
178
342
|
break;
|
|
179
343
|
}
|
|
180
344
|
if (!finalResult) {
|
|
181
|
-
|
|
182
|
-
|
|
345
|
+
// Max iterations reached - but check if work was actually done successfully
|
|
346
|
+
const hasSuccessfulTools = toolsUsed.length > 0;
|
|
347
|
+
const hasToolFailures = conversationHistory.some(msg => {
|
|
348
|
+
if (msg.role === 'tool' && msg.content) {
|
|
349
|
+
const content = typeof msg.content === 'string' ? msg.content : JSON.stringify(msg.content);
|
|
350
|
+
return content.includes('Error:');
|
|
351
|
+
}
|
|
352
|
+
return false;
|
|
353
|
+
});
|
|
354
|
+
if (hasSuccessfulTools && !hasToolFailures) {
|
|
355
|
+
// Tools executed successfully, just model didn't stop naturally
|
|
356
|
+
finalResult = `Task work completed (${toolsUsed.length} operations performed). Max iterations reached but all tool operations succeeded.`;
|
|
357
|
+
logger.info(`[Worker] Max iterations reached, but ${toolsUsed.length} tools executed successfully`);
|
|
358
|
+
}
|
|
359
|
+
else if (hasToolFailures) {
|
|
360
|
+
finalResult = 'Subtask encountered errors and could not be completed within iteration limit.';
|
|
361
|
+
logger.warn(`[Worker] Max iterations reached with tool failures`);
|
|
362
|
+
}
|
|
363
|
+
else {
|
|
364
|
+
finalResult = 'Subtask could not be completed within iteration limit.';
|
|
365
|
+
logger.warn(`[Worker] Max iterations reached with no work done`);
|
|
366
|
+
}
|
|
183
367
|
}
|
|
368
|
+
// Determine success: true if we got a result and it doesn't indicate failure
|
|
369
|
+
const success = !!finalResult &&
|
|
370
|
+
!finalResult.includes('could not be completed') &&
|
|
371
|
+
!finalResult.includes('encountered errors');
|
|
372
|
+
orchestrationLogger.logWorkerComplete(success, toolsUsed, iterationCount);
|
|
184
373
|
return {
|
|
185
|
-
success
|
|
374
|
+
success,
|
|
186
375
|
result: finalResult,
|
|
187
376
|
toolsUsed,
|
|
188
377
|
reasoning: reasoning || 'Task executed',
|
|
@@ -193,5 +382,49 @@ Please complete this subtask and report your findings.`,
|
|
|
193
382
|
const reasoningMatch = content.match(/(?:Reasoning|Analysis|Approach):?\s*([^\n]+)/i);
|
|
194
383
|
return reasoningMatch ? reasoningMatch[1].trim() : '';
|
|
195
384
|
}
|
|
385
|
+
/**
|
|
386
|
+
* Determine if we should prompt Worker to check for completion
|
|
387
|
+
* This helps prevent over-iteration by asking Worker to confirm task is done
|
|
388
|
+
*/
|
|
389
|
+
shouldPromptForCompletion(instruction, toolsUsed, currentIteration) {
|
|
390
|
+
// Don't prompt on first iteration - let Worker do initial work
|
|
391
|
+
if (currentIteration === 0) {
|
|
392
|
+
return false;
|
|
393
|
+
}
|
|
394
|
+
// Immediate prompt after browser navigation - that's usually the end of the task
|
|
395
|
+
const hasBrowserNavigation = toolsUsed.some(tool => tool.includes('browser_navigate'));
|
|
396
|
+
if (hasBrowserNavigation) {
|
|
397
|
+
return true;
|
|
398
|
+
}
|
|
399
|
+
// Detect repetitive tool usage - sign of stuck loop
|
|
400
|
+
const lastThreeTools = toolsUsed.slice(-3);
|
|
401
|
+
if (lastThreeTools.length === 3 &&
|
|
402
|
+
lastThreeTools[0] === lastThreeTools[1] &&
|
|
403
|
+
lastThreeTools[1] === lastThreeTools[2]) {
|
|
404
|
+
return true; // Same tool called 3 times in a row - prompt for completion
|
|
405
|
+
}
|
|
406
|
+
// Don't prompt too frequently - only every 2 iterations after first
|
|
407
|
+
if (currentIteration % 2 !== 0) {
|
|
408
|
+
return false;
|
|
409
|
+
}
|
|
410
|
+
// Check if this looks like a completion-oriented task
|
|
411
|
+
const completionIndicators = [
|
|
412
|
+
'create', 'write', 'generate', 'build', 'make',
|
|
413
|
+
'read', 'list', 'find', 'search', 'get',
|
|
414
|
+
'update', 'modify', 'edit', 'change',
|
|
415
|
+
'delete', 'remove', 'open', 'navigate', 'browse',
|
|
416
|
+
];
|
|
417
|
+
const instructionLower = instruction.toLowerCase();
|
|
418
|
+
const hasCompletionIndicator = completionIndicators.some(indicator => instructionLower.includes(indicator));
|
|
419
|
+
// Prompt if we've seen successful file/content or browser operations
|
|
420
|
+
const hasSignificantOperations = toolsUsed.some(tool => tool.includes('write') ||
|
|
421
|
+
tool.includes('create') ||
|
|
422
|
+
tool.includes('edit') ||
|
|
423
|
+
tool.includes('read') ||
|
|
424
|
+
tool.includes('browser') ||
|
|
425
|
+
tool.includes('navigate'));
|
|
426
|
+
// Prompt if we have completion indicators and significant operations
|
|
427
|
+
return hasCompletionIndicator && hasSignificantOperations && toolsUsed.length >= 2;
|
|
428
|
+
}
|
|
196
429
|
}
|
|
197
430
|
//# sourceMappingURL=worker-agent.js.map
|