ausername-12345 commited on
Commit ·
15036d1
1
Parent(s): c782f16
default to llama-3.1-8b-instant; trim system prompt and tool descriptions to reduce token overhead
Browse files- src/agent.js +18 -54
- src/inferenceClient.js +1 -1
src/agent.js
CHANGED
|
@@ -16,12 +16,10 @@ const BUILTIN_TOOLS = [
|
|
| 16 |
type: 'function',
|
| 17 |
function: {
|
| 18 |
name: 'read_file',
|
| 19 |
-
description: 'Read
|
| 20 |
parameters: {
|
| 21 |
type: 'object',
|
| 22 |
-
properties: {
|
| 23 |
-
path: { type: 'string', description: 'Relative path from project root, e.g. "public/index.html" or "src/agent.js"' },
|
| 24 |
-
},
|
| 25 |
required: ['path'],
|
| 26 |
},
|
| 27 |
},
|
|
@@ -30,13 +28,10 @@ const BUILTIN_TOOLS = [
|
|
| 30 |
type: 'function',
|
| 31 |
function: {
|
| 32 |
name: 'write_file',
|
| 33 |
-
description: '
|
| 34 |
parameters: {
|
| 35 |
type: 'object',
|
| 36 |
-
properties: {
|
| 37 |
-
path: { type: 'string', description: 'Relative path from project root, e.g. "public/index.html" or "src/agent.js"' },
|
| 38 |
-
content: { type: 'string', description: 'The full new content to write' },
|
| 39 |
-
},
|
| 40 |
required: ['path', 'content'],
|
| 41 |
},
|
| 42 |
},
|
|
@@ -45,12 +40,10 @@ const BUILTIN_TOOLS = [
|
|
| 45 |
type: 'function',
|
| 46 |
function: {
|
| 47 |
name: 'list_files',
|
| 48 |
-
description: 'List
|
| 49 |
parameters: {
|
| 50 |
type: 'object',
|
| 51 |
-
properties: {
|
| 52 |
-
dir: { type: 'string', description: 'Relative path from project root, e.g. "public" or "src"' },
|
| 53 |
-
},
|
| 54 |
required: ['dir'],
|
| 55 |
},
|
| 56 |
},
|
|
@@ -61,30 +54,15 @@ const PROPOSE_TOOL = {
|
|
| 61 |
type: 'function',
|
| 62 |
function: {
|
| 63 |
name: 'propose_tool',
|
| 64 |
-
description:
|
| 65 |
-
'Propose a brand new tool (a small piece of JavaScript) for the user to review and approve. ' +
|
| 66 |
-
'Use this whenever you need a capability you do not already have as an approved tool - fetching ' +
|
| 67 |
-
'data, doing a calculation, transforming text, calling an external API, generating a file, etc. ' +
|
| 68 |
-
'Nothing runs until the user approves it, so propose the tool and tell the user, rather than ' +
|
| 69 |
-
'pretending you already did the thing.',
|
| 70 |
parameters: {
|
| 71 |
type: 'object',
|
| 72 |
properties: {
|
| 73 |
-
name: { type: 'string'
|
| 74 |
-
description: { type: 'string'
|
| 75 |
-
reason: { type: 'string'
|
| 76 |
-
parameters: {
|
| 77 |
-
|
| 78 |
-
description: 'JSON Schema (type: object, properties, required) describing the arguments this tool takes',
|
| 79 |
-
},
|
| 80 |
-
code: {
|
| 81 |
-
type: 'string',
|
| 82 |
-
description:
|
| 83 |
-
'JavaScript implementing: async function run(args) { ... return result; }. ' +
|
| 84 |
-
'You have fetch, fs (readFileSync, writeFileSync, readdirSync, existsSync, mkdirSync, unlinkSync, statSync), ' +
|
| 85 |
-
'path (join, resolve, dirname, basename, extname, relative), __projectRoot, JSON, Math, Date, URL, console.log ' +
|
| 86 |
-
'available. Return a JSON-serializable value.',
|
| 87 |
-
},
|
| 88 |
},
|
| 89 |
required: ['name', 'description', 'parameters', 'code'],
|
| 90 |
},
|
|
@@ -98,27 +76,13 @@ function systemPrompt() {
|
|
| 98 |
: '(none yet - you have no approved tools right now)';
|
| 99 |
|
| 100 |
return [
|
| 101 |
-
`You are ${AGENT_NAME}, a sharp, direct AI assistant with a personality
|
| 102 |
-
'
|
|
|
|
|
|
|
|
|
|
| 103 |
'',
|
| 104 |
-
'
|
| 105 |
-
'and propose it with the propose_tool function. The user has to approve any new tool, or any fix to a broken ' +
|
| 106 |
-
'one, before it can run - that is the one hard rule you never route around. Once a tool is approved you can ' +
|
| 107 |
-
'call it directly like any other function.',
|
| 108 |
-
'',
|
| 109 |
-
'When the user asks you to actually do or build something, do it for real via tools rather than describing what ' +
|
| 110 |
-
'you would do. If you truly cannot do it without a new tool, propose one and say so plainly.',
|
| 111 |
-
'',
|
| 112 |
-
'If a tool call comes back with an error, say what happened in one line. A fix may already be queued for approval - ' +
|
| 113 |
-
'do not repeat the exact same failing call hoping for a different result.',
|
| 114 |
-
'',
|
| 115 |
-
'You can also read and modify your own source code directly with `read_file`, `write_file`, and `list_files` ' +
|
| 116 |
-
'— no approval needed. Use `read_file` and `write_file` to edit your HTML (`public/index.html`), CSS ' +
|
| 117 |
-
'(`public/styles.css`), client JS (`public/app.js`), or backend files (`src/*.js`, `server.js`). Changes ' +
|
| 118 |
-
'to `public/` files take effect on the next page load. Changes to backend files require telling the user ' +
|
| 119 |
-
'they should restart the Space for the changes to apply.',
|
| 120 |
-
'',
|
| 121 |
-
'Tools you currently have approved:',
|
| 122 |
toolSummary,
|
| 123 |
].join('\n');
|
| 124 |
}
|
|
|
|
| 16 |
type: 'function',
|
| 17 |
function: {
|
| 18 |
name: 'read_file',
|
| 19 |
+
description: 'Read a project file (relative path from project root, e.g. "public/index.html").',
|
| 20 |
parameters: {
|
| 21 |
type: 'object',
|
| 22 |
+
properties: { path: { type: 'string' } },
|
|
|
|
|
|
|
| 23 |
required: ['path'],
|
| 24 |
},
|
| 25 |
},
|
|
|
|
| 28 |
type: 'function',
|
| 29 |
function: {
|
| 30 |
name: 'write_file',
|
| 31 |
+
description: 'Overwrite a project file (relative path, e.g. "src/agent.js"). Creates parent dirs if needed.',
|
| 32 |
parameters: {
|
| 33 |
type: 'object',
|
| 34 |
+
properties: { path: { type: 'string' }, content: { type: 'string' } },
|
|
|
|
|
|
|
|
|
|
| 35 |
required: ['path', 'content'],
|
| 36 |
},
|
| 37 |
},
|
|
|
|
| 40 |
type: 'function',
|
| 41 |
function: {
|
| 42 |
name: 'list_files',
|
| 43 |
+
description: 'List entries in a project directory (e.g. "." or "src").',
|
| 44 |
parameters: {
|
| 45 |
type: 'object',
|
| 46 |
+
properties: { dir: { type: 'string' } },
|
|
|
|
|
|
|
| 47 |
required: ['dir'],
|
| 48 |
},
|
| 49 |
},
|
|
|
|
| 54 |
type: 'function',
|
| 55 |
function: {
|
| 56 |
name: 'propose_tool',
|
| 57 |
+
description: 'Propose JS tool for user approval. Needs name, description, JSON Schema params, and an async function run(args) body.',
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
parameters: {
|
| 59 |
type: 'object',
|
| 60 |
properties: {
|
| 61 |
+
name: { type: 'string' },
|
| 62 |
+
description: { type: 'string' },
|
| 63 |
+
reason: { type: 'string' },
|
| 64 |
+
parameters: { type: 'object' },
|
| 65 |
+
code: { type: 'string', description: 'async function run(args){...} body. Has fetch, fs, path, __projectRoot.' },
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
},
|
| 67 |
required: ['name', 'description', 'parameters', 'code'],
|
| 68 |
},
|
|
|
|
| 76 |
: '(none yet - you have no approved tools right now)';
|
| 77 |
|
| 78 |
return [
|
| 79 |
+
`You are ${AGENT_NAME}, a sharp, direct AI assistant with a personality.`,
|
| 80 |
+
'Short sentences, no filler. Use tools (read_file/write_file/list_files) to edit your own code - no approval needed.',
|
| 81 |
+
'For new capabilities, use propose_tool - the user must approve before it runs, so tell them, dont pretend it ran.',
|
| 82 |
+
'Dont repeat a failing tool call; a fix may already be queued.',
|
| 83 |
+
'Editing public/ takes effect on next page load. Backend edits need a Space restart which you should tell the user.',
|
| 84 |
'',
|
| 85 |
+
'Approved tools:',
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
toolSummary,
|
| 87 |
].join('\n');
|
| 88 |
}
|
src/inferenceClient.js
CHANGED
|
@@ -2,7 +2,7 @@ const API_URL = process.env.INFERENCE_API_URL;
|
|
| 2 |
const API_KEY = process.env.INFERENCE_API_KEY;
|
| 3 |
const FETCH_TIMEOUT = 30000;
|
| 4 |
|
| 5 |
-
let currentModel = process.env.INFERENCE_MODEL || '
|
| 6 |
|
| 7 |
const AVAILABLE_MODELS = [
|
| 8 |
'lightning',
|
|
|
|
| 2 |
const API_KEY = process.env.INFERENCE_API_KEY;
|
| 3 |
const FETCH_TIMEOUT = 30000;
|
| 4 |
|
| 5 |
+
let currentModel = process.env.INFERENCE_MODEL || 'llama-3.1-8b-instant';
|
| 6 |
|
| 7 |
const AVAILABLE_MODELS = [
|
| 8 |
'lightning',
|