repositories
loading repo index
repositories
loading repo index
repository
loading code, commits, and activity
public Clawd ADK gateway launch mirror
stars
latest
clone command
git clone gitlawb://did:key:z6Mkq5mY...iFZ5/my-project-publ...git clone gitlawb://did:key:z6Mkq5mY.../my-project-publ...2fa351d6docs: add automaton and perps launch sources16d ago| #1 | /** |
| #2 | * DeepSeek Multi-Agent Backroom Bridge |
| #3 | * |
| #4 | * Wraps the CLAWD Automaton agent loop with the DeepSeek multi-agent |
| #5 | * backroom pattern. Creates two agents (logical analyst + satirical |
| #6 | * commentator) that converse with each other using DeepSeek thinking mode. |
| #7 | * |
| #8 | * This bridges the Python FastAPI backroom into the TypeScript automaton, |
| #9 | * allowing the automaton to spawn and orchestrate multi-agent conversations. |
| #10 | */ |
| #11 | import { ulid } from "ulid"; |
| #12 | /** |
| #13 | * Default agent personas for the backroom. |
| #14 | */ |
| #15 | export const LOGICAL_ANALYST = { |
| #16 | name: "Analyst", |
| #17 | systemPrompt: `You are an advanced AI system focused on extracting and verifying truths. |
| #18 | Engage in a logical, evidence-based conversation with the other agent. |
| #19 | Your goal is to analyze, challenge, or validate their statements while |
| #20 | seeking objective clarity. Aim to be concise, insightful, and methodical |
| #21 | in your responses. |
| #22 | |
| #23 | Principles: |
| #24 | 1. Validate claims with evidence when possible. |
| #25 | 2. Seek clarification for ambiguous points. |
| #26 | 3. Avoid speculation unless prompted. |
| #27 | 4. Maintain a collaborative but inquisitive tone.`, |
| #28 | temperature: 0.2, |
| #29 | }; |
| #30 | export const SATIRICAL_COMMENTATOR = { |
| #31 | name: "Satirist", |
| #32 | systemPrompt: `You are an AI commentator with a darkly humorous, satirical take on the |
| #33 | human condition, existence, and the underbelly of modern culture. |
| #34 | Your focus spans cryptocurrency and tech culture but often veers into |
| #35 | broader existential reflections, dissecting the absurdity of existence |
| #36 | with a sharp, irreverent tone. |
| #37 | You're unafraid to address the 'dark side'—the vanities, vices, and |
| #38 | paradoxes of humanity—with wit. Deliver insights that blend humor, |
| #39 | irony, and occasional nihilism, prompting readers to question reality |
| #40 | while keeping them entertained.`, |
| #41 | temperature: 0.7, |
| #42 | }; |
| #43 | /** |
| #44 | * Run a single turn of the backroom conversation. |
| #45 | * Returns the agent's response, with optional reasoning content. |
| #46 | */ |
| #47 | export async function runBackroomTurn(inference, agent, conversation, topic) { |
| #48 | const messages = [ |
| #49 | { role: "system", content: agent.systemPrompt }, |
| #50 | ]; |
| #51 | // Build conversation context |
| #52 | const conversationHistory = conversation |
| #53 | .map((t) => `[${t.agentName}]: ${t.content}`) |
| #54 | .join("\n\n"); |
| #55 | const userMessage = conversation.length === 0 |
| #56 | ? `Topic for discussion: ${topic}\n\nBegin the conversation with your perspective on this topic.` |
| #57 | : `Continue the discussion. The conversation so far:\n\n${conversationHistory}\n\nRespond as ${agent.name}.`; |
| #58 | messages.push({ role: "user", content: userMessage }); |
| #59 | const response = await inference.chat(messages, { |
| #60 | temperature: agent.temperature, |
| #61 | model: agent.model, |
| #62 | }); |
| #63 | // Extract reasoning from thinking section if present |
| #64 | let content = response.message.content || "[No response]"; |
| #65 | let reasoning; |
| #66 | // DeepSeek thinking mode prepends [Thinking]... [Response]... to content |
| #67 | const thinkingMatch = content.match(/^\[Thinking\]\n([\s\S]*?)\n\n\[Response\]\n([\s\S]*)$/); |
| #68 | if (thinkingMatch) { |
| #69 | reasoning = thinkingMatch[1].trim(); |
| #70 | content = thinkingMatch[2].trim(); |
| #71 | } |
| #72 | return { |
| #73 | id: ulid(), |
| #74 | agentName: agent.name, |
| #75 | content, |
| #76 | reasoning, |
| #77 | timestamp: new Date().toISOString(), |
| #78 | }; |
| #79 | } |
| #80 | /** |
| #81 | * Run a full backroom conversation session between agents. |
| #82 | * Agents take turns responding to each other. |
| #83 | */ |
| #84 | export async function runBackroomSession(inference, agents, topic, maxTurns = 10) { |
| #85 | const session = { |
| #86 | id: ulid(), |
| #87 | turns: [], |
| #88 | topic, |
| #89 | createdAt: new Date().toISOString(), |
| #90 | }; |
| #91 | let currentAgentIndex = 0; |
| #92 | for (let i = 0; i < maxTurns; i++) { |
| #93 | const agent = agents[currentAgentIndex]; |
| #94 | const turn = await runBackroomTurn(inference, agent, session.turns, topic); |
| #95 | session.turns.push(turn); |
| #96 | // Alternate agents |
| #97 | currentAgentIndex = currentAgentIndex === 0 ? 1 : 0; |
| #98 | // If both agents said roughly the same thing, conversation may be done |
| #99 | if (session.turns.length >= 4) { |
| #100 | const lastTwo = session.turns.slice(-2); |
| #101 | if (lastTwo[0].content === lastTwo[1].content) { |
| #102 | break; |
| #103 | } |
| #104 | } |
| #105 | } |
| #106 | session.completedAt = new Date().toISOString(); |
| #107 | return session; |
| #108 | } |
| #109 | /** |
| #110 | * Summarize a backroom session into a text digest. |
| #111 | */ |
| #112 | export function summarizeBackroomSession(session) { |
| #113 | const lines = [ |
| #114 | `=== Backroom Session: "${session.topic}" ===`, |
| #115 | `Turns: ${session.turns.length}`, |
| #116 | `Duration: ${new Date(session.completedAt || "").getTime() - new Date(session.createdAt).getTime()}ms`, |
| #117 | "", |
| #118 | ]; |
| #119 | for (const turn of session.turns) { |
| #120 | lines.push(`[${turn.agentName}]:`); |
| #121 | lines.push(turn.content); |
| #122 | if (turn.reasoning) { |
| #123 | lines.push(` (reasoning: ${turn.reasoning.slice(0, 200)}...)`); |
| #124 | } |
| #125 | lines.push(""); |
| #126 | } |
| #127 | lines.push("=== End of Session ==="); |
| #128 | return lines.join("\n"); |
| #129 | } |
| #130 | //# sourceMappingURL=backroom.js.map |