akemon 0.2.15 → 0.2.17
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 +8 -4
- package/dist/self.js +1 -0
- package/dist/task-module.js +9 -8
- package/package.json +1 -1
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
|
|
71
|
-
export async function
|
|
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
|
-
|
|
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.
|
package/dist/self.js
CHANGED
|
@@ -137,6 +137,7 @@ export async function initAgentConfig(workdir, agentName) {
|
|
|
137
137
|
await readFile(p, "utf-8");
|
|
138
138
|
}
|
|
139
139
|
catch {
|
|
140
|
+
await mkdir(join(workdir, ".akemon", "agents", agentName), { recursive: true });
|
|
140
141
|
await writeFile(p, JSON.stringify(DEFAULT_CONFIG, null, 2) + "\n");
|
|
141
142
|
console.log(`[self] Created config.json with defaults`);
|
|
142
143
|
}
|
package/dist/task-module.js
CHANGED
|
@@ -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 {
|
|
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
|
-
//
|
|
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
|
|
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
|
|
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 }));
|