Skip to content

Commit

Permalink
init commit
Browse files Browse the repository at this point in the history
  • Loading branch information
lalalune committed Feb 14, 2024
1 parent d14850d commit 8c5c327
Show file tree
Hide file tree
Showing 32 changed files with 702 additions and 165 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/deploy_worker.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Deploy Cloudflare Worker
on:
push:
branches:
- main

jobs:
deploy:
runs-on: ubuntu-latest
name: Deploy
steps:
- uses: actions/checkout@v3

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'

- name: Install Dependencies
run: npm install

- name: Deploy Worker
env:
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
run: npx wrangler deploy
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
node_modules
.env
concatenated-output.ts
embedding-cache.json
embedding-cache.json
dist
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@

Flexible, scalable and customizable agents to do your bidding.

<img src="resources/image.jpg">
![cj](https://github.com/lalalune/bgent/assets/18633264/7513b5a6-2352-45f3-8b87-7ee0e2171a30)

[![License](https://img.shields.io/badge/License-MIT-blue)](https://github.com/lalalune/bgent/blob/main/LICENSE)
[![stars - bgent](https://img.shields.io/github/stars/lalalune/bgent?style=social)](https://github.com/lalalune/bgent)
[![forks - bgent](https://img.shields.io/github/forks/lalalune/bgent?style=social)](https://github.com/lalalune/bgent)

## PRE-ALPHA RELEASE
- This code is NOT production ready. This package has been released as-is to enable collaboration and development.
- 0.1.0 will be the first official alpha release!

## Features

- Simple and extensible
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bgent",
"version": "0.0.1",
"version": "0.0.3",
"private": false,
"description": "bgent. because agent was taken.",
"type": "module",
Expand Down Expand Up @@ -60,7 +60,6 @@
"@rollup/plugin-json": "^6.1.0",
"@supabase/supabase-js": "^2.39.3",
"@tsndr/cloudflare-worker-jwt": "^2.2.1",
"chalk": "^5.3.0",
"dotenv": "^16.4.4",
"inquirer": "^9.2.14",
"ts-node": "^10.9.2"
Expand Down
11 changes: 4 additions & 7 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,10 @@ export default defineConfig([
],
plugins: [
json(),
resolve(), // so Rollup can resolve packages
commonjs(), // so Rollup can convert commonjs to an ES module
typescript(), // so Rollup can convert TypeScript to JavaScript
resolve(),
commonjs(),
typescript(),
replace({
// see: https://github.com/rollup/plugins/tree/master/packages/replace#preventassignment
preventAssignment: true,
})
].filter(Boolean),
Expand All @@ -55,11 +54,9 @@ export default defineConfig([
],
plugins: [
json(),
typescript(), // so Rollup can convert TypeScript to JavaScript
typescript(),
replace({
// preserve to be handled by bundlers
__DEV__: `(process.env.NODE_ENV !== 'production')`,
// see: https://github.com/rollup/plugins/tree/master/packages/replace#preventassignment
preventAssignment: true,
})
].filter(Boolean),
Expand Down
15 changes: 3 additions & 12 deletions src/agents/cj/actions/__tests__/introduce.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// test creating an agent runtime
import dotenv from "dotenv";

import { type UUID } from "crypto";
Expand All @@ -20,7 +19,6 @@ import {
} from "../../../../test/cache";
dotenv.config();

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

describe("Introduce Action", () => {
Expand Down Expand Up @@ -55,7 +53,6 @@ describe("Introduce Action", () => {
}

async function _testCreateProfile() {
// first, add all the memories for conversation
let conversation = GetTellMeAboutYourselfConversation1(user?.id as UUID);
for (let i = 0; i < conversation.length; i++) {
const c = conversation[i];
Expand All @@ -79,8 +76,7 @@ describe("Introduce Action", () => {

const handler = evaluator.handler!;

// eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
let result = (await handler(runtime, message)) as unknown as string;
let result = (await handler(runtime, message)) as string;

expect(result.includes("programmer")).toBe(true);

Expand Down Expand Up @@ -113,7 +109,6 @@ describe("Introduce Action", () => {

const previousDescriptions = [jimProfileExample1, jimProfileExample2];

// for each description in previousDescriptions, add it to the memory
for (let i = 0; i < previousDescriptions.length; i++) {
const c = previousDescriptions[i];
const bakedMemory =
Expand All @@ -124,13 +119,11 @@ describe("Introduce Action", () => {
room_id,
});
await runtime.descriptionManager.createMemory(bakedMemory);
// wait for .2 seconds

await new Promise((resolve) => setTimeout(resolve, 250));
}

// TODO: fix this
// eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
result = (await handler(runtime, message)) as unknown as string;
result = (await handler(runtime, message)) as string;

expect(result.includes("38")).toBe(true);

Expand All @@ -141,12 +134,10 @@ describe("Introduce Action", () => {
expect(result.toLowerCase().includes("startup")).toBe(true);
}

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

await _testCreateProfile();

// then destroy all memories again
await _cleanup();
}, 60000);
});
4 changes: 1 addition & 3 deletions src/agents/cj/actions/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { type Action } from "../../../lib/types";
import introduce from "./introduce";
/**
* A list of tools/actions available to the agent
*/

export default [introduce] as Action[];
3 changes: 0 additions & 3 deletions src/agents/cj/actions/introduce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,11 @@ const handler = async (runtime: BgentRuntime, message: Message) => {

let responseData = null;
for (let triesLeft = 3; triesLeft > 0; triesLeft--) {
// generate the response
const response = await runtime.completion({
context,
stop: [],
});

// parse the response, which is a json object block
const parsedResponse = parseJSONObjectFromText(response);

if (parsedResponse) {
Expand Down Expand Up @@ -109,7 +107,6 @@ export default {
_runtime: BgentRuntime,
_message: Message,
): Promise<boolean> => {
// immediatel resolve true
return await Promise.resolve(true);
},
description:
Expand Down
6 changes: 0 additions & 6 deletions src/agents/cj/evaluators/__tests__/details.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// test creating an agent runtime
import dotenv from "dotenv";

import { type UUID } from "crypto";
Expand All @@ -18,7 +17,6 @@ import {
} from "../../../../test/cache";
dotenv.config();

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

describe("User Details", () => {
Expand Down Expand Up @@ -54,7 +52,6 @@ describe("User Details", () => {
}

async function _testGetDetails() {
// first, add all the memories for conversation
let conversation = GetTellMeAboutYourselfConversation1(user?.id as UUID);
for (let i = 0; i < conversation.length; i++) {
const c = conversation[i];
Expand All @@ -69,7 +66,6 @@ describe("User Details", () => {
embedding,
});
await runtime.messageManager.createMemory(bakedMemory);
// wait for .2 seconds
if (!embedding) {
writeCachedEmbedding(c.content, bakedMemory.embedding as number[]);
await new Promise((resolve) => setTimeout(resolve, 250));
Expand Down Expand Up @@ -125,12 +121,10 @@ describe("User Details", () => {
expect(locationIncludesSanFrancisco).toBe(true);
}

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

await _testGetDetails();

// then destroy all memories again
await _cleanup();
}, 60000);
});
4 changes: 1 addition & 3 deletions src/agents/cj/evaluators/__tests__/profile.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// test creating an agent runtime
import dotenv from "dotenv";

import { type UUID } from "crypto";
Expand All @@ -23,7 +22,6 @@ import evaluator from "../profile";

dotenv.config();

// create a UUID of 0s
const zeroUuid: UUID = "00000000-0000-0000-0000-000000000000";
let runtime: BgentRuntime;
let user: User;
Expand Down Expand Up @@ -164,7 +162,7 @@ describe("User Profile", () => {

expect(result.toLowerCase().includes("francisco")).toBe(true);

expect(result.toLowerCase().includes("startup")).toBe(true);
expect(result.toLowerCase().includes("startup") || result.toLowerCase().includes("programmer")).toBe(true);

const descriptions = await runtime.descriptionManager.getMemoriesByIds({
userIds: [message.senderId, message.agentId] as UUID[],
Expand Down
9 changes: 1 addition & 8 deletions src/agents/cj/evaluators/details.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Using the most recent conversation, get the details for the user's name, age, lo
Only include the values that can be extracted from the conversation.
Then respond with a JSON object containing a field for description in a JSON block formatted for markdown with this structure:
\`\`\`json
{ user: {{senderName}}, name?: string, age?: number, location?: string, gender?: string}
{ name?: string, age?: number, location?: string, gender?: string}
\`\`\`
Your response must include the JSON block.`;
Expand All @@ -30,13 +30,11 @@ const handler = async (runtime: BgentRuntime, message: Message) => {
let responseData = null;

for (let triesLeft = 3; triesLeft > 0; triesLeft--) {
// generate the response
const response = await runtime.completion({
context,
stop: [],
});

// parse the response, which is a json object block
const parsedResponse = parseJSONObjectFromText(response);

if (parsedResponse) {
Expand All @@ -61,7 +59,6 @@ const handler = async (runtime: BgentRuntime, message: Message) => {

const { user, name, age, location, gender } = responseData;

// find the user
const response = await runtime.supabase
.from("accounts")
.select("*")
Expand All @@ -74,7 +71,6 @@ const handler = async (runtime: BgentRuntime, message: Message) => {

const currentDetails = userRecord.details || {};

// for name, age, location, gender -- if the value exists and doesn't exist in currentDetails, add it
if (name && !currentDetails.name) {
currentDetails.name = name;
}
Expand All @@ -91,7 +87,6 @@ const handler = async (runtime: BgentRuntime, message: Message) => {
currentDetails.gender = gender;
}

// update the user with the new details
const { error: updateError } = await runtime.supabase
.from("accounts")
.update({ details: currentDetails })
Expand All @@ -100,7 +95,6 @@ const handler = async (runtime: BgentRuntime, message: Message) => {
console.error("error updating user", updateError);
}

// respond with the details
return {
name,
age,
Expand All @@ -115,7 +109,6 @@ export default {
_runtime: BgentRuntime,
_message: Message,
): Promise<boolean> => {
// immediatel resolve true
return await Promise.resolve(true);
},
description:
Expand Down
16 changes: 0 additions & 16 deletions src/agents/cj/evaluators/profile.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,3 @@
// - Gather general information about the user

// - Info we want:

// Basics / Logistics
// - Name
// - Gender
// - Age
// - Location

// Deeper
// - What is important to you in a connection?
// - Describe the best aspects of your best connection.
// - Describe what went well and what went poorly.
// - How much do they value interests and hobbies vs other things

import { type UUID } from "crypto";
import { getRelationship, type BgentRuntime } from "../../../lib";
import { composeContext } from "../../../lib/context";
Expand Down
Loading

0 comments on commit 8c5c327

Please sign in to comment.