Skip to content

Commit 0419766

Browse files
committed
Update trust stuff, fix generateTrueOrFalse, update some types, handle evaluators with runAlways
1 parent 45987ed commit 0419766

File tree

14 files changed

+504
-34
lines changed

14 files changed

+504
-34
lines changed

packages/agent/src/index.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
console.log("ok");
21
import { PostgresDatabaseAdapter } from "@ai16z/adapter-postgres/src/index.ts";
32
import { SqliteDatabaseAdapter } from "@ai16z/adapter-sqlite/src/index.ts";
43
import { DirectClientInterface } from "@ai16z/client-direct/src/index.ts";
@@ -15,6 +14,7 @@ import {
1514
ModelProviderName,
1615
} from "@ai16z/eliza/src/types.ts";
1716
import { bootstrapPlugin } from "@ai16z/plugin-bootstrap/src/index.ts";
17+
import { solanaPlugin } from "@ai16z/plugin-solana/src/index.ts";
1818
import { nodePlugin } from "@ai16z/plugin-node/src/index.ts";
1919
import Database from "better-sqlite3";
2020
import fs from "fs";
@@ -198,7 +198,13 @@ export async function createAgent(
198198
modelProvider: character.modelProvider,
199199
evaluators: [],
200200
character,
201-
plugins: [bootstrapPlugin, nodePlugin],
201+
plugins: [
202+
bootstrapPlugin,
203+
nodePlugin,
204+
character.settings.secrets.WALLET_PUBLIC_KEY
205+
? solanaPlugin
206+
: null
207+
].filter(Boolean),
202208
providers: [],
203209
actions: [],
204210
services: [],

packages/client-direct/src/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,8 @@ export class DirectClient {
218218

219219
let message = null as Content | null;
220220

221+
await runtime.evaluate(memory, state);
222+
221223
const result = await runtime.processActions(
222224
memory,
223225
[responseMessage],

packages/client-discord/src/messages.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -463,9 +463,7 @@ export class MessageManager {
463463
shouldRespond = await this._shouldRespond(message, state);
464464
}
465465

466-
if (!shouldRespond) {
467-
return;
468-
}
466+
if (shouldRespond) {
469467

470468
const context = composeContext({
471469
state,
@@ -576,14 +574,15 @@ export class MessageManager {
576574

577575
state = await this.runtime.updateRecentMessageState(state);
578576

579-
await this.runtime.evaluate(memory, state);
580-
581577
await this.runtime.processActions(
582578
memory,
583579
responseMessages,
584580
state,
585581
callback
586582
);
583+
}
584+
await this.runtime.evaluate(memory, state, shouldRespond);
585+
587586
} catch (error) {
588587
console.error("Error handling message:", error);
589588
if (message.channel.type === ChannelType.GuildVoice) {

packages/core/src/embedding.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ export async function embed(runtime: IAgentRuntime, input: string) {
8585
body: JSON.stringify({
8686
input,
8787
model: embeddingModel,
88-
length: 768, // we are squashing dimensions to 768 for openai, even thought the model supports 1536
88+
length: 384, // we are squashing dimensions to 768 for openai, even thought the model supports 1536
8989
// -- this is ok for matryoshka embeddings but longterm, we might want to support 1536
9090
}),
9191
};

packages/core/src/generation.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -400,9 +400,10 @@ export async function generateTrueOrFalse({
400400
modelClass: string;
401401
}): Promise<boolean> {
402402
let retryDelay = 1000;
403+
console.log("modelClass", modelClass)
403404

404405
const stop = Array.from(
405-
new Set([...(models[modelClass].settings.stop || []), ["\n"]])
406+
new Set([...(models[runtime.modelProvider].settings.stop || []), ["\n"]])
406407
) as string[];
407408

408409
while (true) {

packages/core/src/runtime.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -494,14 +494,20 @@ export class AgentRuntime implements IAgentRuntime {
494494
* Evaluate the message and state using the registered evaluators.
495495
* @param message The message to evaluate.
496496
* @param state The state of the agent.
497+
* @param didRespond Whether the agent responded to the message.
497498
* @returns The results of the evaluation.
498499
*/
499-
async evaluate(message: Memory, state?: State) {
500+
async evaluate(message: Memory, state?: State, didRespond?: boolean) {
501+
console.log("Evaluate: ", didRespond)
500502
const evaluatorPromises = this.evaluators.map(
501503
async (evaluator: Evaluator) => {
504+
console.log("Evaluating", evaluator.name)
502505
if (!evaluator.handler) {
503506
return null;
504507
}
508+
if(!didRespond && !evaluator.alwaysRun) {
509+
return null;
510+
}
505511
const result = await evaluator.validate(this, message, state);
506512
if (result) {
507513
return evaluator;

packages/core/src/types.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ export interface EvaluationExample {
231231
* Represents an evaluator, which is used to assess and guide the agent's responses based on the current context and state.
232232
*/
233233
export interface Evaluator {
234+
alwaysRun?: boolean;
234235
description: string; // A detailed description of what the evaluator assesses or guides.
235236
similes: string[]; // An array of strings representing the similies of the action.
236237
examples: EvaluationExample[]; // An array of evaluation examples demonstrating the evaluator.
@@ -547,7 +548,7 @@ export interface IAgentRuntime {
547548
state?: State,
548549
callback?: HandlerCallback
549550
): Promise<void>;
550-
evaluate(message: Memory, state?: State): Promise<string[]>;
551+
evaluate(message: Memory, state?: State, didRespond?: boolean): Promise<string[]>;
551552
ensureParticipantExists(userId: UUID, roomId: UUID): Promise<void>;
552553
ensureUserExists(
553554
userId: UUID,

packages/plugin-bootstrap/src/providers/facts.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,17 @@ const factsProvider: Provider = {
2020

2121
const embedding = await embed(runtime, recentMessages);
2222

23-
console.log("embedding", embedding);
23+
console.log('embedding', embedding);
24+
console.log('embedding length', embedding.length);
25+
2426

2527
const memoryManager = new MemoryManager({
2628
runtime,
2729
tableName: "facts",
2830
});
2931

3032
const relevantFacts = []
31-
32-
// await memoryManager.searchMemoriesByEmbedding(
33+
// await memoryManager.searchMemoriesByEmbedding(
3334
// embedding,
3435
// {
3536
// roomId: message.roomId,

packages/plugin-solana/src/actions/swap.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
} from "@solana/web3.js";
88
import BigNumber from "bignumber.js";
99
import { v4 as uuidv4 } from "uuid";
10-
import { TrustScoreDatabase } from "@ai16z/eliza/src/adapters/trustScoreDatabase.ts";
10+
import { TrustScoreDatabase } from "../adapters/trustScoreDatabase.ts";
1111
import { composeContext } from "@ai16z/eliza/src/context.ts";
1212
import { generateObject } from "@ai16z/eliza/src/generation.ts";
1313
import settings from "@ai16z/eliza/src/settings.ts";
@@ -20,12 +20,12 @@ import {
2020
State,
2121
type Action,
2222
} from "@ai16z/eliza/src/types.ts";
23-
import { TokenProvider } from "@ai16z/eliza/src/providers/token.ts";
24-
import { TrustScoreProvider } from "@ai16z/eliza/src/providers/trustScoreProvider.ts";
23+
import { TokenProvider } from "../providers/token.ts";
24+
import { TrustScoreManager } from "../providers/trustScoreProvider.ts";
2525
import {
2626
walletProvider,
2727
WalletProvider,
28-
} from "@ai16z/eliza/src/providers/wallet.ts";
28+
} from "../providers/wallet.ts";
2929
import { getTokenDecimals } from "./swapUtils.ts";
3030

3131
async function swapToken(
@@ -408,7 +408,7 @@ export const executeSwap: Action = {
408408
solanaPubkey: walletPublicKey.toString(),
409409
});
410410

411-
const trustScoreDatabase = new TrustScoreProvider(
411+
const trustScoreDatabase = new TrustScoreManager(
412412
tokenProvider,
413413
trustScoreDb
414414
);
@@ -438,7 +438,7 @@ export const executeSwap: Action = {
438438
solanaPubkey: walletPublicKey.toString(),
439439
});
440440

441-
const trustScoreDatabase = new TrustScoreProvider(
441+
const trustScoreDatabase = new TrustScoreManager(
442442
tokenProvider,
443443
trustScoreDb
444444
);

packages/plugin-solana/src/adapters/trustScoreDatabase.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import { Database } from "better-sqlite3";
44
import { v4 as uuidv4 } from "uuid";
5-
import { load } from "@ai16z/eliza/src/adapters/sqlite/sqlite_vec.ts";
65

76
// Define interfaces
87
export interface Recommender {
@@ -132,7 +131,7 @@ export class TrustScoreDatabase {
132131

133132
constructor(db: Database) {
134133
this.db = db;
135-
load(db);
134+
// load(db);
136135
// check if the tables exist, if not create them
137136
const tables = this.db
138137
.prepare(

0 commit comments

Comments
 (0)