Skip to content

Commit 8c90803

Browse files
committed
agent is responding, hurray
1 parent 051e883 commit 8c90803

File tree

10 files changed

+36
-34
lines changed

10 files changed

+36
-34
lines changed

packages/agent/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"scripts": {
77
"build": "tsup --format esm --dts",
88
"start": "node --loader ts-node/esm src/index.ts",
9-
"dev": "nodemon --watch src --watch ../core/dist --ext ts,json --exec 'node --loader ts-node/esm' src/index.ts"
9+
"dev": "tsc && nodemon --watch src --watch ../core/dist --ext ts,json --exec 'node --loader ts-node/esm' src/index.ts"
1010
},
1111
"dependencies": {
1212
"@ai16z/eliza": "workspace:*",

packages/agent/src/index.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
IAgentRuntime,
1414
IDatabaseAdapter, ModelProviderName,
1515
} from "@ai16z/eliza/src/types.ts";
16-
import { defaultPlugin } from "@ai16z/plugin-bootstrap/src/index.ts";
16+
import { bootstrapPlugin } from "@ai16z/plugin-bootstrap/src/index.ts";
1717
import { nodePlugin } from "@ai16z/plugin-node/src/index.ts";
1818
import Database from "better-sqlite3";
1919
import fs from "fs";
@@ -165,14 +165,14 @@ export async function initializeClients(
165165
const clientTypes =
166166
character.clients?.map((str) => str.toLowerCase()) || [];
167167

168-
// if (clientTypes.includes("discord")) {
169-
// clients.push(await DiscordClientInterface.start(runtime));
170-
// }
168+
if (clientTypes.includes("discord")) {
169+
clients.push(await DiscordClientInterface.start(runtime));
170+
}
171171

172-
// if (clientTypes.includes("telegram")) {
173-
// const telegramClient = await TelegramClientInterface.start(runtime);
174-
// if (telegramClient) clients.push(telegramClient);
175-
// }
172+
if (clientTypes.includes("telegram")) {
173+
const telegramClient = await TelegramClientInterface.start(runtime);
174+
if (telegramClient) clients.push(telegramClient);
175+
}
176176

177177
if (clientTypes.includes("twitter")) {
178178
const twitterClients = await TwitterClientInterface.start(runtime);
@@ -194,7 +194,7 @@ export async function createAgent(
194194
modelProvider: character.modelProvider,
195195
evaluators: [],
196196
character,
197-
plugins: [defaultPlugin, nodePlugin],
197+
plugins: [bootstrapPlugin, nodePlugin],
198198
providers: [],
199199
actions: [],
200200
services: [],

packages/client-direct/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ export const DirectClientInterface: Client = {
280280
start: async (runtime: IAgentRuntime) => {
281281
console.log("DirectClientInterface start")
282282
const client = new DirectClient();
283-
const serverPort = parseInt(settings.SERVER_PORT || "3001");
283+
const serverPort = parseInt(settings.SERVER_PORT || "3000");
284284
client.start(serverPort);
285285
return client;
286286

packages/client-discord/src/actions/download_media.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ import {
77
Content,
88
HandlerCallback,
99
IAgentRuntime,
10+
IVideoService,
1011
Memory,
1112
ModelClass,
13+
ServiceType,
1214
State,
1315
} from "@ai16z/eliza/src/types.ts";
1416
import { VideoService } from "@ai16z/plugin-node/src/services/video.ts";
@@ -83,7 +85,7 @@ export default {
8385
options: any,
8486
callback: HandlerCallback
8587
) => {
86-
const videoService = VideoService.getInstance();
88+
const videoService = runtime.getService<IVideoService>(ServiceType.VIDEO);
8789
if (!state) {
8890
state = (await runtime.composeState(message)) as State;
8991
}

packages/core/src/embedding.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ export async function embed(runtime: IAgentRuntime, input: string) {
1111
const model = models[runtime.character.settings.model];
1212

1313
if (model !== ModelProviderName.OPENAI && model !== ModelProviderName.OLLAMA) {
14-
return await runtime.getService<ITextGenerationService>(ServiceType.TEXT_GENERATION).getEmbeddingResponse(input);
14+
const service = runtime.getService<ITextGenerationService>(ServiceType.TEXT_GENERATION);
15+
return await service.getInstance().getEmbeddingResponse(input);
1516
}
1617

1718
const embeddingModel = models[runtime.modelProvider].model.embedding;
@@ -26,7 +27,7 @@ export async function embed(runtime: IAgentRuntime, input: string) {
2627
method: "POST",
2728
headers: {
2829
"Content-Type": "application/json",
29-
//Authorization: `Bearer ${runtime.token}`,
30+
// TODO: make this not hardcoded
3031
...(runtime.modelProvider !== ModelProviderName.OLLAMA && { Authorization: `Bearer ${runtime.token}` }),
3132
},
3233
body: JSON.stringify({
@@ -37,7 +38,7 @@ export async function embed(runtime: IAgentRuntime, input: string) {
3738
};
3839
try {
3940
const response = await fetch(
40-
//`${runtime.serverUrl}/embeddings`,
41+
// TODO: make this not hardcoded
4142
`${runtime.serverUrl}${runtime.modelProvider === ModelProviderName.OLLAMA ? '/v1' : ''}/embeddings`,
4243
requestOptions
4344
);

packages/core/src/runtime.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,13 @@ export class AgentRuntime implements IAgentRuntime {
159159
}
160160
registerService(service: Service): void {
161161
const serviceType = (service as typeof Service).serviceType;
162+
console.log("Registering service:", serviceType);
162163
if (this.services.has(serviceType)) {
163164
console.warn(`Service ${serviceType} is already registered. Skipping registration.`);
164165
return;
165166
}
166167

167-
this.services.set((service.constructor as typeof Service).serviceType, service);
168+
this.services.set((service as typeof Service).serviceType, service);
168169
}
169170

170171
/**

packages/core/src/types.ts

+7-9
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,6 @@ export interface State {
147147
goalsData?: Goal[]; // An optional array of goal objects relevant to the current conversation or context.
148148
recentMessages: string; // A string representation of recent messages in the conversation, for context.
149149
recentMessagesData: Memory[]; // An array of memory objects representing recent messages in the conversation.
150-
recentFacts?: string; // An optional string representation of recent facts derived from the conversation.
151-
recentFactsData?: Memory[]; // An optional array of memory objects representing recent facts.
152-
relevantFacts?: string; // An optional string representation of facts relevant to the current context or topic.
153-
relevantFactsData?: Memory[]; // An optional array of memory objects representing relevant facts.
154150
actionNames?: string; // An optional string listing the names of actions that are valid in the current state.
155151
actions?: string; // An optional string representation of actions and their descriptions, relevant to the current state.
156152
actionsData?: Action[]; // An optional array of action objects relevant to the current state.
@@ -584,21 +580,23 @@ export interface IImageDescriptionService extends Service {
584580
}
585581

586582
export interface ITranscriptionService extends Service {
587-
transcribeAttachment(audioBuffer: ArrayBuffer, runtime: IAgentRuntime): Promise<string | null>;
583+
transcribeAttachment(audioBuffer: ArrayBuffer): Promise<string | null>;
588584
transcribeAttachmentLocally(
589-
audioBuffer: ArrayBuffer,
590-
runtime: IAgentRuntime
585+
audioBuffer: ArrayBuffer
591586
): Promise<string | null>;
592-
transcribe(audioBuffer: ArrayBuffer, runtime: IAgentRuntime): Promise<string | null>;
593-
transcribeLocally(audioBuffer: ArrayBuffer, runtime: IAgentRuntime): Promise<string | null>;
587+
transcribe(audioBuffer: ArrayBuffer): Promise<string | null>;
588+
transcribeLocally(audioBuffer: ArrayBuffer): Promise<string | null>;
594589
}
595590

596591
export interface IVideoService extends Service {
597592
isVideoUrl(url: string): boolean;
598593
processVideo(url: string): Promise<Media>;
594+
fetchVideoInfo(url: string): Promise<Media>;
595+
downloadVideo(videoInfo: Media): Promise<string>;
599596
}
600597

601598
export interface ITextGenerationService extends Service {
599+
getInstance(): ITextGenerationService;
602600
initializeModel(): Promise<void>;
603601
queueMessageCompletion(
604602
context: string,

packages/plugin-bootstrap/src/index.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
import { Plugin } from "@ai16z/eliza/src/types.ts";
22
import { continueAction } from "./actions/continue.ts";
33
import { followRoomAction } from "./actions/followRoom.ts";
4-
import { unfollowRoomAction } from "./actions/unfollowRoom.ts";
54
import { ignoreAction } from "./actions/ignore.ts";
6-
import { noneAction } from "./actions/none.ts";
75
import { muteRoomAction } from "./actions/muteRoom.ts";
6+
import { noneAction } from "./actions/none.ts";
7+
import { unfollowRoomAction } from "./actions/unfollowRoom.ts";
88
import { unmuteRoomAction } from "./actions/unmuteRoom.ts";
99
import { factEvaluator } from "./evaluators/fact.ts";
1010
import { goalEvaluator } from "./evaluators/goal.ts";
1111
import { boredomProvider } from "./providers/boredom.ts";
12-
import { timeProvider } from "./providers/time.ts";
1312
import { factsProvider } from "./providers/facts.ts";
13+
import { timeProvider } from "./providers/time.ts";
1414

15-
export const defaultPlugin: Plugin = {
16-
name: "default",
17-
description: "Default plugin, with basic actions and evaluators",
15+
export const bootstrapPlugin: Plugin = {
16+
name: "bootstrap",
17+
description: "Agent bootstrap with basic actions and evaluators",
1818
actions: [
1919
continueAction,
2020
followRoomAction,

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { formatFacts } from "../evaluators/fact.ts";
77
const factsProvider: Provider = {
88
get: async (runtime: IAgentRuntime, message: Memory, state?: State) => {
99

10-
const recentMessagesData = state?.recentMessagesData;
10+
const recentMessagesData = state?.recentMessagesData?.slice(-10);
1111

1212
const recentMessages = formatMessages({ messages: recentMessagesData, actors: state?.actorsData });
1313

@@ -38,7 +38,7 @@ const factsProvider: Provider = {
3838

3939
const formattedFacts = formatFacts(allFacts);
4040

41-
return "Important facts that {{agentName}} knows:\n{{formattedFacts}}".replace("{{agentName}}", runtime.character.name).replace("{{formattedFacts}}", formattedFacts);
41+
return "Key facts that {{agentName}} knows:\n{{formattedFacts}}".replace("{{agentName}}", runtime.character.name).replace("{{formattedFacts}}", formattedFacts);
4242
},
4343
};
4444

packages/plugin-node/src/services/video.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ export class VideoService extends Service {
307307
console.log("Starting transcription...");
308308
const startTime = Date.now();
309309
const transcript =
310-
await runtime.getService<ITranscriptionService>(ServiceType.TRANSCRIPTION).transcribe(audioBuffer, runtime);
310+
await runtime.getService<ITranscriptionService>(ServiceType.TRANSCRIPTION).transcribe(audioBuffer);
311311
const endTime = Date.now();
312312
console.log(
313313
`Transcription completed in ${(endTime - startTime) / 1000} seconds`

0 commit comments

Comments
 (0)