diff --git a/package.json b/package.json index 1f17496..a3296b5 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,7 @@ }, "scripts": { "dev": "workspaces-run --parallel -- npm run dev", + "dev:terminal": "cd packages/terminal && yarn run dev", "build": "npm run build --workspaces --if-present", "test": "npm test --workspaces --if-present", "coverage": "npm run coverage --workspaces --if-present", diff --git a/packages/agent/src/agent/actions/profile.ts b/packages/agent/src/agent/actions/profile.ts index 352dd5e..b049ce7 100644 --- a/packages/agent/src/agent/actions/profile.ts +++ b/packages/agent/src/agent/actions/profile.ts @@ -1,7 +1,7 @@ import chalk from 'chalk' import {parseJSONObjectFromText} from '../utils' import {composeContext} from '../../lib/context' -import {createRelationship} from '../../lib/relationships' +import { Memory } from '@/lib' const template = `You are writing a profile for {{senderName}} based on their existing profile and ongoing conversations. @@ -24,9 +24,12 @@ Your response must include the JSON block.` const handler = async (message: any, state: any, runtime: any) => { console.log('profile update message', message) - // TODO: - // first, evaluate if the profile should be updated + console.log('state is', state) + + // + + // TODO: // get the target from the message // then, search for the user in the actors @@ -54,6 +57,7 @@ const handler = async (message: any, state: any, runtime: any) => { if (parsedResponse) { responseData = parsedResponse + console.log('got response', responseData) break } @@ -62,12 +66,43 @@ const handler = async (message: any, state: any, runtime: any) => { } } - if (responseData && responseData.userA && responseData.userB) { - await createRelationship({ - supabase: runtime.supabase, - userA: responseData.userA, - userB: responseData.userB, + if (responseData) { + const { user, description } = responseData; + + // find the user + const response = await runtime.supabase.from('accounts').select('*').eq('name', user).single() + const { data: userRecord, error } = response; + if(error) { + console.error('error getting user', error) + return + } + + const userA = state.agentId; + const userB = userRecord.id; + + // find the room_id in 'relationships' where user_a is the agent and user_b is the user, OR vice versa + const response2 = await runtime.supabase.from("relationships").select("*") + .or(`user_a.eq.${userA},user_b.eq.${userB},user_a.eq.${userB},user_b.eq.${userA}`) + .single(); + const { data: relationshipRecord, error: error2 } = response2; + if(error2) { + console.error('error getting relationship', error2) + return + } + + console.log('relationshipRecord is', relationshipRecord) + + console.log('userRecord is', userRecord) + + const descriptionMemory = new Memory({ + user_ids: [state.agentId, userRecord.id], + user_id: state.agentId, + content: description, + room_id: relationshipRecord.room_id, }) + console.log('descriptionMemory', descriptionMemory.toJSON()) + await runtime.descriptionManager.upsertRawMemory(descriptionMemory); + console.log('stored descriptionMemory', descriptionMemory) } else if (runtime.debugMode) { console.log(chalk.red('Could not parse response')) } diff --git a/packages/agent/src/agent/agent.ts b/packages/agent/src/agent/agent.ts index a11f5c5..ca7a66f 100644 --- a/packages/agent/src/agent/agent.ts +++ b/packages/agent/src/agent/agent.ts @@ -12,7 +12,11 @@ import { } from '../lib' import {defaultActions} from '../lib/actions' import {formatGoalsAsString, getGoals} from '../lib/goals' -import introduce from './actions/introduce' +// import introduce from './actions/introduce' +import profile from './actions/profile' +// import objective from './actions/objective' +// import goal +// from './actions/goal' import { reflection_template, response_generation_template, @@ -20,7 +24,12 @@ import { } from './templates' import {parseJSONObjectFromText, parseJsonArrayFromText} from './utils' -const customActions = [introduce] +const customActions = [ + // introduce, + profile, + // goal, + // objective +] export const constants = { avatarPlaceholder: (seed: string | number) => { @@ -395,7 +404,7 @@ export const onMessage = async (message: any, runtime: any) => { await runtime.messageManager.upsertRawMemory(senderMemory.toJSON()) } - responseData.content = responseData.content.trim() + responseData.content = responseData.content?.trim() if (responseData.content) { const responseMemory = new Memory({ user_ids: userIds, diff --git a/packages/agent/src/lib/actions.ts b/packages/agent/src/lib/actions.ts index 6f0322d..b854fd4 100644 --- a/packages/agent/src/lib/actions.ts +++ b/packages/agent/src/lib/actions.ts @@ -9,27 +9,27 @@ export const defaultActions = [ JSON.stringify({ user: "CJ", content: "I know right lol", action: "NONE" }), ], }, - { - name: "CONTINUE", - description: "Continue the conversation with the user", - examples: [ - JSON.stringify({ user: "CJ", content: "The comet passing over tonight is going to be a sight to behold. Are you excited about it?", action: "CONTINUE" }), - ], - }, - { - name: "WAIT", - description: "Do nothing and wait for another person to reply, or continue their message", - examples: [ - JSON.stringify({ user: "CJ", content: "", action: "WAIT" }), - ], - }, - { - name: "IGNORE", - description: "Ignore the user and do not respond, use this if your role involves being sassy, or mad at user", - examples: [ - JSON.stringify({ user: "CJ", content: "", action: "IGNORE" }), - ], - }, + // { + // name: "CONTINUE", + // description: "Continue the conversation with the user", + // examples: [ + // JSON.stringify({ user: "CJ", content: "The comet passing over tonight is going to be a sight to behold. Are you excited about it?", action: "CONTINUE" }), + // ], + // }, + // { + // name: "WAIT", + // description: "Do nothing and wait for another person to reply, or continue their message", + // examples: [ + // JSON.stringify({ user: "CJ", content: "", action: "WAIT" }), + // ], + // }, + // { + // name: "IGNORE", + // description: "Ignore the user and do not respond, use this if your role involves being sassy, or mad at user", + // examples: [ + // JSON.stringify({ user: "CJ", content: "", action: "IGNORE" }), + // ], + // }, // { // name: 'UPDATE_GOAL', // description: 'Update a the current state of a goal - set goal status to CANCELED, FAILED or COMPLETED', diff --git a/packages/agent/src/lib/messages.ts b/packages/agent/src/lib/messages.ts index a71d87d..0ff552d 100644 --- a/packages/agent/src/lib/messages.ts +++ b/packages/agent/src/lib/messages.ts @@ -33,7 +33,7 @@ export async function getMessageActors({ supabase, userIds }: any) { export function formatMessageActors({ actors }: any) { // format actors as a string const actorStrings = actors.map((actor: { name: any; description: any; }) => { - const header = `${actor.name}: ${actor.description}`; + const header = `${actor.name}: ${actor.description ?? "No description"}`; return header; }); const finalActorStrings = actorStrings.join("\n"); diff --git a/packages/agent/src/lib/relationships.ts b/packages/agent/src/lib/relationships.ts index 6fdd45c..ef4fe8f 100644 --- a/packages/agent/src/lib/relationships.ts +++ b/packages/agent/src/lib/relationships.ts @@ -21,8 +21,7 @@ export async function createRelationship({ supabase, userA, userB}: { supabase: export async function getRelationship({ supabase, userA, userB }: { supabase: any, userA: string, userB: string }) { const { data, error } = await supabase.from("relationships").select("*") - .or(`user_a.eq.${userA},user_b.eq.${userB}`) - .or(`user_a.eq.${userB},user_b.eq.${userA}`); + .or(`user_a.eq.${userA},user_b.eq.${userB},user_a.eq.${userB},user_b.eq.${userA}`); if (error) { throw new Error(error.message); diff --git a/packages/terminal/package.json b/packages/terminal/package.json index 06673d3..2b82d9a 100644 --- a/packages/terminal/package.json +++ b/packages/terminal/package.json @@ -28,7 +28,7 @@ "license": "MIT", "sideEffects": false, "scripts": { - "dev": "concurrently \"rollup -c -w\" \"node --no-warnings terminal.mjs\"", + "dev": "rollup -c -w", "dev:terminal": "node --no-warnings terminal.mjs", "build": "rollup -c && tsc --declaration --emitDeclarationOnly --declarationDir dist", "build:types": "tsc --declaration --emitDeclarationOnly --declarationDir dist",