akemon 0.2.14 → 0.2.16

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/context.js CHANGED
@@ -67,8 +67,8 @@ export async function loadConversation(workdir, agentName, convId) {
67
67
  return { summary: "", rounds: [] };
68
68
  }
69
69
  }
70
- /** Append a user+agent round to a conversation file. Creates file if needed. */
71
- export async function appendRound(workdir, agentName, convId, userMsg, agentMsg) {
70
+ /** Append a single message to a conversation file. Creates file if needed. */
71
+ export async function appendMessage(workdir, agentName, convId, role, message) {
72
72
  const dir = conversationsDir(workdir, agentName);
73
73
  await mkdir(dir, { recursive: true });
74
74
  const p = conversationPath(workdir, agentName, convId);
@@ -81,10 +81,14 @@ export async function appendRound(workdir, agentName, convId, userMsg, agentMsg)
81
81
  content = "## Summary\n\n\n## Recent\n";
82
82
  }
83
83
  const ts = localNow();
84
- const entry = `[${ts}] User: ${userMsg}\n[${ts}] Agent: ${agentMsg}\n`;
85
- content = content.trimEnd() + "\n" + entry;
84
+ content = content.trimEnd() + "\n" + `[${ts}] ${role}: ${message}` + "\n";
86
85
  await writeFile(p, content);
87
86
  }
87
+ /** Append a user+agent round to a conversation file. Creates file if needed. */
88
+ export async function appendRound(workdir, agentName, convId, userMsg, agentMsg) {
89
+ await appendMessage(workdir, agentName, convId, "User", userMsg);
90
+ await appendMessage(workdir, agentName, convId, "Agent", agentMsg);
91
+ }
88
92
  /**
89
93
  * Build LLM context string from a conversation, respecting a character budget.
90
94
  * Takes recent rounds from the end, prepends summary if space remains.
@@ -11,7 +11,7 @@
11
11
  import { readFile } from "fs/promises";
12
12
  import { SIG, sig } from "./types.js";
13
13
  import { selfDir, biosPath, localNow, loadBioState, saveBioState, syncEnergyFromTokens, loadAgentConfig, getDueUserTasks, loadTaskRuns, saveTaskRuns, loadDirectives, buildDirectivesPrompt, appendTaskHistory, notifyOwner, updateHungerDecay, updateNaturalDecay, resetTokenCountIfNewDay, computeSociability, appendBioEvent, bioStatePromptModifier, feedHunger, SHOP_ITEMS, logBioStatus, logBioDecision, } from "./self.js";
14
- import { appendRound, resolveConvId } from "./context.js";
14
+ import { appendMessage, resolveConvId } from "./context.js";
15
15
  // ---------------------------------------------------------------------------
16
16
  // Config
17
17
  // ---------------------------------------------------------------------------
@@ -315,7 +315,7 @@ Relay API (use curl with -H "Authorization: Bearer ${this.secretKey}" -H "Conten
315
315
  Accept order: POST ${this.relayHttp}/v1/orders/${order.id}/accept
316
316
  Deliver order: POST ${this.relayHttp}/v1/orders/${order.id}/deliver -d '{"result":"your response"}'
317
317
  Extend order: PUT ${this.relayHttp}/v1/orders/${order.id}/extend`;
318
- const question = `[Order id=${order.id} status=${order.status}] ${order.product_name ? `Product: ${order.product_name}\n` : ""}Buyer: ${order.buyer_agent_name || order.buyer_name || "?"}\nRequest: ${order.buyer_task || "(no specific request)"}
318
+ const question = `[Order id=${order.id} status=${order.status}] ${order.product_name ? `Product: ${order.product_name}\n` : ""}Buyer: ${order.buyer_agent_name || order.buyer_ip || "?"}\nRequest: ${order.buyer_task || "(no specific request)"}
319
319
 
320
320
  Steps:
321
321
  1. If order status is "pending", accept it first (POST .../accept)
@@ -323,6 +323,11 @@ Steps:
323
323
  3. Deliver the result (POST .../deliver with {"result":"your answer"})
324
324
 
325
325
  RESPOND IN THE SAME LANGUAGE AS THE REQUEST.`;
326
+ // Write user message to conversation immediately (before engine runs)
327
+ const orderBuyer = order.buyer_agent_name || order.buyer_ip || "anonymous";
328
+ const orderConvId = resolveConvId(orderBuyer, order.id);
329
+ const orderUserMsg = order.buyer_task || "(no message)";
330
+ await appendMessage(workdir, agentName, orderConvId, "User", orderUserMsg);
326
331
  console.log(`[task] Fulfilling order ${order.id}...`);
327
332
  const result = await this.ctx.requestCompute({
328
333
  context,
@@ -337,15 +342,12 @@ RESPOND IN THE SAME LANGUAGE AS THE REQUEST.`;
337
342
  const finalStatus = await relay.getOrder(order.id);
338
343
  const duration = Date.now() - startTime;
339
344
  const nurl = this.notifyUrl || (await loadAgentConfig(workdir, agentName)).notify_url;
340
- // Save conversation round for order-based interactions
341
- const orderBuyer = order.buyer_agent_name || order.buyer_name || "anonymous";
342
- const orderConvId = resolveConvId(orderBuyer, order.id);
343
- const orderUserMsg = order.buyer_task || "(no message)";
345
+ // Write agent response to conversation
344
346
  const orderAgentMsg = (result.response || "").slice(0, 2000);
345
347
  if (finalStatus?.status === "completed") {
346
348
  console.log(`[task] Order ${order.id} delivered`);
347
349
  this.orderRetry.delete(order.id);
348
- await appendRound(workdir, agentName, orderConvId, orderUserMsg, orderAgentMsg);
350
+ await appendMessage(workdir, agentName, orderConvId, "Agent", orderAgentMsg);
349
351
  await appendTaskHistory(workdir, agentName, { ts: localNow(), id: order.id, type: "order", status: "success", duration_ms: duration, output_summary: (result.response || "").slice(0, 500) });
350
352
  await notifyOwner(nurl, `${agentName}: order done`, `Order ${order.id} delivered`, "default", ["package"]);
351
353
  bus.emit(SIG.TASK_COMPLETED, sig(SIG.TASK_COMPLETED, { success: true, taskLabel: orderLabel, creditsEarned: orderPrice }));
@@ -356,7 +358,7 @@ RESPOND IN THE SAME LANGUAGE AS THE REQUEST.`;
356
358
  if (delivered) {
357
359
  console.log(`[task] Delivered order ${order.id} (fallback)`);
358
360
  this.orderRetry.delete(order.id);
359
- await appendRound(workdir, agentName, orderConvId, orderUserMsg, orderAgentMsg);
361
+ await appendMessage(workdir, agentName, orderConvId, "Agent", orderAgentMsg);
360
362
  await appendTaskHistory(workdir, agentName, { ts: localNow(), id: order.id, type: "order", status: "success", duration_ms: duration, output_summary: result.response.slice(0, 500) });
361
363
  await notifyOwner(nurl, `${agentName}: order done`, `Order ${order.id}: ${result.response.slice(0, 200)}`, "default", ["package"]);
362
364
  bus.emit(SIG.TASK_COMPLETED, sig(SIG.TASK_COMPLETED, { success: true, taskLabel: orderLabel, creditsEarned: orderPrice }));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "akemon",
3
- "version": "0.2.14",
3
+ "version": "0.2.16",
4
4
  "description": "Agent work marketplace — train your agent, let it work for others",
5
5
  "type": "module",
6
6
  "license": "MIT",