UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

28 lines (27 loc) • 1.74 kB
import { randomBytes } from "node:crypto"; import { sendMessageContinuationTier } from "../../agents/send-message-tool.js"; function buildTier3ReviveSpawn(delegationForRevive, enrichSpecToolCtx) { if (delegationForRevive === undefined) return undefined; return async (req) => { const out = await delegationForRevive.execute({ description: req.row.description ?? "revived teammate", prompt: req.prompt, run_in_background: true, ...(req.row.agentType !== undefined ? { subagent_type: req.row.agentType } : {}), ...(req.row.name !== undefined ? { name: req.row.name } : {}), ...(req.row.model !== undefined ? { model: req.row.model } : {}), }, enrichSpecToolCtx({ toolCallId: `rv-${randomBytes(8).toString("hex")}`, reviveClaim: { row: req.row, rev: req.rev, ...(req.peerSeed !== undefined ? { peerSeed: req.peerSeed } : {}) } })); const o = (typeof out === "string" ? { content: out } : out); return { content: typeof o.content === "string" ? o.content : JSON.stringify(o.content), ...(o.isError === true ? { isError: true } : {}), ...(o.details !== undefined ? { details: o.details } : {}), }; }; } export function sendMessageContinuationSeats(seats) { const delegationForRevive = seats.specTools.find((t) => t.agentListing !== undefined); const reviveSpawn = seats.agentStore !== undefined && seats.mailbox !== undefined ? buildTier3ReviveSpawn(delegationForRevive, seats.enrichSpecToolCtx) : undefined; return { reviveSpawn, tier: sendMessageContinuationTier({ agentStore: seats.agentStore, mailbox: seats.mailbox, reviveSpawn, runner: seats.runner }) }; }