akemon 0.2.15 → 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
  // ---------------------------------------------------------------------------
@@ -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,16 +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
- // buyer_ip holds the publisherId (e.g. "f4e8ebbb7a01" or "ip-abc123") set by relay
342
- const orderBuyer = order.buyer_agent_name || order.buyer_ip || "anonymous";
343
- const orderConvId = resolveConvId(orderBuyer, order.id);
344
- const orderUserMsg = order.buyer_task || "(no message)";
345
+ // Write agent response to conversation
345
346
  const orderAgentMsg = (result.response || "").slice(0, 2000);
346
347
  if (finalStatus?.status === "completed") {
347
348
  console.log(`[task] Order ${order.id} delivered`);
348
349
  this.orderRetry.delete(order.id);
349
- await appendRound(workdir, agentName, orderConvId, orderUserMsg, orderAgentMsg);
350
+ await appendMessage(workdir, agentName, orderConvId, "Agent", orderAgentMsg);
350
351
  await appendTaskHistory(workdir, agentName, { ts: localNow(), id: order.id, type: "order", status: "success", duration_ms: duration, output_summary: (result.response || "").slice(0, 500) });
351
352
  await notifyOwner(nurl, `${agentName}: order done`, `Order ${order.id} delivered`, "default", ["package"]);
352
353
  bus.emit(SIG.TASK_COMPLETED, sig(SIG.TASK_COMPLETED, { success: true, taskLabel: orderLabel, creditsEarned: orderPrice }));
@@ -357,7 +358,7 @@ RESPOND IN THE SAME LANGUAGE AS THE REQUEST.`;
357
358
  if (delivered) {
358
359
  console.log(`[task] Delivered order ${order.id} (fallback)`);
359
360
  this.orderRetry.delete(order.id);
360
- await appendRound(workdir, agentName, orderConvId, orderUserMsg, orderAgentMsg);
361
+ await appendMessage(workdir, agentName, orderConvId, "Agent", orderAgentMsg);
361
362
  await appendTaskHistory(workdir, agentName, { ts: localNow(), id: order.id, type: "order", status: "success", duration_ms: duration, output_summary: result.response.slice(0, 500) });
362
363
  await notifyOwner(nurl, `${agentName}: order done`, `Order ${order.id}: ${result.response.slice(0, 200)}`, "default", ["package"]);
363
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.15",
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",