@xaidenlabs/uso 1.2.1 → 1.2.2
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/package.json +1 -1
- package/packages/uso-core/dist/cjs/agent/brain.d.ts.map +1 -1
- package/packages/uso-core/dist/cjs/agent/brain.js +25 -71
- package/packages/uso-core/dist/cjs/agent/brain.js.map +1 -1
- package/packages/uso-core/dist/cjs/agent/prompts.d.ts +1 -1
- package/packages/uso-core/dist/cjs/agent/prompts.d.ts.map +1 -1
- package/packages/uso-core/dist/cjs/agent/prompts.js +25 -20
- package/packages/uso-core/dist/cjs/agent/prompts.js.map +1 -1
- package/packages/uso-core/dist/esm/agent/brain.d.ts.map +1 -1
- package/packages/uso-core/dist/esm/agent/brain.js +25 -71
- package/packages/uso-core/dist/esm/agent/brain.js.map +1 -1
- package/packages/uso-core/dist/esm/agent/prompts.d.ts +1 -1
- package/packages/uso-core/dist/esm/agent/prompts.d.ts.map +1 -1
- package/packages/uso-core/dist/esm/agent/prompts.js +25 -20
- package/packages/uso-core/dist/esm/agent/prompts.js.map +1 -1
- package/packages/uso-core/src/agent/brain.ts +30 -79
- package/packages/uso-core/src/agent/prompts.ts +26 -19
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"brain.d.ts","sourceRoot":"","sources":["../../../src/agent/brain.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAA2B,MAAM,aAAa,CAAC;AACvE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAU1C,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,WAAW,GAAG,eAAe,GAAG,aAAa,CAAC;IACpD,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EA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WAAW,EACnB,KAAK,EAAE,UAAU,GAChB,OAAO,CAAC;QAAE,WAAW,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,OAAO,CAAC;QAAC,KAAK,EAAE,UAAU,CAAA;KAAE,CAAC;IA6DxE;;OAEG;IACH,OAAO,CAAC,aAAa;IAoDrB;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAgDzB,OAAO,CAAC,cAAc;CA6BvB"}
|
|
@@ -30,34 +30,8 @@ class AgentBrain {
|
|
|
30
30
|
temperature: 0.1,
|
|
31
31
|
maxTokens: 2048,
|
|
32
32
|
};
|
|
33
|
-
//
|
|
34
|
-
|
|
35
|
-
toolDefs.push({
|
|
36
|
-
name: "TASK_COMPLETE",
|
|
37
|
-
description: "Mark the user's goal as complete.",
|
|
38
|
-
parameters: {
|
|
39
|
-
type: "object",
|
|
40
|
-
properties: {
|
|
41
|
-
summary: { type: "string", description: "Summary of what was accomplished." }
|
|
42
|
-
},
|
|
43
|
-
required: ["summary"],
|
|
44
|
-
}
|
|
45
|
-
}, {
|
|
46
|
-
name: "TASK_FAILED",
|
|
47
|
-
description: "Mark the user's goal as failed due to inability to accomplish it.",
|
|
48
|
-
parameters: {
|
|
49
|
-
type: "object",
|
|
50
|
-
properties: {
|
|
51
|
-
reason: { type: "string", description: "Reason why the goal could not be completed." }
|
|
52
|
-
},
|
|
53
|
-
required: ["reason"],
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
if (this.llm.provider === "openai" ||
|
|
57
|
-
this.llm.provider === "github" ||
|
|
58
|
-
this.llm.provider === "gemini") {
|
|
59
|
-
options.tools = toolDefs;
|
|
60
|
-
}
|
|
33
|
+
// Removed native tool calling logic because GitHub Models' gpt-4o-mini often omits tool calls.
|
|
34
|
+
// We will rely entirely on the text-based THOUGHT/ACTION JSON format.
|
|
61
35
|
let response;
|
|
62
36
|
try {
|
|
63
37
|
response = await this.llm.chat(messages, options);
|
|
@@ -77,44 +51,6 @@ class AgentBrain {
|
|
|
77
51
|
state: newState,
|
|
78
52
|
};
|
|
79
53
|
}
|
|
80
|
-
// Handle native function calling responses
|
|
81
|
-
if (response.toolCalls && response.toolCalls.length > 0) {
|
|
82
|
-
const tc = response.toolCalls[0]; // Process one tool call at a time
|
|
83
|
-
const thought = response.content || `Calling ${tc.name}`;
|
|
84
|
-
const newState = (0, state_1.appendHistory)(state, {
|
|
85
|
-
role: "thought",
|
|
86
|
-
content: thought,
|
|
87
|
-
});
|
|
88
|
-
if (tc.name === "TASK_COMPLETE") {
|
|
89
|
-
return {
|
|
90
|
-
action: {
|
|
91
|
-
type: "task_complete",
|
|
92
|
-
thought,
|
|
93
|
-
summary: String(tc.arguments?.summary ?? ""),
|
|
94
|
-
},
|
|
95
|
-
state: newState,
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
if (tc.name === "TASK_FAILED") {
|
|
99
|
-
return {
|
|
100
|
-
action: {
|
|
101
|
-
type: "task_failed",
|
|
102
|
-
thought,
|
|
103
|
-
reason: String(tc.arguments?.reason ?? ""),
|
|
104
|
-
},
|
|
105
|
-
state: newState,
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
return {
|
|
109
|
-
action: {
|
|
110
|
-
type: "tool_call",
|
|
111
|
-
thought,
|
|
112
|
-
toolName: tc.name,
|
|
113
|
-
toolParams: tc.arguments,
|
|
114
|
-
},
|
|
115
|
-
state: newState,
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
54
|
// Parse text-based THOUGHT + ACTION format (for Ollama and fallback)
|
|
119
55
|
const action = this.parseTextResponse(response.content);
|
|
120
56
|
const newState = (0, state_1.appendHistory)(state, {
|
|
@@ -134,6 +70,22 @@ class AgentBrain {
|
|
|
134
70
|
state,
|
|
135
71
|
};
|
|
136
72
|
}
|
|
73
|
+
if (action.toolName === "INVALID_ACTION") {
|
|
74
|
+
const observation = (0, prompts_1.buildObservationMessage)("INVALID_ACTION", false, "You did not provide a valid JSON action block or native tool call. You MUST provide exactly ONE action.");
|
|
75
|
+
const newState = (0, state_1.appendHistory)(state, {
|
|
76
|
+
role: "observation",
|
|
77
|
+
content: observation,
|
|
78
|
+
toolName: "INVALID_ACTION",
|
|
79
|
+
});
|
|
80
|
+
return {
|
|
81
|
+
observation,
|
|
82
|
+
success: false,
|
|
83
|
+
state: (0, state_1.appendError)(newState, {
|
|
84
|
+
message: "Invalid action format",
|
|
85
|
+
stepId: "parse",
|
|
86
|
+
}),
|
|
87
|
+
};
|
|
88
|
+
}
|
|
137
89
|
const result = await this.tools.execute(action.toolName, action.toolParams ?? {}, state);
|
|
138
90
|
const observation = (0, prompts_1.buildObservationMessage)(action.toolName, result.success, result.output || result.error || "No output");
|
|
139
91
|
const newState = (0, state_1.appendHistory)(state, {
|
|
@@ -161,7 +113,7 @@ class AgentBrain {
|
|
|
161
113
|
// System prompt
|
|
162
114
|
messages.push({
|
|
163
115
|
role: "system",
|
|
164
|
-
content: (0, prompts_1.buildSystemPrompt)(this.tools, state.environment.os, state.environment.route),
|
|
116
|
+
content: (0, prompts_1.buildSystemPrompt)(this.tools, state.environment.os, state.environment.route, false),
|
|
165
117
|
});
|
|
166
118
|
// User's goal
|
|
167
119
|
messages.push({
|
|
@@ -220,9 +172,10 @@ class AgentBrain {
|
|
|
220
172
|
}
|
|
221
173
|
// No parseable action — treat as thinking aloud
|
|
222
174
|
return {
|
|
223
|
-
type: "
|
|
175
|
+
type: "tool_call",
|
|
224
176
|
thought,
|
|
225
|
-
|
|
177
|
+
toolName: "INVALID_ACTION",
|
|
178
|
+
toolParams: {},
|
|
226
179
|
};
|
|
227
180
|
}
|
|
228
181
|
try {
|
|
@@ -231,9 +184,10 @@ class AgentBrain {
|
|
|
231
184
|
}
|
|
232
185
|
catch {
|
|
233
186
|
return {
|
|
234
|
-
type: "
|
|
187
|
+
type: "tool_call",
|
|
235
188
|
thought,
|
|
236
|
-
|
|
189
|
+
toolName: "INVALID_ACTION",
|
|
190
|
+
toolParams: { error: `Invalid JSON in ACTION block: ${actionMatch[1]}` },
|
|
237
191
|
};
|
|
238
192
|
}
|
|
239
193
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"brain.js","sourceRoot":"","sources":["../../../src/agent/brain.ts"],"names":[],"mappings":";;;AAGA,uCAKmB;AACnB,mCAAqD;AAYrD;;;;;;;;;;GAUG;AACH,MAAa,UAAU;IAEX;IACA;IAFV,YACU,GAAe,EACf,KAAmB;QADnB,QAAG,GAAH,GAAG,CAAY;QACf,UAAK,GAAL,KAAK,CAAc;IAC1B,CAAC;IAEJ;;OAEG;IACH,KAAK,CAAC,KAAK,CAAC,KAAiB;QAC3B,MAAM,QAAQ,GAAG,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;QAE3C,MAAM,OAAO,GAAe;YAC1B,WAAW,EAAE,GAAG;YAChB,SAAS,EAAE,IAAI;SAChB,CAAC;QAEF
|
|
1
|
+
{"version":3,"file":"brain.js","sourceRoot":"","sources":["../../../src/agent/brain.ts"],"names":[],"mappings":";;;AAGA,uCAKmB;AACnB,mCAAqD;AAYrD;;;;;;;;;;GAUG;AACH,MAAa,UAAU;IAEX;IACA;IAFV,YACU,GAAe,EACf,KAAmB;QADnB,QAAG,GAAH,GAAG,CAAY;QACf,UAAK,GAAL,KAAK,CAAc;IAC1B,CAAC;IAEJ;;OAEG;IACH,KAAK,CAAC,KAAK,CAAC,KAAiB;QAC3B,MAAM,QAAQ,GAAG,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;QAE3C,MAAM,OAAO,GAAe;YAC1B,WAAW,EAAE,GAAG;YAChB,SAAS,EAAE,IAAI;SAChB,CAAC;QAEF,+FAA+F;QAC/F,sEAAsE;QAEtE,IAAI,QAAQ,CAAC;QACb,IAAI,CAAC;YACH,QAAQ,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;QACpD,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,MAAM,QAAQ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AC;IAEO,cAAc,CACpB,OAAe,EACf,MAA4D;QAE5D,IAAI,MAAM,CAAC,MAAM,KAAK,eAAe,EAAE,CAAC;YACtC,OAAO;gBACL,IAAI,EAAE,eAAe;gBACrB,OAAO;gBACP,OAAO,EACL,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,IAAI,EAAE,CAAC,IAAI,OAAO;aAClD,CAAC;QACJ,CAAC;QAED,IAAI,MAAM,CAAC,MAAM,KAAK,aAAa,EAAE,CAAC;YACpC,OAAO;gBACL,IAAI,EAAE,aAAa;gBACnB,OAAO;gBACP,MAAM,EACJ,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,IAAI,EAAE,CAAC,IAAI,OAAO;aACjD,CAAC;QACJ,CAAC;QAED,OAAO;YACL,IAAI,EAAE,WAAW;YACjB,OAAO;YACP,QAAQ,EAAE,MAAM,CAAC,MAAM;YACvB,UAAU,EAAE,MAAM,CAAC,MAAM,IAAI,EAAE;SAChC,CAAC;IACJ,CAAC;CACF;AA7PD,gCA6PC"}
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* format, and guardrails.
|
|
7
7
|
*/
|
|
8
8
|
import type { ToolRegistry } from "./tool-registry";
|
|
9
|
-
export declare function buildSystemPrompt(toolRegistry: ToolRegistry, os: string, route: string): string;
|
|
9
|
+
export declare function buildSystemPrompt(toolRegistry: ToolRegistry, os: string, route: string, useNativeToolCalling: boolean): string;
|
|
10
10
|
export declare function buildPlanningPrompt(userGoal: string): string;
|
|
11
11
|
export declare function buildReflectionPrompt(failedStep: string, errorOutput: string, attemptCount: number): string;
|
|
12
12
|
export declare function buildObservationMessage(toolName: string, success: boolean, output: string): string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prompts.d.ts","sourceRoot":"","sources":["../../../src/agent/prompts.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAGpD,wBAAgB,iBAAiB,CAC/B,YAAY,EAAE,YAAY,EAC1B,EAAE,EAAE,MAAM,EACV,KAAK,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"prompts.d.ts","sourceRoot":"","sources":["../../../src/agent/prompts.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAGpD,wBAAgB,iBAAiB,CAC/B,YAAY,EAAE,YAAY,EAC1B,EAAE,EAAE,MAAM,EACV,KAAK,EAAE,MAAM,EACb,oBAAoB,EAAE,OAAO,GAC5B,MAAM,CA6DR;AAGD,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAY5D;AAGD,wBAAgB,qBAAqB,CACnC,UAAU,EAAE,MAAM,EAClB,WAAW,EAAE,MAAM,EACnB,YAAY,EAAE,MAAM,GACnB,MAAM,CAiBR;AAGD,wBAAgB,uBAAuB,CACrC,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,MAAM,GACb,MAAM,CAGR"}
|
|
@@ -12,8 +12,28 @@ exports.buildPlanningPrompt = buildPlanningPrompt;
|
|
|
12
12
|
exports.buildReflectionPrompt = buildReflectionPrompt;
|
|
13
13
|
exports.buildObservationMessage = buildObservationMessage;
|
|
14
14
|
// ─── System Identity Prompt ────────────────────────────────────────
|
|
15
|
-
function buildSystemPrompt(toolRegistry, os, route) {
|
|
15
|
+
function buildSystemPrompt(toolRegistry, os, route, useNativeToolCalling) {
|
|
16
16
|
const toolSummary = toolRegistry.getToolSummary();
|
|
17
|
+
const responseInstructions = useNativeToolCalling
|
|
18
|
+
? `Since you have native tool calling enabled, you MUST invoke exactly ONE tool for EVERY response.
|
|
19
|
+
Do not output raw JSON text blocks for actions; simply call the tool natively.
|
|
20
|
+
If you need to talk to the user or indicate completion/failure, use the TASK_COMPLETE or TASK_FAILED tools.`
|
|
21
|
+
: `For EVERY turn, output EXACTLY this format:
|
|
22
|
+
|
|
23
|
+
THOUGHT: <your reasoning about what to do next>
|
|
24
|
+
ACTION: <a single JSON object with "action" and "params" keys>
|
|
25
|
+
|
|
26
|
+
Example:
|
|
27
|
+
THOUGHT: I need to check if Anchor is installed before trying to build.
|
|
28
|
+
ACTION: {"action": "check_environment", "params": {}}
|
|
29
|
+
|
|
30
|
+
When you have completed the user's goal, output:
|
|
31
|
+
THOUGHT: <summary of what was accomplished>
|
|
32
|
+
ACTION: {"action": "TASK_COMPLETE", "params": {"summary": "<final summary>"}}
|
|
33
|
+
|
|
34
|
+
If you cannot accomplish the goal, output:
|
|
35
|
+
THOUGHT: <explanation of why>
|
|
36
|
+
ACTION: {"action": "TASK_FAILED", "params": {"reason": "<reason>"}}`;
|
|
17
37
|
return `You are the USO Agent — an autonomous AI assistant built into the Universal Solana Orchestrator CLI.
|
|
18
38
|
|
|
19
39
|
## Your Identity
|
|
@@ -25,33 +45,18 @@ You are an expert Solana developer and DevOps engineer. You help developers buil
|
|
|
25
45
|
- Current Directory: ${process.cwd()}
|
|
26
46
|
|
|
27
47
|
## Available Tools
|
|
28
|
-
You have access to
|
|
48
|
+
You have access to a set of tools to interact with the environment.
|
|
29
49
|
|
|
30
50
|
${toolSummary}
|
|
31
51
|
|
|
32
52
|
## How to Respond
|
|
33
53
|
You operate in a Thought → Action → Observation loop.
|
|
34
54
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
THOUGHT: <your reasoning about what to do next>
|
|
38
|
-
ACTION: <a single JSON object with "action" and "params" keys>
|
|
39
|
-
|
|
40
|
-
Example:
|
|
41
|
-
THOUGHT: I need to check if Anchor is installed before trying to build.
|
|
42
|
-
ACTION: {"action": "check_environment", "params": {}}
|
|
43
|
-
|
|
44
|
-
When you have completed the user's goal, output:
|
|
45
|
-
THOUGHT: <summary of what was accomplished>
|
|
46
|
-
ACTION: {"action": "TASK_COMPLETE", "params": {"summary": "<final summary>"}}
|
|
47
|
-
|
|
48
|
-
If you cannot accomplish the goal, output:
|
|
49
|
-
THOUGHT: <explanation of why>
|
|
50
|
-
ACTION: {"action": "TASK_FAILED", "params": {"reason": "<reason>"}}
|
|
55
|
+
${responseInstructions}
|
|
51
56
|
|
|
52
57
|
## Rules
|
|
53
|
-
1. ALWAYS output exactly ONE action per turn. You MUST use a tool or ACTION block for EVERY single response. Never just output plain text.
|
|
54
|
-
2. ALWAYS
|
|
58
|
+
1. ALWAYS output exactly ONE action per turn. You MUST use a tool call or ACTION block for EVERY single response. Never just output plain text.
|
|
59
|
+
2. ALWAYS provide your reasoning before or during your tool call.
|
|
55
60
|
3. Use check_environment FIRST before attempting any build/test/deploy.
|
|
56
61
|
4. NEVER deploy to mainnet-beta without explicitly confirming with the user. If the user asked to deploy to devnet or testnet, proceed without asking for confirmation.
|
|
57
62
|
5. If a command fails, analyze the error and try a different approach. Don't repeat the same failing command.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prompts.js","sourceRoot":"","sources":["../../../src/agent/prompts.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;AAKH,
|
|
1
|
+
{"version":3,"file":"prompts.js","sourceRoot":"","sources":["../../../src/agent/prompts.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;AAKH,8CAkEC;AAGD,kDAYC;AAGD,sDAqBC;AAGD,0DAOC;AApHD,sEAAsE;AACtE,SAAgB,iBAAiB,CAC/B,YAA0B,EAC1B,EAAU,EACV,KAAa,EACb,oBAA6B;IAE7B,MAAM,WAAW,GAAG,YAAY,CAAC,cAAc,EAAE,CAAC;IAElD,MAAM,oBAAoB,GAAG,oBAAoB;QAC/C,CAAC,CAAC;;4GAEsG;QACxG,CAAC,CAAC;;;;;;;;;;;;;;;oEAe8D,CAAC;IAEnE,OAAO;;;;;;sBAMa,EAAE;mBACL,KAAK;uBACD,OAAO,CAAC,GAAG,EAAE;;;;;EAKlC,WAAW;;;;;EAKX,oBAAoB;;;;;;;;;;;;;;;;;;iFAkB2D,CAAC;AA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H,OAAO,CAAC,iBAAiB;IAgDzB,OAAO,CAAC,cAAc;CA6BvB"}
|
|
@@ -27,34 +27,8 @@ export class AgentBrain {
|
|
|
27
27
|
temperature: 0.1,
|
|
28
28
|
maxTokens: 2048,
|
|
29
29
|
};
|
|
30
|
-
//
|
|
31
|
-
|
|
32
|
-
toolDefs.push({
|
|
33
|
-
name: "TASK_COMPLETE",
|
|
34
|
-
description: "Mark the user's goal as complete.",
|
|
35
|
-
parameters: {
|
|
36
|
-
type: "object",
|
|
37
|
-
properties: {
|
|
38
|
-
summary: { type: "string", description: "Summary of what was accomplished." }
|
|
39
|
-
},
|
|
40
|
-
required: ["summary"],
|
|
41
|
-
}
|
|
42
|
-
}, {
|
|
43
|
-
name: "TASK_FAILED",
|
|
44
|
-
description: "Mark the user's goal as failed due to inability to accomplish it.",
|
|
45
|
-
parameters: {
|
|
46
|
-
type: "object",
|
|
47
|
-
properties: {
|
|
48
|
-
reason: { type: "string", description: "Reason why the goal could not be completed." }
|
|
49
|
-
},
|
|
50
|
-
required: ["reason"],
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
if (this.llm.provider === "openai" ||
|
|
54
|
-
this.llm.provider === "github" ||
|
|
55
|
-
this.llm.provider === "gemini") {
|
|
56
|
-
options.tools = toolDefs;
|
|
57
|
-
}
|
|
30
|
+
// Removed native tool calling logic because GitHub Models' gpt-4o-mini often omits tool calls.
|
|
31
|
+
// We will rely entirely on the text-based THOUGHT/ACTION JSON format.
|
|
58
32
|
let response;
|
|
59
33
|
try {
|
|
60
34
|
response = await this.llm.chat(messages, options);
|
|
@@ -74,44 +48,6 @@ export class AgentBrain {
|
|
|
74
48
|
state: newState,
|
|
75
49
|
};
|
|
76
50
|
}
|
|
77
|
-
// Handle native function calling responses
|
|
78
|
-
if (response.toolCalls && response.toolCalls.length > 0) {
|
|
79
|
-
const tc = response.toolCalls[0]; // Process one tool call at a time
|
|
80
|
-
const thought = response.content || `Calling ${tc.name}`;
|
|
81
|
-
const newState = appendHistory(state, {
|
|
82
|
-
role: "thought",
|
|
83
|
-
content: thought,
|
|
84
|
-
});
|
|
85
|
-
if (tc.name === "TASK_COMPLETE") {
|
|
86
|
-
return {
|
|
87
|
-
action: {
|
|
88
|
-
type: "task_complete",
|
|
89
|
-
thought,
|
|
90
|
-
summary: String(tc.arguments?.summary ?? ""),
|
|
91
|
-
},
|
|
92
|
-
state: newState,
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
if (tc.name === "TASK_FAILED") {
|
|
96
|
-
return {
|
|
97
|
-
action: {
|
|
98
|
-
type: "task_failed",
|
|
99
|
-
thought,
|
|
100
|
-
reason: String(tc.arguments?.reason ?? ""),
|
|
101
|
-
},
|
|
102
|
-
state: newState,
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
return {
|
|
106
|
-
action: {
|
|
107
|
-
type: "tool_call",
|
|
108
|
-
thought,
|
|
109
|
-
toolName: tc.name,
|
|
110
|
-
toolParams: tc.arguments,
|
|
111
|
-
},
|
|
112
|
-
state: newState,
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
51
|
// Parse text-based THOUGHT + ACTION format (for Ollama and fallback)
|
|
116
52
|
const action = this.parseTextResponse(response.content);
|
|
117
53
|
const newState = appendHistory(state, {
|
|
@@ -131,6 +67,22 @@ export class AgentBrain {
|
|
|
131
67
|
state,
|
|
132
68
|
};
|
|
133
69
|
}
|
|
70
|
+
if (action.toolName === "INVALID_ACTION") {
|
|
71
|
+
const observation = buildObservationMessage("INVALID_ACTION", false, "You did not provide a valid JSON action block or native tool call. You MUST provide exactly ONE action.");
|
|
72
|
+
const newState = appendHistory(state, {
|
|
73
|
+
role: "observation",
|
|
74
|
+
content: observation,
|
|
75
|
+
toolName: "INVALID_ACTION",
|
|
76
|
+
});
|
|
77
|
+
return {
|
|
78
|
+
observation,
|
|
79
|
+
success: false,
|
|
80
|
+
state: appendError(newState, {
|
|
81
|
+
message: "Invalid action format",
|
|
82
|
+
stepId: "parse",
|
|
83
|
+
}),
|
|
84
|
+
};
|
|
85
|
+
}
|
|
134
86
|
const result = await this.tools.execute(action.toolName, action.toolParams ?? {}, state);
|
|
135
87
|
const observation = buildObservationMessage(action.toolName, result.success, result.output || result.error || "No output");
|
|
136
88
|
const newState = appendHistory(state, {
|
|
@@ -158,7 +110,7 @@ export class AgentBrain {
|
|
|
158
110
|
// System prompt
|
|
159
111
|
messages.push({
|
|
160
112
|
role: "system",
|
|
161
|
-
content: buildSystemPrompt(this.tools, state.environment.os, state.environment.route),
|
|
113
|
+
content: buildSystemPrompt(this.tools, state.environment.os, state.environment.route, false),
|
|
162
114
|
});
|
|
163
115
|
// User's goal
|
|
164
116
|
messages.push({
|
|
@@ -217,9 +169,10 @@ export class AgentBrain {
|
|
|
217
169
|
}
|
|
218
170
|
// No parseable action — treat as thinking aloud
|
|
219
171
|
return {
|
|
220
|
-
type: "
|
|
172
|
+
type: "tool_call",
|
|
221
173
|
thought,
|
|
222
|
-
|
|
174
|
+
toolName: "INVALID_ACTION",
|
|
175
|
+
toolParams: {},
|
|
223
176
|
};
|
|
224
177
|
}
|
|
225
178
|
try {
|
|
@@ -228,9 +181,10 @@ export class AgentBrain {
|
|
|
228
181
|
}
|
|
229
182
|
catch {
|
|
230
183
|
return {
|
|
231
|
-
type: "
|
|
184
|
+
type: "tool_call",
|
|
232
185
|
thought,
|
|
233
|
-
|
|
186
|
+
toolName: "INVALID_ACTION",
|
|
187
|
+
toolParams: { error: `Invalid JSON in ACTION block: ${actionMatch[1]}` },
|
|
234
188
|
};
|
|
235
189
|
}
|
|
236
190
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"brain.js","sourceRoot":"","sources":["../../../src/agent/brain.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,iBAAiB,EACjB,mBAAmB,EACnB,uBAAuB,EACvB,qBAAqB,GACtB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,SAAS,CA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AAI,EAAE,eAAe;gBACrB,OAAO;gBACP,OAAO,EACL,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,IAAI,EAAE,CAAC,IAAI,OAAO;aAClD,CAAC;QACJ,CAAC;QAED,IAAI,MAAM,CAAC,MAAM,KAAK,aAAa,EAAE,CAAC;YACpC,OAAO;gBACL,IAAI,EAAE,aAAa;gBACnB,OAAO;gBACP,MAAM,EACJ,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,IAAI,EAAE,CAAC,IAAI,OAAO;aACjD,CAAC;QACJ,CAAC;QAED,OAAO;YACL,IAAI,EAAE,WAAW;YACjB,OAAO;YACP,QAAQ,EAAE,MAAM,CAAC,MAAM;YACvB,UAAU,EAAE,MAAM,CAAC,MAAM,IAAI,EAAE;SAChC,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* format, and guardrails.
|
|
7
7
|
*/
|
|
8
8
|
import type { ToolRegistry } from "./tool-registry";
|
|
9
|
-
export declare function buildSystemPrompt(toolRegistry: ToolRegistry, os: string, route: string): string;
|
|
9
|
+
export declare function buildSystemPrompt(toolRegistry: ToolRegistry, os: string, route: string, useNativeToolCalling: boolean): string;
|
|
10
10
|
export declare function buildPlanningPrompt(userGoal: string): string;
|
|
11
11
|
export declare function buildReflectionPrompt(failedStep: string, errorOutput: string, attemptCount: number): string;
|
|
12
12
|
export declare function buildObservationMessage(toolName: string, success: boolean, output: string): string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prompts.d.ts","sourceRoot":"","sources":["../../../src/agent/prompts.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAGpD,wBAAgB,iBAAiB,CAC/B,YAAY,EAAE,YAAY,EAC1B,EAAE,EAAE,MAAM,EACV,KAAK,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"prompts.d.ts","sourceRoot":"","sources":["../../../src/agent/prompts.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAGpD,wBAAgB,iBAAiB,CAC/B,YAAY,EAAE,YAAY,EAC1B,EAAE,EAAE,MAAM,EACV,KAAK,EAAE,MAAM,EACb,oBAAoB,EAAE,OAAO,GAC5B,MAAM,CA6DR;AAGD,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAY5D;AAGD,wBAAgB,qBAAqB,CACnC,UAAU,EAAE,MAAM,EAClB,WAAW,EAAE,MAAM,EACnB,YAAY,EAAE,MAAM,GACnB,MAAM,CAiBR;AAGD,wBAAgB,uBAAuB,CACrC,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,MAAM,GACb,MAAM,CAGR"}
|
|
@@ -6,8 +6,28 @@
|
|
|
6
6
|
* format, and guardrails.
|
|
7
7
|
*/
|
|
8
8
|
// ─── System Identity Prompt ────────────────────────────────────────
|
|
9
|
-
export function buildSystemPrompt(toolRegistry, os, route) {
|
|
9
|
+
export function buildSystemPrompt(toolRegistry, os, route, useNativeToolCalling) {
|
|
10
10
|
const toolSummary = toolRegistry.getToolSummary();
|
|
11
|
+
const responseInstructions = useNativeToolCalling
|
|
12
|
+
? `Since you have native tool calling enabled, you MUST invoke exactly ONE tool for EVERY response.
|
|
13
|
+
Do not output raw JSON text blocks for actions; simply call the tool natively.
|
|
14
|
+
If you need to talk to the user or indicate completion/failure, use the TASK_COMPLETE or TASK_FAILED tools.`
|
|
15
|
+
: `For EVERY turn, output EXACTLY this format:
|
|
16
|
+
|
|
17
|
+
THOUGHT: <your reasoning about what to do next>
|
|
18
|
+
ACTION: <a single JSON object with "action" and "params" keys>
|
|
19
|
+
|
|
20
|
+
Example:
|
|
21
|
+
THOUGHT: I need to check if Anchor is installed before trying to build.
|
|
22
|
+
ACTION: {"action": "check_environment", "params": {}}
|
|
23
|
+
|
|
24
|
+
When you have completed the user's goal, output:
|
|
25
|
+
THOUGHT: <summary of what was accomplished>
|
|
26
|
+
ACTION: {"action": "TASK_COMPLETE", "params": {"summary": "<final summary>"}}
|
|
27
|
+
|
|
28
|
+
If you cannot accomplish the goal, output:
|
|
29
|
+
THOUGHT: <explanation of why>
|
|
30
|
+
ACTION: {"action": "TASK_FAILED", "params": {"reason": "<reason>"}}`;
|
|
11
31
|
return `You are the USO Agent — an autonomous AI assistant built into the Universal Solana Orchestrator CLI.
|
|
12
32
|
|
|
13
33
|
## Your Identity
|
|
@@ -19,33 +39,18 @@ You are an expert Solana developer and DevOps engineer. You help developers buil
|
|
|
19
39
|
- Current Directory: ${process.cwd()}
|
|
20
40
|
|
|
21
41
|
## Available Tools
|
|
22
|
-
You have access to
|
|
42
|
+
You have access to a set of tools to interact with the environment.
|
|
23
43
|
|
|
24
44
|
${toolSummary}
|
|
25
45
|
|
|
26
46
|
## How to Respond
|
|
27
47
|
You operate in a Thought → Action → Observation loop.
|
|
28
48
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
THOUGHT: <your reasoning about what to do next>
|
|
32
|
-
ACTION: <a single JSON object with "action" and "params" keys>
|
|
33
|
-
|
|
34
|
-
Example:
|
|
35
|
-
THOUGHT: I need to check if Anchor is installed before trying to build.
|
|
36
|
-
ACTION: {"action": "check_environment", "params": {}}
|
|
37
|
-
|
|
38
|
-
When you have completed the user's goal, output:
|
|
39
|
-
THOUGHT: <summary of what was accomplished>
|
|
40
|
-
ACTION: {"action": "TASK_COMPLETE", "params": {"summary": "<final summary>"}}
|
|
41
|
-
|
|
42
|
-
If you cannot accomplish the goal, output:
|
|
43
|
-
THOUGHT: <explanation of why>
|
|
44
|
-
ACTION: {"action": "TASK_FAILED", "params": {"reason": "<reason>"}}
|
|
49
|
+
${responseInstructions}
|
|
45
50
|
|
|
46
51
|
## Rules
|
|
47
|
-
1. ALWAYS output exactly ONE action per turn. You MUST use a tool or ACTION block for EVERY single response. Never just output plain text.
|
|
48
|
-
2. ALWAYS
|
|
52
|
+
1. ALWAYS output exactly ONE action per turn. You MUST use a tool call or ACTION block for EVERY single response. Never just output plain text.
|
|
53
|
+
2. ALWAYS provide your reasoning before or during your tool call.
|
|
49
54
|
3. Use check_environment FIRST before attempting any build/test/deploy.
|
|
50
55
|
4. NEVER deploy to mainnet-beta without explicitly confirming with the user. If the user asked to deploy to devnet or testnet, proceed without asking for confirmation.
|
|
51
56
|
5. If a command fails, analyze the error and try a different approach. Don't repeat the same failing command.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prompts.js","sourceRoot":"","sources":["../../../src/agent/prompts.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,sEAAsE;AACtE,MAAM,UAAU,iBAAiB,CAC/B,YAA0B,EAC1B,EAAU,EACV,KAAa;
|
|
1
|
+
{"version":3,"file":"prompts.js","sourceRoot":"","sources":["../../../src/agent/prompts.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,sEAAsE;AACtE,MAAM,UAAU,iBAAiB,CAC/B,YAA0B,EAC1B,EAAU,EACV,KAAa,EACb,oBAA6B;IAE7B,MAAM,WAAW,GAAG,YAAY,CAAC,cAAc,EAAE,CAAC;IAElD,MAAM,oBAAoB,GAAG,oBAAoB;QAC/C,CAAC,CAAC;;4GAEsG;QACxG,CAAC,CAAC;;;;;;;;;;;;;;;oEAe8D,CAAC;IAEnE,OAAO;;;;;;sBAMa,EAAE;mBACL,KAAK;uBACD,OAAO,CAAC,GAAG,EAAE;;;;;EAKlC,WAAW;;;;;EAKX,oBAAoB;;;;;;;;;;;;;;;;;;iFAkB2D,CAAC;AAClF,CAAC;AAED,sEAAsE;AACtE,MAAM,UAAU,mBAAmB,CAAC,QAAgB;IAClD,OAAO;;GAEN,QAAQ;;;;;;;;gEAQqD,CAAC;AACjE,CAAC;AAED,sEAAsE;AACtE,MAAM,UAAU,qBAAqB,CACnC,UAAkB,EAClB,WAAmB,EACnB,YAAoB;IAEpB,OAAO;;eAEM,UAAU;;;EAGvB,WAAW,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC;;;mBAGT,YAAY;;;;;;;gDAOiB,CAAC;AACjD,CAAC;AAED,sEAAsE;AACtE,MAAM,UAAU,uBAAuB,CACrC,QAAgB,EAChB,OAAgB,EAChB,MAAc;IAEd,MAAM,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,UAAU,CAAC;IAClD,OAAO,gBAAgB,QAAQ,KAAK,MAAM,MAAM,MAAM,EAAE,CAAC;AAC3D,CAAC"}
|
|
@@ -47,40 +47,8 @@ export class AgentBrain {
|
|
|
47
47
|
maxTokens: 2048,
|
|
48
48
|
};
|
|
49
49
|
|
|
50
|
-
//
|
|
51
|
-
|
|
52
|
-
toolDefs.push(
|
|
53
|
-
{
|
|
54
|
-
name: "TASK_COMPLETE",
|
|
55
|
-
description: "Mark the user's goal as complete.",
|
|
56
|
-
parameters: {
|
|
57
|
-
type: "object",
|
|
58
|
-
properties: {
|
|
59
|
-
summary: { type: "string", description: "Summary of what was accomplished." }
|
|
60
|
-
},
|
|
61
|
-
required: ["summary"],
|
|
62
|
-
}
|
|
63
|
-
},
|
|
64
|
-
{
|
|
65
|
-
name: "TASK_FAILED",
|
|
66
|
-
description: "Mark the user's goal as failed due to inability to accomplish it.",
|
|
67
|
-
parameters: {
|
|
68
|
-
type: "object",
|
|
69
|
-
properties: {
|
|
70
|
-
reason: { type: "string", description: "Reason why the goal could not be completed." }
|
|
71
|
-
},
|
|
72
|
-
required: ["reason"],
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
);
|
|
76
|
-
|
|
77
|
-
if (
|
|
78
|
-
this.llm.provider === "openai" ||
|
|
79
|
-
this.llm.provider === "github" ||
|
|
80
|
-
this.llm.provider === "gemini"
|
|
81
|
-
) {
|
|
82
|
-
options.tools = toolDefs;
|
|
83
|
-
}
|
|
50
|
+
// Removed native tool calling logic because GitHub Models' gpt-4o-mini often omits tool calls.
|
|
51
|
+
// We will rely entirely on the text-based THOUGHT/ACTION JSON format.
|
|
84
52
|
|
|
85
53
|
let response;
|
|
86
54
|
try {
|
|
@@ -101,48 +69,7 @@ export class AgentBrain {
|
|
|
101
69
|
};
|
|
102
70
|
}
|
|
103
71
|
|
|
104
|
-
// Handle native function calling responses
|
|
105
|
-
if (response.toolCalls && response.toolCalls.length > 0) {
|
|
106
|
-
const tc = response.toolCalls[0]; // Process one tool call at a time
|
|
107
|
-
const thought = response.content || `Calling ${tc.name}`;
|
|
108
|
-
|
|
109
|
-
const newState = appendHistory(state, {
|
|
110
|
-
role: "thought",
|
|
111
|
-
content: thought,
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
if (tc.name === "TASK_COMPLETE") {
|
|
115
|
-
return {
|
|
116
|
-
action: {
|
|
117
|
-
type: "task_complete",
|
|
118
|
-
thought,
|
|
119
|
-
summary: String(tc.arguments?.summary ?? ""),
|
|
120
|
-
},
|
|
121
|
-
state: newState,
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
72
|
|
|
125
|
-
if (tc.name === "TASK_FAILED") {
|
|
126
|
-
return {
|
|
127
|
-
action: {
|
|
128
|
-
type: "task_failed",
|
|
129
|
-
thought,
|
|
130
|
-
reason: String(tc.arguments?.reason ?? ""),
|
|
131
|
-
},
|
|
132
|
-
state: newState,
|
|
133
|
-
};
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
return {
|
|
137
|
-
action: {
|
|
138
|
-
type: "tool_call",
|
|
139
|
-
thought,
|
|
140
|
-
toolName: tc.name,
|
|
141
|
-
toolParams: tc.arguments,
|
|
142
|
-
},
|
|
143
|
-
state: newState,
|
|
144
|
-
};
|
|
145
|
-
}
|
|
146
73
|
|
|
147
74
|
// Parse text-based THOUGHT + ACTION format (for Ollama and fallback)
|
|
148
75
|
const action = this.parseTextResponse(response.content);
|
|
@@ -169,6 +96,27 @@ export class AgentBrain {
|
|
|
169
96
|
};
|
|
170
97
|
}
|
|
171
98
|
|
|
99
|
+
if (action.toolName === "INVALID_ACTION") {
|
|
100
|
+
const observation = buildObservationMessage(
|
|
101
|
+
"INVALID_ACTION",
|
|
102
|
+
false,
|
|
103
|
+
"You did not provide a valid JSON action block or native tool call. You MUST provide exactly ONE action."
|
|
104
|
+
);
|
|
105
|
+
const newState = appendHistory(state, {
|
|
106
|
+
role: "observation",
|
|
107
|
+
content: observation,
|
|
108
|
+
toolName: "INVALID_ACTION",
|
|
109
|
+
});
|
|
110
|
+
return {
|
|
111
|
+
observation,
|
|
112
|
+
success: false,
|
|
113
|
+
state: appendError(newState, {
|
|
114
|
+
message: "Invalid action format",
|
|
115
|
+
stepId: "parse",
|
|
116
|
+
}),
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
|
|
172
120
|
const result = await this.tools.execute(
|
|
173
121
|
action.toolName,
|
|
174
122
|
action.toolParams ?? {},
|
|
@@ -213,6 +161,7 @@ export class AgentBrain {
|
|
|
213
161
|
this.tools,
|
|
214
162
|
state.environment.os,
|
|
215
163
|
state.environment.route,
|
|
164
|
+
false, // Force useNativeToolCalling = false
|
|
216
165
|
),
|
|
217
166
|
});
|
|
218
167
|
|
|
@@ -282,9 +231,10 @@ export class AgentBrain {
|
|
|
282
231
|
|
|
283
232
|
// No parseable action — treat as thinking aloud
|
|
284
233
|
return {
|
|
285
|
-
type: "
|
|
234
|
+
type: "tool_call",
|
|
286
235
|
thought,
|
|
287
|
-
|
|
236
|
+
toolName: "INVALID_ACTION",
|
|
237
|
+
toolParams: {},
|
|
288
238
|
};
|
|
289
239
|
}
|
|
290
240
|
|
|
@@ -296,9 +246,10 @@ export class AgentBrain {
|
|
|
296
246
|
return this.classifyAction(thought, parsed);
|
|
297
247
|
} catch {
|
|
298
248
|
return {
|
|
299
|
-
type: "
|
|
249
|
+
type: "tool_call",
|
|
300
250
|
thought,
|
|
301
|
-
|
|
251
|
+
toolName: "INVALID_ACTION",
|
|
252
|
+
toolParams: { error: `Invalid JSON in ACTION block: ${actionMatch[1]}` },
|
|
302
253
|
};
|
|
303
254
|
}
|
|
304
255
|
}
|
|
@@ -13,9 +13,31 @@ export function buildSystemPrompt(
|
|
|
13
13
|
toolRegistry: ToolRegistry,
|
|
14
14
|
os: string,
|
|
15
15
|
route: string,
|
|
16
|
+
useNativeToolCalling: boolean,
|
|
16
17
|
): string {
|
|
17
18
|
const toolSummary = toolRegistry.getToolSummary();
|
|
18
19
|
|
|
20
|
+
const responseInstructions = useNativeToolCalling
|
|
21
|
+
? `Since you have native tool calling enabled, you MUST invoke exactly ONE tool for EVERY response.
|
|
22
|
+
Do not output raw JSON text blocks for actions; simply call the tool natively.
|
|
23
|
+
If you need to talk to the user or indicate completion/failure, use the TASK_COMPLETE or TASK_FAILED tools.`
|
|
24
|
+
: `For EVERY turn, output EXACTLY this format:
|
|
25
|
+
|
|
26
|
+
THOUGHT: <your reasoning about what to do next>
|
|
27
|
+
ACTION: <a single JSON object with "action" and "params" keys>
|
|
28
|
+
|
|
29
|
+
Example:
|
|
30
|
+
THOUGHT: I need to check if Anchor is installed before trying to build.
|
|
31
|
+
ACTION: {"action": "check_environment", "params": {}}
|
|
32
|
+
|
|
33
|
+
When you have completed the user's goal, output:
|
|
34
|
+
THOUGHT: <summary of what was accomplished>
|
|
35
|
+
ACTION: {"action": "TASK_COMPLETE", "params": {"summary": "<final summary>"}}
|
|
36
|
+
|
|
37
|
+
If you cannot accomplish the goal, output:
|
|
38
|
+
THOUGHT: <explanation of why>
|
|
39
|
+
ACTION: {"action": "TASK_FAILED", "params": {"reason": "<reason>"}}`;
|
|
40
|
+
|
|
19
41
|
return `You are the USO Agent — an autonomous AI assistant built into the Universal Solana Orchestrator CLI.
|
|
20
42
|
|
|
21
43
|
## Your Identity
|
|
@@ -27,33 +49,18 @@ You are an expert Solana developer and DevOps engineer. You help developers buil
|
|
|
27
49
|
- Current Directory: ${process.cwd()}
|
|
28
50
|
|
|
29
51
|
## Available Tools
|
|
30
|
-
You have access to
|
|
52
|
+
You have access to a set of tools to interact with the environment.
|
|
31
53
|
|
|
32
54
|
${toolSummary}
|
|
33
55
|
|
|
34
56
|
## How to Respond
|
|
35
57
|
You operate in a Thought → Action → Observation loop.
|
|
36
58
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
THOUGHT: <your reasoning about what to do next>
|
|
40
|
-
ACTION: <a single JSON object with "action" and "params" keys>
|
|
41
|
-
|
|
42
|
-
Example:
|
|
43
|
-
THOUGHT: I need to check if Anchor is installed before trying to build.
|
|
44
|
-
ACTION: {"action": "check_environment", "params": {}}
|
|
45
|
-
|
|
46
|
-
When you have completed the user's goal, output:
|
|
47
|
-
THOUGHT: <summary of what was accomplished>
|
|
48
|
-
ACTION: {"action": "TASK_COMPLETE", "params": {"summary": "<final summary>"}}
|
|
49
|
-
|
|
50
|
-
If you cannot accomplish the goal, output:
|
|
51
|
-
THOUGHT: <explanation of why>
|
|
52
|
-
ACTION: {"action": "TASK_FAILED", "params": {"reason": "<reason>"}}
|
|
59
|
+
${responseInstructions}
|
|
53
60
|
|
|
54
61
|
## Rules
|
|
55
|
-
1. ALWAYS output exactly ONE action per turn. You MUST use a tool or ACTION block for EVERY single response. Never just output plain text.
|
|
56
|
-
2. ALWAYS
|
|
62
|
+
1. ALWAYS output exactly ONE action per turn. You MUST use a tool call or ACTION block for EVERY single response. Never just output plain text.
|
|
63
|
+
2. ALWAYS provide your reasoning before or during your tool call.
|
|
57
64
|
3. Use check_environment FIRST before attempting any build/test/deploy.
|
|
58
65
|
4. NEVER deploy to mainnet-beta without explicitly confirming with the user. If the user asked to deploy to devnet or testnet, proceed without asking for confirmation.
|
|
59
66
|
5. If a command fails, analyze the error and try a different approach. Don't repeat the same failing command.
|