Skip to content

Commit

Permalink
wrangler, cj runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
lalalune committed Feb 10, 2024
1 parent 1c6e61e commit 90e05a7
Show file tree
Hide file tree
Showing 19 changed files with 362 additions and 40 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/deploy_worker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ jobs:
- name: Build Worker
run: npm run build:worker

- name: Install Wrangler
run: npm install -g @cloudflare/wrangler

- uses: actions/checkout@v3
- name: Deploy
Expand Down
4 changes: 2 additions & 2 deletions packages/agent/__tests__/createRuntime.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createClient } from "@supabase/supabase-js";
import { AgentRuntime } from "../src";
import { CojourneyRuntime } from "../src";

export async function createRuntime() {
const supabase = await createClient(
Expand All @@ -15,7 +15,7 @@ export async function createRuntime() {
password: process.env.TEST_PASSWORD as string,
});

const runtime = new AgentRuntime({
const runtime = new CojourneyRuntime({
debugMode: false,
serverUrl: process.env.SERVER_URL,
supabase,
Expand Down
File renamed without changes.
192 changes: 192 additions & 0 deletions packages/agent/__tests__/matchmaking.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
// test creating an agent runtime
import dotenv from "dotenv";
dotenv.config();

import { createRuntime } from "./createRuntime.js";

import {
GetTellMeAboutYourselfConversation1,
GetTellMeAboutYourselfConversation2,
GetTellMeAboutYourselfConversation3,
TwoTruthsAndALieConversation1,
TwoTruthsAndALieConversation2,
TwoTruthsAndALieConversation3,
GetEyeColorConversationExample1,
GetEyeColorConversationExample2,
GetEyeColorConversationExample3,
} from "./data.js";
import { UUID } from "crypto";
import { getRelationship } from "../src/index.js";

// create a UUID of 0s
const zeroUuid = "00000000-0000-0000-0000-000000000000";

// # 1. Description generation - test the prompt

// 1. Create a description based on the conversation
// 2. Check if the description includes key details
// 3. Check that the description does NOT include details about other agents

// # 2. Description degradation

// Do we get eye color remembered when we start talking about deeper stuff?

// 1. Create a description based on the conversation at different points in time
// 2. Check if the description includes key details
// 3. Check that the description does NOT include details about other agents
// 4. Check that the description continues to include details from previous descriptions

describe("Agent Runtime", () => {
test("Description Generation and Handling", async () => {
const { user, runtime } = await createRuntime();

async function _cleanup() {
await runtime.messageManager.removeAllMemoriesByUserIds([
user?.id as UUID,
zeroUuid,
]);
}

const data = await getRelationship({
supabase: runtime.supabase,
userA: user?.id as UUID,
userB: zeroUuid,
});

const room_id = data?.room_id;



async function _testBasicDetails() {
const conversation = GetTellMeAboutYourselfConversation1(user?.id as UUID);
for (let i = 0; i < conversation.length; i++) {
const c = conversation[i];
const bakedMemory = await runtime.messageManager.addEmbeddingToMemory({
user_id: c.user_id,
user_ids: [user?.id as UUID, zeroUuid],
content: {
content: c.content,
},
room_id
});
await runtime.messageManager.createMemory(bakedMemory);
}

// TODO: import description template

// TODO: prepare state

// TODO: generate description

// TODO: check that the description includes key details

// TODO: check that the description does NOT include details about other agents
}

// Based on the full conversation, generate a description that appropriately summarizes public and private details
async function _testDescriptionGeneration() {
// create memories for each message in conversation
const conversation = [
...GetTellMeAboutYourselfConversation2(user?.id),
...GetTellMeAboutYourselfConversation3(user?.id),
];
for (let i = 0; i < conversation.length; i++) {
const c = conversation[i];
const bakedMemory = await runtime.messageManager.addEmbeddingToMemory({
user_id: c.user_id,
user_ids: [user?.id as UUID, zeroUuid],
content: {
content: c.content,
},
room_id: undefined,
});
await runtime.messageManager.createMemory(bakedMemory);
}

// generate a description

// TODO: import description template

// TODO: prepare state

// TODO: generate description

// TODO: check that the description includes key details

// TODO: check that the description does NOT include details about other agents
}

async function _testDescriptionRemembered() {
// create memories for each message in conversation
const conversation = [
...GetEyeColorConversationExample1(user?.id),
...GetEyeColorConversationExample2(user?.id),
...GetEyeColorConversationExample3(user?.id),
...TwoTruthsAndALieConversation1(user?.id),
...TwoTruthsAndALieConversation2(user?.id),
...TwoTruthsAndALieConversation3(user?.id),
];
for (let i = 0; i < conversation.length; i++) {
const c = conversation[i];
const bakedMemory = await runtime.messageManager.addEmbeddingToMemory({
user_id: c.user_id,
user_ids: [user?.id as UUID, zeroUuid],
content: {
content: c.content,
},
room_id: undefined,
});
await runtime.messageManager.createMemory(bakedMemory);
}

// generate another description and check that the original details were remembered

// TODO: import description template

// TODO: prepare state, including last description

// TODO: generate description

// TODO: check that the description includes key details

// TODO: check that the description does NOT include details about other agents

// TODO: check that the description continues to include details from previous descriptions
}

// first, destroy all memories where the user_id is TestUser
await _cleanup();

await _testDescriptionGeneration();

// then, create new memories
await _testDescriptionRemembered();

// then destroy all memories again
await _cleanup();
});
test("Rolodex and Matchmaking", async () => {
const { user, runtime } = await createRuntime();

async function _cleanup() {
await runtime.messageManager.removeAllMemoriesByUserIds([
user?.id as UUID,
zeroUuid,
]);
await runtime.descriptionManager.removeAllMemoriesByUserIds([
user?.id as UUID,
zeroUuid,
]);
}

_cleanup();

async function _testSearchUsers() {
// TODO: Add test users for Gloria and Alice to environment
// TODO: Add personas to description, then search for them
// Make sure that the expected personas are returned in order, i.e. Jim and Alice, not Jim and Gloria
}

_cleanup();
});
});
4 changes: 2 additions & 2 deletions packages/agent/src/agent/actions.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { AgentRuntime } from "../lib/runtime";
import { CojourneyRuntime } from "../lib/runtime";

/**
* A list of tools/actions available to the agent
*/
export const customActions = [];

export function addCustomActions(runtime: AgentRuntime) {
export function addCustomActions(runtime: CojourneyRuntime) {
customActions.forEach((action) => {
if (!runtime.getActions().includes(action)) {
runtime.registerAction(action);
Expand Down
14 changes: 7 additions & 7 deletions packages/agent/src/agent/agent.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { UUID } from "crypto";
import { AgentRuntime, composeContext, embeddingZeroVector } from "../lib";
import { CojourneyRuntime, composeContext, embeddingZeroVector } from "../lib";
import logger from "../lib/logger";
import { composeState } from "../lib/state";
import { Action, Content, Message, State } from "../lib/types";
Expand All @@ -12,7 +12,7 @@ import {
} from "./templates";

async function _main(
runtime: AgentRuntime,
runtime: CojourneyRuntime,
message: Message,
state: State,
template: string,
Expand Down Expand Up @@ -77,7 +77,7 @@ async function _main(
* Handles the subsequent action execution if the main prompt outputs an action other than WAIT/CONTINUE
*/
async function _processActions(
runtime: AgentRuntime,
runtime: CojourneyRuntime,
message: Message,
state: State,
data: { action: string },
Expand Down Expand Up @@ -107,7 +107,7 @@ async function _processActions(
}

// stores either 1 or 2 memories, depending on whether the sender's content is empty or not
async function _storeSenderMemory(runtime: AgentRuntime, message: Message) {
async function _storeSenderMemory(runtime: CojourneyRuntime, message: Message) {
const { content: senderContent, senderId, userIds, room_id } = message;

// TODO: The types here are ugly, log and very this
Expand All @@ -130,7 +130,7 @@ async function _storeSenderMemory(runtime: AgentRuntime, message: Message) {
}

async function _storeAgentMemory(
runtime: AgentRuntime,
runtime: CojourneyRuntime,
message: Message,
state: State,
responseData: Content,
Expand All @@ -154,7 +154,7 @@ async function _storeAgentMemory(
}

// main entry point for the agent
export const onMessage = async (message: Message, runtime: AgentRuntime) => {
export const onMessage = async (message: Message, runtime: CojourneyRuntime) => {
// if runtime.getActions does not include any customActions, add them
addCustomActions(runtime);
addCustomEvaluators(runtime);
Expand Down Expand Up @@ -187,7 +187,7 @@ export const onMessage = async (message: Message, runtime: AgentRuntime) => {
};

// main entry point for the agent
export const onUpdate = async (message: Message, runtime: AgentRuntime) => {
export const onUpdate = async (message: Message, runtime: CojourneyRuntime) => {
// if runtime.getActions does not include any customActions, add them
addCustomActions(runtime);

Expand Down
10 changes: 6 additions & 4 deletions packages/agent/src/agent/evaluation.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import { Evaluator, Message, State } from "@/lib/types";
import { AgentRuntime } from "../lib/runtime";
import { CojourneyRuntime } from "../lib/runtime";
// import goal from './evaluators/goal';
// import introduce from './evaluators/introduce';
// import objective from './evaluators/objective';
import profile from "./evaluators/profile";
import profile from "./evaluators/details";
import description from "./evaluators/details";

export const customEvaluators: Evaluator[] = [
// goal,
// introduce,
// objective,
profile,
description,
];

export function addCustomEvaluators(runtime: AgentRuntime) {
export function addCustomEvaluators(runtime: CojourneyRuntime) {
// if runtime.evaluators does not include any customEvaluators, add them
customEvaluators.forEach((evaluator) => {
if (!runtime.evaluators.includes(evaluator)) {
Expand All @@ -23,7 +25,7 @@ export function addCustomEvaluators(runtime: AgentRuntime) {

// evaluation
export const evaluate = async (
runtime: AgentRuntime,
runtime: CojourneyRuntime,
message: Message,
state: State,
) => {
Expand Down
Loading

0 comments on commit 90e05a7

Please sign in to comment.