Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor COT and cleanups #21

Merged
merged 8 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions examples/eternum-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -428,10 +428,14 @@ Remember to replace placeholders like <realm_id>, <entity_id>, <x>, <y>, and <mo
Now, please wait for a user query about the Eternum game, and respond according to the steps outlined above.

</query_guide>
`;

// API DOCs etc
export const PROVIDER_GUIDE = `

<PROVIDER_GUIDE>

Use these to call functions.
Use these to call functions with graphql


<IMPORTANT_RULES>
Expand Down Expand Up @@ -663,6 +667,8 @@ Now, please wait for a user query about the Eternum game, and respond according
</EXAMPLE>
</CREATE_BUILDING>
</FUNCTIONS>
</PROVIDER_GUIDE>`;
</PROVIDER_GUIDE>

`;

console.log(JSON.stringify(ETERNUM_CONTEXT));
25 changes: 23 additions & 2 deletions examples/example-basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { env } from "../packages/core/src/core/env";
import { LLMClient } from "../packages/core/src/core/llm-client";
import { ChainOfThought } from "../packages/core/src/core/chain-of-thought";
import { ETERNUM_CONTEXT } from "./eternum-context";
import { ETERNUM_CONTEXT, PROVIDER_GUIDE } from "./eternum-context";
import * as readline from "readline";
import chalk from "chalk";
import { starknetTransactionAction } from "../packages/core/src/core/actions/starknet-transaction";
Expand All @@ -14,6 +14,7 @@ import {
starknetTransactionSchema,
} from "../packages/core/src/core/validation";
import type { JSONSchemaType } from "ajv";
import { ChromaVectorDB } from "../packages/core/src/core/vector-db";

async function getCliInput(prompt: string): Promise<string> {
const rl = readline.createInterface({
Expand All @@ -36,11 +37,31 @@ async function main() {
apiKey: env.ANTHROPIC_API_KEY,
});

const memory = new ChromaVectorDB("agent_memory");

await memory.storeDocument({
title: "Game Rules",
content: ETERNUM_CONTEXT,
category: "rules",
tags: ["game-mechanics", "rules"],
lastUpdated: new Date(),
});

await memory.storeDocument({
title: "Provider Guide",
content: PROVIDER_GUIDE,
category: "actions",
tags: ["actions", "provider-guide"],
lastUpdated: new Date(),
});

// Initialize ChainOfThought
const dreams = new ChainOfThought(llmClient, {
const dreams = new ChainOfThought(llmClient, memory, {
worldState: ETERNUM_CONTEXT,
});

// Load initial context

// Register available actions
dreams.registerAction(
"EXECUTE_TRANSACTION",
Expand Down
21 changes: 18 additions & 3 deletions examples/example-goal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { LLMClient } from "../packages/core/src/core/llm-client";
import { ChainOfThought } from "../packages/core/src/core/chain-of-thought";
import { ETERNUM_CONTEXT } from "./eternum-context";
import * as readline from "readline";
import { type GoalStatus } from "../packages/core/src/core/goal-manager";

import chalk from "chalk";
import { starknetTransactionAction } from "../packages/core/src/core/actions/starknet-transaction";
import { graphqlAction } from "../packages/core/src/core/actions/graphql";
Expand All @@ -20,6 +20,8 @@ import {
starknetTransactionSchema,
} from "../packages/core/src/core/validation";
import type { JSONSchemaType } from "ajv";
import { ChromaVectorDB } from "../packages/core/src/core/vector-db";
import { GoalStatus } from "../packages/core/src/types";

async function getCliInput(prompt: string): Promise<string> {
const rl = readline.createInterface({
Expand Down Expand Up @@ -68,10 +70,23 @@ async function main() {
apiKey: env.ANTHROPIC_API_KEY,
});

// Fetch context
const context = await fetchContext();

const dreams = new ChainOfThought(llmClient, {
worldState: context,
// Initialize memory
const memory = new ChromaVectorDB("agent_memory");

// Load initial context
await memory.storeDocument({
title: "Game Rules",
content: ETERNUM_CONTEXT,
category: "rules",
tags: ["game-mechanics", "rules"],
lastUpdated: new Date(),
});

const dreams = new ChainOfThought(llmClient, memory, {
worldState: ETERNUM_CONTEXT,
});

// Register actions
Expand Down
Loading
Loading