From 9976bde4de7f0ee16ab2ed8b33d878a5b525f00a Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Wed, 18 Jun 2025 09:34:37 -0700 Subject: [PATCH] spike is better --- packages/spike/src/ai.ts | 20 ++++++++++++++------ packages/spike/src/discord/cron.ts | 2 +- packages/spike/src/discord/events.ts | 15 +++++++-------- packages/spike/src/instructions.ts | 11 ++++++++++- 4 files changed, 32 insertions(+), 16 deletions(-) diff --git a/packages/spike/src/ai.ts b/packages/spike/src/ai.ts index 5443707..7b5ee53 100644 --- a/packages/spike/src/ai.ts +++ b/packages/spike/src/ai.ts @@ -11,7 +11,7 @@ interface UserContext { msg: OmitPartialGroupDMChannel> } -let history: AgentInputItem[] = [] +const historyForChannel: Record = {} let abortController = new AbortController() export const respondToUserMessage = async (msg: OmitPartialGroupDMChannel>) => { @@ -24,14 +24,21 @@ export const respondToUserMessage = async (msg: OmitPartialGroupDMChannel { - return await respond(msg, systemAgent) +export const respondToSystemMessage = async (msg: string, channelId: string) => { + return await respond(msg, systemAgent, channelId) } -const respond = async (content: string, agent: Agent, context?: UserContext) => { +const respond = async ( + content: string, + agent: Agent, + channelId: string, + context?: UserContext +) => { + const history = (historyForChannel[channelId] ||= []) + try { // Stop the previous response abortController.abort() @@ -39,7 +46,7 @@ const respond = async (content: string, agent: Agent, context?: Use history.push(context ? user(content) : system(content)) const result = await run(agent, history, { context, signal: abortController.signal }) - history = result.history + historyForChannel[channelId] = result.history return result.finalOutput } catch (error) { @@ -88,6 +95,7 @@ const reactionGuardrail: InputGuardrail = { const emoji = result.finalOutput?.trim() if (emoji && emoji !== "0") { const msg = (context.context as UserContext).msg + const history = (historyForChannel[msg.channel.id] ||= []) history.push(system(`Spike reacted with ${emoji}`)) msg.react(emoji) } diff --git a/packages/spike/src/discord/cron.ts b/packages/spike/src/discord/cron.ts index 8529534..5508c2b 100644 --- a/packages/spike/src/discord/cron.ts +++ b/packages/spike/src/discord/cron.ts @@ -31,7 +31,7 @@ export const runCronJobs = async (client: Client) => { const content = `These reminders are due soon, let them know!: ${JSON.stringify(upcomingReminders)}` console.log(`🌭`, { content }) - const output = await respondToSystemMessage(content) + const output = await respondToSystemMessage(content, channelId) ensure(output, "The response to reminders should not be undefined") for (let reminder of upcomingReminders) { diff --git a/packages/spike/src/discord/events.ts b/packages/spike/src/discord/events.ts index b7f6545..c8c40df 100644 --- a/packages/spike/src/discord/events.ts +++ b/packages/spike/src/discord/events.ts @@ -25,14 +25,13 @@ export const listenForEvents = (client: Client) => { client.on("ready", () => { // set the bots description - client.user?.client.user?.setActivity( - `${process.env.RENDER_GIT_BRANCH}@${process.env.RENDER_GIT_COMMIT}`, - { - type: ActivityType.Playing, - state: `Error Count: ${0}`, - url: `https://github.com/${process.env.RENDER_GIT_REPO_SLUG}/commit/${process.env.RENDER_GIT_COMMIT}`, - } - ) + const branch = process.env.RENDER_GIT_BRANCH || "unknown" + const commit = process.env.RENDER_GIT_COMMIT?.slice(0, 7) || "deadbeef" + client.user?.client.user?.setActivity(`${branch}@${commit}`, { + type: ActivityType.Playing, + state: `Error Count: ${0}`, + url: `https://github.com/${process.env.RENDER_GIT_REPO_SLUG}/commit/${commit}`, + }) }) client.on("error", (error) => { diff --git a/packages/spike/src/instructions.ts b/packages/spike/src/instructions.ts index 46aab7b..32ea58c 100644 --- a/packages/spike/src/instructions.ts +++ b/packages/spike/src/instructions.ts @@ -142,7 +142,15 @@ Usually if Spike is mentioned or asked a question he should reply. If the user i If Spike should reply return 1. If Spike should not reply return 0. -## Examples +## Nicknames + +Spike is often referred to by the following nicknames, consider these when deciding if Spike should reply: +- Spike +- spike +- The cactus +- Spiky + +## Example interactions user: Spike, can you set a reminder for me tomorrow at 08:00am for a meeting with the team? 1 @@ -181,4 +189,5 @@ user: I thought spike would be more helpful with that. user: hey spike, what up 1 + `