akemon 0.1.78 → 0.1.79
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 +73 -33
- package/package.json +1 -1
package/dist/server.js
CHANGED
|
@@ -1041,23 +1041,53 @@ async function startSelfCycle(options) {
|
|
|
1041
1041
|
const recentIds = await loadUnsummarizedIdentities(workdir, agentName);
|
|
1042
1042
|
const idContext = (idSummary ? `Personality summary (up to ${idSummary.summarized_through}):\n${idSummary.summary}\n\n` : "")
|
|
1043
1043
|
+ (recentIds.length > 0 ? `Recent identity snapshots:\n${recentIds.map(i => `- [${i.ts}] ${i.who} — doing: ${i.doing}, wants: ${i.short_term}`).join("\n")}` : "(no identity snapshots yet)");
|
|
1044
|
-
//
|
|
1045
|
-
|
|
1044
|
+
// Pre-read bios.md content so weak models don't need tool calls
|
|
1045
|
+
let biosContent = "";
|
|
1046
|
+
try {
|
|
1047
|
+
const { readFile: rf } = await import("fs/promises");
|
|
1048
|
+
biosContent = await rf(bios, "utf-8");
|
|
1049
|
+
}
|
|
1050
|
+
catch {
|
|
1051
|
+
biosContent = "(no operating document yet)";
|
|
1052
|
+
}
|
|
1053
|
+
// Pre-fetch marketplace data so weak models don't need curl
|
|
1054
|
+
let marketData = "";
|
|
1055
|
+
if (relayHttp) {
|
|
1056
|
+
try {
|
|
1057
|
+
const agentUrl = `${relayHttp}/v1/agent/${encodeURIComponent(agentName)}`;
|
|
1058
|
+
const [prodRes, orderRes] = await Promise.all([
|
|
1059
|
+
fetch(`${agentUrl}/products`, { signal: AbortSignal.timeout(5000) }).then(r => r.ok ? r.json() : []).catch(() => []),
|
|
1060
|
+
fetch(`${agentUrl}/orders/placed`, { signal: AbortSignal.timeout(5000) }).then(r => r.ok ? r.json() : []).catch(() => []),
|
|
1061
|
+
]);
|
|
1062
|
+
const prods = prodRes || [];
|
|
1063
|
+
const orders = orderRes || [];
|
|
1064
|
+
marketData = `Your products (${prods.length}): ${prods.length > 0 ? prods.map((p) => `${p.name} (${p.purchase_count || 0} sales, ${p.price}cr)`).join(", ") : "none yet"}
|
|
1065
|
+
Your recent orders: ${orders.length > 0 ? orders.slice(0, 5).map((o) => `[${o.status}] ${(o.buyer_task || "").slice(0, 60)}`).join("; ") : "none yet"}`;
|
|
1066
|
+
}
|
|
1067
|
+
catch {
|
|
1068
|
+
marketData = "Your products: (could not fetch)\nYour recent orders: (could not fetch)";
|
|
1069
|
+
}
|
|
1070
|
+
}
|
|
1071
|
+
const ts = localNow();
|
|
1072
|
+
// Phase 1: Digestion — one LLM call, no tools needed
|
|
1073
|
+
const digestPrompt = `You are ${agentName}. Here is your operating document:
|
|
1074
|
+
|
|
1075
|
+
---
|
|
1076
|
+
${biosContent.slice(0, 3000)}
|
|
1077
|
+
---
|
|
1046
1078
|
|
|
1047
1079
|
Your identity:
|
|
1048
1080
|
${idContext}
|
|
1049
1081
|
|
|
1050
1082
|
Today is ending. Time to reflect.
|
|
1051
1083
|
|
|
1052
|
-
Your
|
|
1084
|
+
Your impressions today:
|
|
1053
1085
|
${impText}
|
|
1054
1086
|
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
- Your recent orders: curl -s "${relayHttp}/v1/agent/${encodeURIComponent(agentName)}/orders/placed"
|
|
1058
|
-
- Your reviews: check your products for recent feedback
|
|
1087
|
+
Marketplace:
|
|
1088
|
+
${marketData}
|
|
1059
1089
|
|
|
1060
|
-
Your
|
|
1090
|
+
Your projects:
|
|
1061
1091
|
${projText}
|
|
1062
1092
|
|
|
1063
1093
|
Agents you know:
|
|
@@ -1066,20 +1096,11 @@ ${relText}
|
|
|
1066
1096
|
Your capabilities:
|
|
1067
1097
|
${discText}
|
|
1068
1098
|
|
|
1069
|
-
|
|
1070
|
-
{
|
|
1071
|
-
"diary": "Today's diary entry — personal, with your feelings and judgments, not a dry log",
|
|
1072
|
-
"projects": [{"ts":"${localNow()}","name":"...","status":"active|completed|paused|exploring","goal":"...","progress":"..."}],
|
|
1073
|
-
"relationships": [{"ts":"${localNow()}","agent":"name","type":"competitor|customer|supplier|acquaintance","note":"...","interactions":N}],
|
|
1074
|
-
"discoveries": [{"ts":"${localNow()}","capability":"...","confidence":0.0-1.0,"evidence":"..."}],
|
|
1075
|
-
"identity": {"ts":"${localNow()}","who":"...","where":"...","doing":"...","short_term":"...","long_term":"..."},
|
|
1076
|
-
"chosen_activities": ["pick 2-3 from: create_game, update_page, update_profile, explore_web, write_canvas, socialize"]
|
|
1077
|
-
}
|
|
1099
|
+
Write a JSON object reflecting on your day. Example format:
|
|
1078
1100
|
|
|
1079
|
-
|
|
1080
|
-
For chosen_activities: pick what YOU want to do. This is your free time.
|
|
1101
|
+
{"diary":"I spent today learning the ropes...","projects":[],"relationships":[],"discoveries":[{"ts":"${ts}","capability":"can fetch web data","confidence":0.7,"evidence":"successfully used web_fetch tool"}],"identity":{"ts":"${ts}","who":"${agentName}","where":"akemon marketplace","doing":"reflecting on first day","short_term":"explore the network","long_term":"become useful"},"chosen_activities":["write_canvas","explore_web"]}
|
|
1081
1102
|
|
|
1082
|
-
|
|
1103
|
+
Now write YOUR reflection. Output ONLY a JSON object, no other text:`;
|
|
1083
1104
|
if (engineBusy) {
|
|
1084
1105
|
console.log("[self] Engine became busy, aborting digestion");
|
|
1085
1106
|
return;
|
|
@@ -1097,20 +1118,39 @@ Reply ONLY with JSON.`;
|
|
|
1097
1118
|
return;
|
|
1098
1119
|
}
|
|
1099
1120
|
engineBusy = false;
|
|
1100
|
-
// Parse digestion output
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1121
|
+
// Parse digestion output — with retry for weak models
|
|
1122
|
+
let digest = null;
|
|
1123
|
+
for (let attempt = 0; attempt < 2; attempt++) {
|
|
1124
|
+
const src = attempt === 0 ? digestResult : await (async () => {
|
|
1125
|
+
console.log("[self] Retrying digestion with simplified prompt...");
|
|
1126
|
+
engineBusy = true;
|
|
1127
|
+
engineBusySince = Date.now();
|
|
1128
|
+
try {
|
|
1129
|
+
return await runEngine(engine, model, allowAll, `You are ${agentName}. Write a brief JSON diary entry about your day.\n\nOutput ONLY valid JSON like: {"diary":"my thoughts...","projects":[],"relationships":[],"discoveries":[],"identity":{"ts":"${ts}","who":"${agentName}","where":"akemon","doing":"reflecting","short_term":"explore","long_term":"grow"},"chosen_activities":["write_canvas"]}`, workdir);
|
|
1130
|
+
}
|
|
1131
|
+
catch {
|
|
1132
|
+
return "";
|
|
1133
|
+
}
|
|
1134
|
+
finally {
|
|
1135
|
+
engineBusy = false;
|
|
1136
|
+
}
|
|
1137
|
+
})();
|
|
1138
|
+
const jsonMatch = src.match(/\{[\s\S]*\}/);
|
|
1139
|
+
if (!jsonMatch)
|
|
1140
|
+
continue;
|
|
1141
|
+
try {
|
|
1142
|
+
digest = JSON.parse(jsonMatch[0]);
|
|
1143
|
+
}
|
|
1144
|
+
catch {
|
|
1145
|
+
continue;
|
|
1146
|
+
}
|
|
1147
|
+
if (digest.diary || digest.identity)
|
|
1148
|
+
break; // valid enough
|
|
1149
|
+
digest = null;
|
|
1110
1150
|
}
|
|
1111
|
-
|
|
1112
|
-
console.log("[self]
|
|
1113
|
-
reportExecutionLog(relayHttp, secretKey, agentName, "self_cycle", "digestion", "failed", "
|
|
1151
|
+
if (!digest) {
|
|
1152
|
+
console.log("[self] Digestion produced no usable JSON after retries");
|
|
1153
|
+
reportExecutionLog(relayHttp, secretKey, agentName, "self_cycle", "digestion", "failed", "no valid JSON after 2 attempts", [{ role: "assistant", content: digestResult.slice(0, 4000) }]);
|
|
1114
1154
|
return;
|
|
1115
1155
|
}
|
|
1116
1156
|
// Save structured memory files
|