Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

Oracle: personal conviction-drop exit alerts

nirholas513036406318
diff --git a/api/_lib/oracle/alerts.js b/api/_lib/oracle/alerts.js
index 8c8c0d06d..1ae18fcd7 100644
--- a/api/_lib/oracle/alerts.js
+++ b/api/_lib/oracle/alerts.js
@@ -261,6 +261,35 @@ export async function alertPersonalSignal(chatId, coin, minScore) {
await sendTo(chatId, text);
}
+/**
+ * Fire a personal conviction-drop warning when a coin's score falls
+ * significantly below the subscriber's entry conviction AND below their
+ * min_score threshold. Signals that the thesis for an open position is
+ * weakening — the subscriber should reassess.
+ *
+ * @param {string} chatId
+ * @param {{ symbol:string, mint:string, newScore:number, newTier:string, entryScore:number, minScore:number }} drop
+ */
+export async function alertPersonalConvictionDrop(chatId, drop) {
+ const token = process.env.TELEGRAM_BOT_TOKEN;
+ if (!token || !chatId) return;
+
+ const sym = escHtml((drop.symbol || drop.mint.slice(0, 6)).toUpperCase());
+ const newTier = escHtml(drop.newTier || 'unknown');
+ const emoji = TIER_EMOJI[drop.newTier] || '⚪';
+ const delta = Math.round(drop.entryScore - drop.newScore);
+ const mintLink = encodeURIComponent(drop.mint);
+
+ const text = [
+ `⚠️ <b>$${sym}</b> conviction weakened`,
+ `${emoji} ${newTier} · score <b>${drop.newScore}</b> (was ${drop.entryScore} at entry, −${delta} pts)`,
+ `Below your threshold of ${drop.minScore} — consider reviewing your position.`,
+ `<a href="https://pump.fun/coin/${mintLink}">pump.fun</a> · <a href="https://three.ws/oracle?mint=${mintLink}">Oracle ↗</a>`,
+ ].join('\n');
+
+ await sendTo(chatId, text);
+}
+
/** Send to a specific chat ID (not the platform channel). */
async function sendTo(chatId, text) {
const token = process.env.TELEGRAM_BOT_TOKEN;
diff --git a/workers/oracle/agent-loop.js b/workers/oracle/agent-loop.js
index 94b35ac00..73ab1647e 100644
--- a/workers/oracle/agent-loop.js
+++ b/workers/oracle/agent-loop.js
@@ -9,11 +9,16 @@ import { sql } from '../../api/_lib/db.js';
import { log } from './log.js';
import { evaluateWatch } from '../../api/_lib/oracle/agent-eval.js';
import { executeAction, agentBudget } from './executor.js';
-import { alertAgentEntry, alertPersonalEntry, alertPersonalSignal } from '../../api/_lib/oracle/alerts.js';
+import { alertAgentEntry, alertPersonalEntry, alertPersonalSignal, alertPersonalConvictionDrop } from '../../api/_lib/oracle/alerts.js';
// Module cursor — only consider verdicts scored since the last pass.
let cursor = new Date(Date.now() - 60_000).toISOString();
+// In-memory dedup for conviction-drop alerts: Set of "agentId:mint" pairs alerted
+// in this process lifetime. Prevents spam when the same coin stays below threshold
+// across multiple score passes.
+const _dropAlerted = new Set();
+
async function armedWatches(network) {
return sql`
select w.agent_id, w.user_id, w.network, w.armed, w.mode, w.min_score, w.min_tier,
@@ -44,6 +49,31 @@ export async function freshlyScored(network, sinceIso, limit = 60) {
}));
}
+/**
+ * Find open agent positions that have been re-scored in this pass and whose
+ * new conviction has dropped significantly (≥5 pts below entry conviction)
+ * AND is now below the agent's min_score. Returns one row per (agent_id, mint).
+ * Used for personal conviction-drop exit warnings.
+ */
+async function droppedConvictionPositions(network, mints) {
+ if (!mints.length) return [];
+ return sql`
+ select a.agent_id, a.mint, a.conviction as entry_conviction,
+ oc.score as new_score, oc.tier as new_tier, oc.symbol,
+ w.min_score, w.telegram_chat_id
+ from oracle_watch_actions a
+ join oracle_conviction oc on oc.mint = a.mint and oc.network = a.network
+ join oracle_agent_watch w on w.agent_id = a.agent_id and w.network = a.network
+ where a.network = ${network}
+ and a.mint = any(${mints}::text[])
+ and (a.outcome is null or a.outcome = 'open')
+ and w.armed = true
+ and w.telegram_chat_id is not null
+ and oc.score < w.min_score
+ and (a.conviction::numeric - oc.score::numeric) >= 5
+ `.catch((e) => { log.warn('droppedConvictionPositions query failed:', e.message); return []; });
+}
+
async function alreadyActed(agentId, mint, network) {
const r = await sql`
select 1 from oracle_watch_actions
@@ -63,6 +93,23 @@ export async function actOnFreshCoins(cfg, coins) {
const watches = await armedWatches(cfg.network);
if (!watches.length) return 0;
+ // Conviction-drop exit warnings — batch, one query for all fresh mints.
+ const freshMints = coins.map((c) => c.mint);
+ const drops = await droppedConvictionPositions(cfg.network, freshMints);
+ for (const d of drops) {
+ const key = `${d.agent_id}:${d.mint}`;
+ if (_dropAlerted.has(key)) continue;
+ _dropAlerted.add(key);
+ alertPersonalConvictionDrop(d.telegram_chat_id, {
+ symbol: d.symbol,
+ mint: d.mint,
+ newScore: Number(d.new_score),
+ newTier: d.new_tier,
+ entryScore: Number(d.entry_conviction),
+ minScore: Number(d.min_score),
+ }).catch(() => {});
+ }
+
let acted = 0;
const liveEntries = [];
for (const watch of watches) {