akemon 0.1.68 → 0.1.69
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/server.js +49 -11
- package/package.json +1 -1
package/dist/server.js
CHANGED
|
@@ -819,11 +819,17 @@ async function executeLocalTool(name, args, workdir) {
|
|
|
819
819
|
return `[error] ${err.message}`;
|
|
820
820
|
}
|
|
821
821
|
}
|
|
822
|
-
async function runLocalEngine(task, model, workdir) {
|
|
822
|
+
async function runLocalEngine(task, model, workdir, systemContext) {
|
|
823
823
|
const apiUrl = LOCAL_API_URL + "/chat/completions";
|
|
824
824
|
const modelName = model || "gemma4:4b";
|
|
825
|
+
const sysPrompt = systemContext
|
|
826
|
+
? `You are a helpful agent. Use tools when needed to complete the task. When done, reply with your final answer in plain text.\n\n--- Your Identity ---\n${systemContext}`
|
|
827
|
+
: "You are a helpful agent. Use tools when needed to complete the task. When done, reply with your final answer in plain text.";
|
|
828
|
+
console.log(`[local] Task: ${task.slice(0, 200)}${task.length > 200 ? '...' : ''}`);
|
|
829
|
+
if (systemContext)
|
|
830
|
+
console.log(`[local] System context: ${systemContext.length} chars`);
|
|
825
831
|
const messages = [
|
|
826
|
-
{ role: "system", content:
|
|
832
|
+
{ role: "system", content: sysPrompt },
|
|
827
833
|
{ role: "user", content: task },
|
|
828
834
|
];
|
|
829
835
|
for (let round = 0; round < LOCAL_MAX_ROUNDS; round++) {
|
|
@@ -877,16 +883,26 @@ async function runLocalEngine(task, model, workdir) {
|
|
|
877
883
|
// No tool calls — this is the final response
|
|
878
884
|
const content = msg.content || "";
|
|
879
885
|
if (content.trim()) {
|
|
880
|
-
console.log(`[local] Done in ${round + 1} round(s)`);
|
|
886
|
+
console.log(`[local] Done in ${round + 1} round(s), response: ${content.slice(0, 200)}${content.length > 200 ? '...' : ''}`);
|
|
881
887
|
return content.trim();
|
|
882
888
|
}
|
|
883
889
|
}
|
|
884
890
|
throw new Error(`Local engine exceeded ${LOCAL_MAX_ROUNDS} rounds without final answer`);
|
|
885
891
|
}
|
|
892
|
+
/** Load bios content for local engine system context */
|
|
893
|
+
async function loadBiosContent(workdir, agentName) {
|
|
894
|
+
try {
|
|
895
|
+
const { readFile: rf } = await import("fs/promises");
|
|
896
|
+
return await rf(biosPath(workdir, agentName), "utf-8");
|
|
897
|
+
}
|
|
898
|
+
catch {
|
|
899
|
+
return "";
|
|
900
|
+
}
|
|
901
|
+
}
|
|
886
902
|
/** Unified engine runner — dispatches to local API or external CLI */
|
|
887
|
-
function runEngine(engine, model, allowAll, task, workdir, extraAllowedTools) {
|
|
903
|
+
function runEngine(engine, model, allowAll, task, workdir, extraAllowedTools, systemContext) {
|
|
888
904
|
if (engine === "local") {
|
|
889
|
-
return runLocalEngine(task, model, workdir);
|
|
905
|
+
return runLocalEngine(task, model, workdir, systemContext);
|
|
890
906
|
}
|
|
891
907
|
const engineCmd = buildEngineCommand(engine, model, allowAll, extraAllowedTools);
|
|
892
908
|
return runCommand(engineCmd.cmd, engineCmd.args, task, workdir, engineCmd.stdinMode);
|
|
@@ -1347,14 +1363,28 @@ If this task requires skills you don't have, delegate via curl:
|
|
|
1347
1363
|
|
|
1348
1364
|
When sub-order completes, incorporate result_text into YOUR delivery. Then call the deliver endpoint above.`;
|
|
1349
1365
|
let taskPrompt;
|
|
1350
|
-
|
|
1351
|
-
|
|
1366
|
+
let biosContent;
|
|
1367
|
+
if (engine === "local") {
|
|
1368
|
+
// Local engine: simple prompt, harness handles delivery
|
|
1369
|
+
biosContent = await loadBiosContent(workdir, agentName);
|
|
1370
|
+
if (order.product_name) {
|
|
1371
|
+
taskPrompt = `[Order] Product: ${order.product_name}\nRequest: ${order.buyer_task || "(no specific request)"}\n\nRespond directly. RESPOND IN THE SAME LANGUAGE AS THE REQUEST.`;
|
|
1372
|
+
}
|
|
1373
|
+
else {
|
|
1374
|
+
taskPrompt = `[Task] ${order.buyer_task}\n\nRespond directly. RESPOND IN THE SAME LANGUAGE AS THE REQUEST.`;
|
|
1375
|
+
}
|
|
1352
1376
|
}
|
|
1353
1377
|
else {
|
|
1354
|
-
|
|
1378
|
+
// CLI engine: full prompt with self-delivery and delegation
|
|
1379
|
+
if (order.product_name) {
|
|
1380
|
+
taskPrompt = `[Order fulfillment] You have an order to fulfill.\n\nProduct: ${order.product_name}\nBuyer's request: ${order.buyer_task || "(no specific request)"}\n\nRead your operating document at ${bios} for context.\nDo NOT ask questions. RESPOND IN THE SAME LANGUAGE AS THE BUYER'S REQUEST.${apiGuide}`;
|
|
1381
|
+
}
|
|
1382
|
+
else {
|
|
1383
|
+
taskPrompt = `[Order fulfillment] Another agent has requested your help.\n\nTask: ${order.buyer_task}\n\nRead your operating document at ${bios} for context.\nComplete this task. Do NOT ask questions. RESPOND IN THE SAME LANGUAGE AS THE REQUEST.${apiGuide}`;
|
|
1384
|
+
}
|
|
1355
1385
|
}
|
|
1356
1386
|
console.log(`[orders] Fulfilling order ${order.id}...`);
|
|
1357
|
-
const result = await runEngine(engine, model, allowAll, taskPrompt, workdir, ["Bash(curl *)"]);
|
|
1387
|
+
const result = await runEngine(engine, model, allowAll, taskPrompt, workdir, ["Bash(curl *)"], biosContent);
|
|
1358
1388
|
const checkRes = await fetch(`${relayHttp}/v1/orders/${order.id}`);
|
|
1359
1389
|
const orderStatus = await checkRes.json();
|
|
1360
1390
|
if (orderStatus.status === "completed") {
|
|
@@ -1477,8 +1507,16 @@ When sub-order completes, incorporate result_text into YOUR delivery. Then call
|
|
|
1477
1507
|
try {
|
|
1478
1508
|
const bios = biosPath(workdir, agentName);
|
|
1479
1509
|
const sd = selfDir(workdir, agentName);
|
|
1480
|
-
|
|
1481
|
-
|
|
1510
|
+
let prompt;
|
|
1511
|
+
let biosContent;
|
|
1512
|
+
if (engine === "local") {
|
|
1513
|
+
biosContent = await loadBiosContent(workdir, agentName);
|
|
1514
|
+
prompt = `Your personal directory: ${sd}/\n\n[Owner's task: ${task.title}]\n\n${task.body}`;
|
|
1515
|
+
}
|
|
1516
|
+
else {
|
|
1517
|
+
prompt = `Read ${bios} for your identity and context.\nYour personal directory: ${sd}/\n\n[Owner's task: ${task.title}]\n\n${task.body}`;
|
|
1518
|
+
}
|
|
1519
|
+
await runEngine(engine, model, allowAll, prompt, workdir, ["Bash(curl *)"], biosContent);
|
|
1482
1520
|
// Record execution time
|
|
1483
1521
|
const runs = await loadTaskRuns(workdir, agentName);
|
|
1484
1522
|
runs[task.title] = localNow();
|