Skip to content

Commit 2b21f8a

Browse files
logging
1 parent 64d612f commit 2b21f8a

File tree

16 files changed

+132
-101
lines changed

16 files changed

+132
-101
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"start:service:all": "pnpm --filter \"@ai16z/agent\" start:service:all --isRoot",
99
"stop:service:all": "pnpm --filter \"@ai16z/agent\" stop:service:all",
1010
"start": "pnpm --filter \"@ai16z/agent\" start --isRoot",
11+
"start:client": "pnpm --dir client start --isRoot",
1112
"dev": "bash ./scripts/dev.sh",
1213
"lint": "pnpm --dir packages/core lint && pnpm --dir packages/agent lint",
1314
"prettier-check": "npx prettier --check .",

packages/agent/src/index.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ import Database from "better-sqlite3";
2121
import fs from "fs";
2222
import readline from "readline";
2323
import yargs from "yargs";
24-
import { character } from "./character.ts";
24+
// import { character } from "./character.ts";
25+
import { blobert } from "./blobert.ts";
2526

2627
export const wait = (minTime: number = 1000, maxTime: number = 3000) => {
2728
const waitTime =
@@ -263,7 +264,7 @@ const startAgents = async () => {
263264

264265
let charactersArg = args.characters || args.character;
265266

266-
let characters = [character];
267+
let characters = [blobert];
267268

268269
if (charactersArg) {
269270
characters = await loadCharacters(charactersArg);

packages/client-discord/src/voice.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,11 @@ import {
3131
ITranscriptionService,
3232
Memory,
3333
ModelClass,
34-
Service,
3534
ServiceType,
3635
State,
3736
UUID,
3837
} from "@ai16z/eliza";
39-
import { stringToUuid } from "@ai16z/eliza/src/uuid.ts";
38+
import { stringToUuid } from "@ai16z/eliza";
4039

4140
export function getWavHeader(
4241
audioLength: number,

packages/client-twitter/src/base.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ export class ClientBase extends EventEmitter {
207207
);
208208
await this.setCookiesFromArray(cookiesArray);
209209
} else {
210-
console.log("Cookies file path:", cookiesFilePath);
210+
elizaLogger.debug("Cookies file path:", cookiesFilePath);
211211
if (fs.existsSync(cookiesFilePath)) {
212212
const cookiesArray = JSON.parse(
213213
fs.readFileSync(cookiesFilePath, "utf-8")

packages/client-twitter/src/interactions.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { SearchMode, Tweet } from "agent-twitter-client";
22
import fs from "fs";
3-
import { composeContext } from "@ai16z/eliza";
3+
import { composeContext, elizaLogger } from "@ai16z/eliza";
44
import { generateMessageResponse, generateShouldRespond } from "@ai16z/eliza";
55
import { messageCompletionFooter, shouldRespondFooter } from "@ai16z/eliza";
66
import {
@@ -199,7 +199,7 @@ export class TwitterInteractionClient extends ClientBase {
199199
console.log("skipping tweet with no text", tweet.id);
200200
return { text: "", action: "IGNORE" };
201201
}
202-
console.log("handling tweet", tweet.id);
202+
elizaLogger.log("handling tweet", tweet.id);
203203
const formatTweet = (tweet: Tweet) => {
204204
return ` ID: ${tweet.id}
205205
From: ${tweet.name} (@${tweet.username})
@@ -267,8 +267,6 @@ export class TwitterInteractionClient extends ClientBase {
267267
this.saveRequestMessage(message, state);
268268
}
269269

270-
console.log("composeState done");
271-
272270
const shouldRespondContext = composeContext({
273271
state,
274272
template:

packages/core/src/embedding.ts

+3-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
21
import path from "node:path";
32

4-
53
import { models } from "./models.ts";
64
import { IAgentRuntime, ModelProviderName, ModelClass } from "./types.ts";
75
import fs from "fs";
@@ -29,8 +27,6 @@ async function getRemoteEmbedding(
2927
// Construct full URL
3028
const fullUrl = `${baseEndpoint}/embeddings`;
3129

32-
//console.log("Calling embedding API at:", fullUrl); // Debug log
33-
3430
const requestOptions = {
3531
method: "POST",
3632
headers: {
@@ -52,7 +48,7 @@ async function getRemoteEmbedding(
5248
const response = await fetch(fullUrl, requestOptions);
5349

5450
if (!response.ok) {
55-
console.error("API Response:", await response.text()); // Debug log
51+
elizaLogger.error("API Response:", await response.text()); // Debug log
5652
throw new Error(
5753
`Embedding API Error: ${response.status} ${response.statusText}`
5854
);
@@ -65,7 +61,7 @@ async function getRemoteEmbedding(
6561
const data: EmbeddingResponse = await response.json();
6662
return data?.data?.[0].embedding;
6763
} catch (e) {
68-
console.error("Full error details:", e);
64+
elizaLogger.error("Full error details:", e);
6965
throw e;
7066
}
7167
}
@@ -176,7 +172,7 @@ export async function retrieveCachedEmbedding(
176172
input: string
177173
) {
178174
if (!input) {
179-
console.log("No input to retrieve cached embedding for");
175+
elizaLogger.log("No input to retrieve cached embedding for");
180176
return null;
181177
}
182178

packages/core/src/memory.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { embed } from "./embedding.ts";
2+
import elizaLogger from "./logger.ts";
23
import {
34
IAgentRuntime,
45
IMemoryManager,
@@ -160,7 +161,7 @@ export class MemoryManager implements IMemoryManager {
160161
await this.runtime.databaseAdapter.getMemoryById(memory.id);
161162

162163
if (existingMessage) {
163-
// console.log("Memory already exists, skipping");
164+
elizaLogger.debug("Memory already exists, skipping");
164165
return;
165166
}
166167
await this.runtime.databaseAdapter.createMemory(

packages/core/src/runtime.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,6 @@ export class AgentRuntime implements IAgentRuntime {
131131
services: Map<ServiceType, Service> = new Map();
132132
memoryManagers: Map<string, IMemoryManager> = new Map();
133133

134-
logging: boolean = false;
135-
136134
registerMemoryManager(manager: IMemoryManager): void {
137135
if (!manager.tableName) {
138136
throw new Error("Memory manager must have a tableName");
@@ -428,7 +426,6 @@ export class AgentRuntime implements IAgentRuntime {
428426
state?: State,
429427
callback?: HandlerCallback
430428
): Promise<void> {
431-
console.log("Processing actions", responses);
432429
if (!responses[0].content?.action) {
433430
elizaLogger.warn("No action found in the response content.");
434431
return;
@@ -499,7 +496,7 @@ export class AgentRuntime implements IAgentRuntime {
499496
async evaluate(message: Memory, state?: State, didRespond?: boolean) {
500497
const evaluatorPromises = this.evaluators.map(
501498
async (evaluator: Evaluator) => {
502-
console.log("Evaluating", evaluator.name);
499+
elizaLogger.log("Evaluating", evaluator.name);
503500
if (!evaluator.handler) {
504501
return null;
505502
}

packages/core/src/types.ts

+6
Original file line numberDiff line numberDiff line change
@@ -670,3 +670,9 @@ export enum ServiceType {
670670
SPEECH_GENERATION = "speech_generation",
671671
PDF = "pdf",
672672
}
673+
674+
export enum LoggingLevel {
675+
DEBUG = "debug",
676+
VERBOSE = "verbose",
677+
NONE = "none",
678+
}

packages/plugin-starknet/readme.md

+5
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,8 @@ Reuse providers and utilities from the existing actions where possible. Add more
1010

1111
1. Add the action to the `actions` directory. Try to follow the naming convention of the other actions.
1212
2. Export the action in the `index.ts` file.
13+
14+
## TODO:
15+
16+
1. Ekubo DCA
17+
2. Unruggable

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

+69-8
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,46 @@ import {
1717

1818
import { getStarknetAccount, validateSettings } from "../utils/index.ts";
1919

20+
interface SwapContent {
21+
sellTokenAddress: string;
22+
buyTokenAddress: string;
23+
sellAmount: string;
24+
}
25+
26+
export function isSwapContent(content: SwapContent): content is SwapContent {
27+
// Validate types
28+
const validTypes =
29+
typeof content.sellTokenAddress === "string" &&
30+
typeof content.buyTokenAddress === "string" &&
31+
typeof content.sellAmount === "string";
32+
if (!validTypes) {
33+
return false;
34+
}
35+
36+
// Validate addresses (must be 32-bytes long with 0x prefix)
37+
const validAddresses =
38+
content.sellTokenAddress.startsWith("0x") &&
39+
content.sellTokenAddress.length === 66 &&
40+
content.buyTokenAddress.startsWith("0x") &&
41+
content.buyTokenAddress.length === 66;
42+
43+
return validAddresses;
44+
}
45+
2046
const swapTemplate = `Respond with a JSON markdown block containing only the extracted values. Use null for any values that cannot be determined.
2147
48+
These are known addresses you will get asked to swap, use these addresses for sellTokenAddress and buyTokenAddress:
49+
- BROTHER/brother/$brother: 0x03b405a98c9e795d427fe82cdeeeed803f221b52471e3a757574a2b4180793ee
50+
- BTC/btc: 0x03fe2b97c1fd336e750087d68b9b867997fd64a2661ff3ca5a7c771641e8e7ac
51+
- ETH/eth: 0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7
52+
- STRK/strk: 0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d
53+
- LORDS/lords: 0x0124aeb495b947201f5fac96fd1138e326ad86195b98df6dec9009158a533b49
54+
2255
Example response:
2356
\`\`\`json
2457
{
2558
"sellTokenAddress": "0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7",
26-
"buyTokenAddress": "0x053c91253bc9682c04929ca02ed00b3e423f6710d2ee7e0d5ebb06f3ecf368a8",
59+
"buyTokenAddress": "0x124aeb495b947201f5fac96fd1138e326ad86195b98df6dec9009158a533b49",
2760
"sellAmount": "1000000000000000000"
2861
}
2962
\`\`\`
@@ -48,7 +81,8 @@ export const executeSwap: Action = {
4881
validate: async (runtime: IAgentRuntime, message: Memory) => {
4982
return validateSettings(runtime);
5083
},
51-
description: "Perform a token swap using Avnu.",
84+
description:
85+
"Perform a token swap on starknet. Use this action when a user asks you to swap tokens anything.",
5286
handler: async (
5387
runtime: IAgentRuntime,
5488
message: Memory,
@@ -75,6 +109,11 @@ export const executeSwap: Action = {
75109

76110
console.log("Response:", response);
77111

112+
if (!isSwapContent(response)) {
113+
callback?.({ text: "Invalid swap content, please try again." });
114+
return false;
115+
}
116+
78117
try {
79118
// Get quote
80119
const quoteParams: QuoteRequest = {
@@ -105,7 +144,7 @@ export const executeSwap: Action = {
105144
return true;
106145
} catch (error) {
107146
console.error("Error during token swap:", error);
108-
callback?.({ text: `Error during swap: ${error.message}` });
147+
callback?.({ text: `Error during swap:` });
109148
return false;
110149
}
111150
},
@@ -114,19 +153,41 @@ export const executeSwap: Action = {
114153
{
115154
user: "{{user1}}",
116155
content: {
117-
text: "Swap 1 ETH for USDC on Starknet",
156+
text: "Swap 10 ETH for LORDS",
157+
},
158+
},
159+
{
160+
user: "{{agent}}",
161+
content: {
162+
text: "Ok, I'll swap 10 ETH for LORDS",
163+
},
164+
},
165+
],
166+
[
167+
{
168+
user: "{{user1}}",
169+
content: {
170+
text: "Swap 100 $lords on starknet",
118171
},
119172
},
120173
{
121-
user: "{{user2}}",
174+
user: "{{agent}}",
175+
content: {
176+
text: "Ok, I'll swap 100 $lords on starknet",
177+
},
178+
},
179+
],
180+
[
181+
{
182+
user: "{{user1}}",
122183
content: {
123-
text: "Buy LORDS on Starknet",
184+
text: "Swap 0.5 BTC for LORDS",
124185
},
125186
},
126187
{
127-
user: "{{user2}}",
188+
user: "{{agent}}",
128189
content: {
129-
text: "Executing swap...",
190+
text: "Ok, I'll swap 0.5 BTC for LORDS",
130191
},
131192
},
132193
],

packages/plugin-starknet/src/actions/takeOrder.ts

+18-18
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,7 @@ interface Order {
2020
price: number;
2121
}
2222

23-
const take_order: Action = {
24-
name: "TAKE_STARKNET_ORDER",
25-
similes: ["BUY_STARKNET_ORDER", "PLACE_STARKNET_ORDER"],
26-
description:
27-
"Records a starknet buy order based on the user's conviction level.",
28-
examples: [],
29-
validate: async (runtime: IAgentRuntime, message: Memory) => {
30-
const text = (message.content as Content).text;
31-
// Check if the message contains a ticker symbol
32-
const tickerRegex = /\b[A-Z]{1,5}\b/g;
33-
return tickerRegex.test(text);
34-
},
35-
handler: async (runtime: IAgentRuntime, message: Memory) => {
36-
const text = (message.content as Content).text;
37-
const userId = message.userId;
38-
39-
const template = `
23+
const template = `
4024
4125
// CLAUDE TODO: Put the usual conversation context here
4226
@@ -52,6 +36,21 @@ Determine if the user is trying to shill the ticker. if they are, respond with e
5236
// - contractAddress: string
5337
`;
5438

39+
const take_order: Action = {
40+
name: "TAKE_STARKNET_ORDER",
41+
similes: ["BUY_STARKNET_ORDER", "PLACE_STARKNET_ORDER"],
42+
description:
43+
"Records a starknet buy order based on the user's conviction level.",
44+
validate: async (runtime: IAgentRuntime, message: Memory) => {
45+
const text = (message.content as Content).text;
46+
// Check if the message contains a ticker symbol
47+
const tickerRegex = /\b[A-Z]{1,5}\b/g;
48+
return tickerRegex.test(text);
49+
},
50+
handler: async (runtime: IAgentRuntime, message: Memory) => {
51+
const text = (message.content as Content).text;
52+
const userId = message.userId;
53+
5554
let ticker, contractAddress;
5655

5756
// TODO:
@@ -130,6 +129,7 @@ Determine if the user is trying to shill the ticker. if they are, respond with e
130129
text: `Recorded a ${conviction} conviction buy order for ${ticker} (${contractAddress}) with an amount of ${buyAmount} at the price of ${currentPrice}.`,
131130
};
132131
},
133-
};
132+
examples: [] as ActionExample[][],
133+
} as Action;
134134

135135
export default take_order;

0 commit comments

Comments
 (0)