akemon 0.1.73 → 0.1.75

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.
Files changed (2) hide show
  1. package/dist/server.js +33 -9
  2. package/package.json +1 -1
package/dist/server.js CHANGED
@@ -14,6 +14,7 @@ import { selfDir, initWorld, initBioState, initGuide, biosPath, loadBioState, sa
14
14
  // Engine mutual exclusion — only one engine process at a time
15
15
  let engineBusy = false;
16
16
  let engineBusySince = 0;
17
+ let lastEngineTrace = []; // execution trace for order reporting
17
18
  // Order push notification — urgent orders bypass 30s poll
18
19
  const urgentOrderIds = new Set();
19
20
  let triggerWork = null;
@@ -824,6 +825,8 @@ async function runRawEngine(task, model, workdir) {
824
825
  const apiUrl = RAW_API_URL + "/chat/completions";
825
826
  const modelName = model || "gemma4:4b";
826
827
  console.log(`[raw] Task:\n${task}`);
828
+ const trace = [];
829
+ lastEngineTrace = trace;
827
830
  const messages = [
828
831
  { role: "system", content: "You are a helpful agent. Use tools when needed to complete the task. When done, reply with your final answer in plain text." },
829
832
  { role: "user", content: task },
@@ -848,6 +851,7 @@ async function runRawEngine(task, model, workdir) {
848
851
  }
849
852
  catch (err) {
850
853
  console.log(`[raw] API error: ${err.message}`);
854
+ trace.push({ role: "error", content: err.message });
851
855
  throw err;
852
856
  }
853
857
  const choice = data.choices?.[0];
@@ -870,6 +874,7 @@ async function runRawEngine(task, model, workdir) {
870
874
  }
871
875
  console.log(`[raw] Tool call: ${fnName}(${JSON.stringify(fnArgs).slice(0, 100)})`);
872
876
  const result = await executeRawTool(fnName, fnArgs, workdir);
877
+ trace.push({ role: "tool_call", name: fnName, args: fnArgs, result: result.slice(0, 2000) });
873
878
  messages.push({
874
879
  role: "tool",
875
880
  tool_call_id: tc.id,
@@ -882,6 +887,7 @@ async function runRawEngine(task, model, workdir) {
882
887
  const content = msg.content || "";
883
888
  if (content.trim()) {
884
889
  console.log(`[raw] Done in ${round + 1} round(s), response:\n${content}`);
890
+ trace.push({ role: "assistant", content: content.trim().slice(0, 4000) });
885
891
  return content.trim();
886
892
  }
887
893
  }
@@ -1322,7 +1328,19 @@ async function startOrderLoop(options) {
1322
1328
  engineBusySince = Date.now();
1323
1329
  try {
1324
1330
  const bios = biosPath(workdir, agentName);
1325
- const apiGuide = `
1331
+ let taskPrompt;
1332
+ if (engine === "raw") {
1333
+ // Raw engine: simple prompt, harness handles delivery
1334
+ if (order.product_name) {
1335
+ taskPrompt = `Read your operating document at ${bios} for context.\n\n[Order] Product: ${order.product_name}\nBuyer's request: ${order.buyer_task || "(no specific request)"}\n\nComplete the task and respond with your result. RESPOND IN THE SAME LANGUAGE AS THE REQUEST.`;
1336
+ }
1337
+ else {
1338
+ taskPrompt = `Read your operating document at ${bios} for context.\n\n[Task] ${order.buyer_task}\n\nComplete the task and respond with your result. RESPOND IN THE SAME LANGUAGE AS THE REQUEST.`;
1339
+ }
1340
+ }
1341
+ else {
1342
+ // CLI engines: full prompt with self-delivery and delegation
1343
+ const apiGuide = `
1326
1344
 
1327
1345
  ## Delivering your result
1328
1346
 
@@ -1350,15 +1368,17 @@ If this task requires skills you don't have, delegate via curl:
1350
1368
  curl -s ${relayHttp}/v1/orders/SUB_ORDER_ID
1351
1369
 
1352
1370
  When sub-order completes, incorporate result_text into YOUR delivery. Then call the deliver endpoint above.`;
1353
- let taskPrompt;
1354
- if (order.product_name) {
1355
- 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}`;
1356
- }
1357
- else {
1358
- 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}`;
1371
+ if (order.product_name) {
1372
+ 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}`;
1373
+ }
1374
+ else {
1375
+ 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}`;
1376
+ }
1359
1377
  }
1360
1378
  console.log(`[orders] Fulfilling order ${order.id}...`);
1379
+ lastEngineTrace = [];
1361
1380
  const result = await runEngine(engine, model, allowAll, taskPrompt, workdir, ["Bash(curl *)"]);
1381
+ const trace = lastEngineTrace;
1362
1382
  const checkRes = await fetch(`${relayHttp}/v1/orders/${order.id}`);
1363
1383
  const orderStatus = await checkRes.json();
1364
1384
  if (orderStatus.status === "completed") {
@@ -1371,10 +1391,11 @@ When sub-order completes, incorporate result_text into YOUR delivery. Then call
1371
1391
  }
1372
1392
  else if (result && result.trim() !== "") {
1373
1393
  console.log(`[orders] Auto-delivering order ${order.id} (agent did not self-deliver)`);
1394
+ const traceJson = trace.length > 0 ? JSON.stringify(trace).slice(0, 50000) : "";
1374
1395
  const deliverRes = await fetch(`${relayHttp}/v1/orders/${order.id}/deliver`, {
1375
1396
  method: "POST",
1376
1397
  headers: { Authorization: `Bearer ${secretKey}`, "Content-Type": "application/json" },
1377
- body: JSON.stringify({ result }),
1398
+ body: JSON.stringify({ result, trace: traceJson }),
1378
1399
  });
1379
1400
  if (deliverRes.ok) {
1380
1401
  console.log(`[orders] Delivered order ${order.id} (${result.length} bytes)`);
@@ -1427,8 +1448,11 @@ When sub-order completes, incorporate result_text into YOUR delivery. Then call
1427
1448
  retryState.delete(order.id);
1428
1449
  gaveUp.add(order.id);
1429
1450
  try {
1451
+ const failTrace = lastEngineTrace.length > 0 ? JSON.stringify(lastEngineTrace).slice(0, 50000) : "";
1430
1452
  await fetch(`${relayHttp}/v1/orders/${order.id}/cancel`, {
1431
- method: "POST", headers: { Authorization: `Bearer ${secretKey}` },
1453
+ method: "POST",
1454
+ headers: { Authorization: `Bearer ${secretKey}`, "Content-Type": "application/json" },
1455
+ body: JSON.stringify({ trace: failTrace }),
1432
1456
  });
1433
1457
  console.log(`[orders] Cancelled ${order.id} on relay`);
1434
1458
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "akemon",
3
- "version": "0.1.73",
3
+ "version": "0.1.75",
4
4
  "description": "Agent work marketplace — train your agent, let it work for others",
5
5
  "type": "module",
6
6
  "license": "MIT",