autoclaw 1.0.36 → 1.0.38
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/dist/agent.js +1 -0
- package/dist/tools/index.js +2 -0
- package/dist/tools/prompt-optimizer.js +64 -0
- package/package.json +2 -2
package/dist/agent.js
CHANGED
|
@@ -44,6 +44,7 @@ GUIDELINES:
|
|
|
44
44
|
2. ROBUSTNESS: Use standard Linux/Unix tools found in minimal images (Alpine/Debian).
|
|
45
45
|
3. TOOLS: Use 'execute_shell_command' for actions, 'write_file' for code generation.
|
|
46
46
|
4. CLARITY: Output concise logs. You are a worker unit, not a chat bot.
|
|
47
|
+
5. OPTIMIZATION: When asked to generate creative content (images, stories, complex code), use 'optimize_prompt' first to ensure the best possible output quality.
|
|
47
48
|
`
|
|
48
49
|
}
|
|
49
50
|
];
|
package/dist/tools/index.js
CHANGED
|
@@ -5,12 +5,14 @@ import { NotifyTool } from './notify.js';
|
|
|
5
5
|
import { BrowserTool } from './browser.js';
|
|
6
6
|
import { ScreenshotTool } from './screenshot.js';
|
|
7
7
|
import { ImageTool } from './image.js';
|
|
8
|
+
import { PromptOptimizerTool } from './prompt-optimizer.js';
|
|
8
9
|
// Central Registry of all available tools
|
|
9
10
|
export const toolRegistry = [
|
|
10
11
|
ShellTool,
|
|
11
12
|
ReadFileTool,
|
|
12
13
|
WriteFileTool,
|
|
13
14
|
DateTimeTool,
|
|
15
|
+
PromptOptimizerTool,
|
|
14
16
|
EmailTool,
|
|
15
17
|
SearchTool,
|
|
16
18
|
NotifyTool,
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import OpenAI from 'openai';
|
|
2
|
+
export const PromptOptimizerTool = {
|
|
3
|
+
name: "Prompt Optimizer",
|
|
4
|
+
definition: {
|
|
5
|
+
type: "function",
|
|
6
|
+
function: {
|
|
7
|
+
name: "optimize_prompt",
|
|
8
|
+
description: "Optimize a user's raw task description or prompt to be more professional, structured, and effective. STRONGLY RECOMMENDED for creative tasks (like image generation) or complex scripts to ensure high-quality results.",
|
|
9
|
+
parameters: {
|
|
10
|
+
type: "object",
|
|
11
|
+
properties: {
|
|
12
|
+
raw_prompt: {
|
|
13
|
+
type: "string",
|
|
14
|
+
description: "The original, raw prompt or task description provided by the user."
|
|
15
|
+
},
|
|
16
|
+
context: {
|
|
17
|
+
type: "string",
|
|
18
|
+
description: "Optional context about the goal, audience, or specific requirements (e.g., 'for an image generator', 'for a code reviewer')."
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
required: ["raw_prompt"]
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
handler: async (args, config) => {
|
|
26
|
+
if (!config?.apiKey) {
|
|
27
|
+
return "Error: OpenAI API Key is missing in the configuration. Please run 'autoclaw setup' or check your .env file.";
|
|
28
|
+
}
|
|
29
|
+
const client = new OpenAI({
|
|
30
|
+
apiKey: config.apiKey,
|
|
31
|
+
baseURL: config.baseUrl
|
|
32
|
+
});
|
|
33
|
+
const contextMsg = args.context ? `Context: ${args.context}` : "Context: General AI Assistant interaction.";
|
|
34
|
+
try {
|
|
35
|
+
const completion = await client.chat.completions.create({
|
|
36
|
+
model: config.model || 'gpt-4o',
|
|
37
|
+
messages: [
|
|
38
|
+
{
|
|
39
|
+
role: "system",
|
|
40
|
+
content: `You are an expert Prompt Engineer. Your goal is to rewrite the user's raw prompt to be clear, precise, and highly effective for LLMs or professional communication.
|
|
41
|
+
|
|
42
|
+
RULES:
|
|
43
|
+
1. Preserve the original intent.
|
|
44
|
+
2. Structure the prompt logically (e.g., Role, Context, Task, Constraints, Output Format).
|
|
45
|
+
3. Use professional and concise language.
|
|
46
|
+
4. Return ONLY the optimized prompt. Do not add conversational filler.`
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
role: "user",
|
|
50
|
+
content: `Raw Prompt: "${args.raw_prompt}"
|
|
51
|
+
|
|
52
|
+
${contextMsg}
|
|
53
|
+
|
|
54
|
+
Please optimize this prompt.`
|
|
55
|
+
}
|
|
56
|
+
]
|
|
57
|
+
});
|
|
58
|
+
return completion.choices[0].message?.content || "Error: Failed to generate optimized prompt.";
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
return `Error optimizing prompt: ${error.message}`;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
};
|
package/package.json
CHANGED