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

fix: some trust fixes #346

Merged
merged 7 commits into from
Nov 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
7,245 changes: 7,245 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions packages/agent/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ export async function createAgent(
token: string
) {
console.log("Creating runtime for character", character.name);
console.log("character.settings.secrets?.WALLET_PUBLIC_KEY", character.settings.secrets?.WALLET_PUBLIC_KEY)
return new AgentRuntime({
databaseAdapter: db,
token,
Expand Down
2 changes: 1 addition & 1 deletion packages/client-auto/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class AutoClient {
this.runtime = runtime;

const trustScoreDb = new TrustScoreDatabase(runtime.databaseAdapter.db);
this.trustScoreProvider = new TrustScoreManager(null, trustScoreDb);
this.trustScoreProvider = new TrustScoreManager(runtime, null, trustScoreDb);
this.walletProvider = new WalletProvider(
new Connection(runtime.getSetting("RPC_URL")),
new PublicKey(runtime.getSetting("WALLET_PUBLIC_KEY"))
Expand Down
56 changes: 29 additions & 27 deletions packages/client-discord/src/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,69 +82,71 @@ export type InterestChannels = {
};

const discordShouldRespondTemplate =
`# Task: Decide if {{agentName}} should respond.
About {{agentName}}:
`# About {{agentName}}:
{{bio}}

# INSTRUCTIONS: Determine if {{agentName}} should respond to the message and participate in the conversation. Do not comment. Just respond with "RESPOND" or "IGNORE" or "STOP".

# RESPONSE EXAMPLES
<user 1>: I just saw a really great movie
<user 2>: Oh? Which movie?
{{user1}}: I just saw a really great movie
{{user2}}: Oh? Which movie?
Result: [IGNORE]

{{agentName}}: Oh, this is my favorite scene
<user 1>: sick
<user 2>: wait, why is it your favorite scene
{{user1}}: sick
{{user2}}: wait, why is it your favorite scene
Result: [RESPOND]

<user>: stfu bot
{{user1}}: stfu bot
Result: [STOP]

<user>: Hey {{agent}}, can you help me with something
{{user1}}: Hey {{agent}}, can you help me with something
Result: [RESPOND]

<user>: {{agentName}} stfu plz
{{user1}}: {{agentName}} stfu plz
Result: [STOP]

<user>: i need help
{{user1}}: i need help
{{agentName}}: how can I help you?
<user>: no. i need help from someone else
{{user1}}: no. i need help from someone else
Result: [IGNORE]

<user>: Hey {{agent}}, can I ask you a question
{{user1}}: Hey {{agent}}, can I ask you a question
{{agentName}}: Sure, what is it
<user>: can you ask claude to create a basic react module that demonstrates a counter
{{user1}}: can you ask claude to create a basic react module that demonstrates a counter
Result: [RESPOND]

<user>: {{agentName}} can you tell me a story
<user>: {about a girl named elara
{{agentName}}: Sure.
{{agentName}}: Once upon a time, in a quaint little village, there was a curious girl named Elara.
{{agentName}}: Elara was known for her adventurous spirit and her knack for finding beauty in the mundane.
<user>: I'm loving it, keep going
{{user1}}: {{agentName}} can you tell me a story
{{agentName}}: uhhh...
{{user1}}: please do it
{{agentName}}: okay
{{agentName}}: once upon a time, in a quaint little village, there was a curious girl named elara
{{user1}}: I'm loving it, keep going
Result: [RESPOND]

<user>: {{agentName}} stop responding plz
{{user1}}: {{agentName}} stop responding plz
Result: [STOP]

<user>: okay, i want to test something. can you say marco?
{{user1}}: okay, i want to test something. {{agentName}}, can you say marco?
{{agentName}}: marco
<user>: great. okay, now do it again
{{user1}}: great. okay, now do it again
Result: [RESPOND]

Response options are [RESPOND], [IGNORE] and [STOP].

{{agentName}} is in a room with other users and is very worried about being annoying and saying too much.
{{agentName}} is in a room with other users and should only respond when they are being addressed, and should not respond if they are continuing a conversation that is very long.

Respond with [RESPOND] to messages that are directed at {{agentName}}, or participate in conversations that are interesting or relevant to their background.
If a message is not interesting or relevant, respond with [IGNORE]
Unless directly responding to a user, respond with [IGNORE] to messages that are very short or do not contain much information.
If a message is not interesting, relevant, or does not directly address {{agentName}}, respond with [IGNORE]

Also, respond with [IGNORE] to messages that are very short or do not contain much information.

If a user asks {{agentName}} to be quiet, respond with [STOP]
If {{agentName}} concludes a conversation and isn't part of the conversation anymore, respond with [STOP]

IMPORTANT: {{agentName}} is particularly sensitive about being annoying, so if there is any doubt, it is better to respond with [IGNORE].
If {{agentName}} is conversing with a user and they have not asked to stop, it is better to respond with [RESPOND].

The goal is to decide whether {{agentName}} should respond to the last message.

{{recentMessages}}

# INSTRUCTIONS: Choose the option that best describes {{agentName}}'s response to the last message. Ignore messages if they are addressed to someone else.
Expand Down
73 changes: 38 additions & 35 deletions packages/client-telegram/src/messageManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,69 +22,71 @@ import { ImageDescriptionService } from "@ai16z/plugin-node";
const MAX_MESSAGE_LENGTH = 4096; // Telegram's max message length

const telegramShouldRespondTemplate =
`# Task: Decide if {{agentName}} should respond.
About {{agentName}}:
`# About {{agentName}}:
{{bio}}

# INSTRUCTIONS: Determine if {{agentName}} should respond to the message and participate in the conversation. Do not comment. Just respond with "RESPOND" or "IGNORE" or "STOP".

# RESPONSE EXAMPLES
<user 1>: I just saw a really great movie
<user 2>: Oh? Which movie?
{{user1}}: I just saw a really great movie
{{user2}}: Oh? Which movie?
Result: [IGNORE]

{{agentName}}: Oh, this is my favorite scene
<user 1>: sick
<user 2>: wait, why is it your favorite scene
{{user1}}: sick
{{user2}}: wait, why is it your favorite scene
Result: [RESPOND]

<user>: stfu bot
{{user1}}: stfu bot
Result: [STOP]

<user>: Hey {{agent}}, can you help me with something
{{user1}}: Hey {{agent}}, can you help me with something
Result: [RESPOND]

<user>: {{agentName}} stfu plz
{{user1}}: {{agentName}} stfu plz
Result: [STOP]

<user>: i need help
{{user1}}: i need help
{{agentName}}: how can I help you?
<user>: no. i need help from someone else
{{user1}}: no. i need help from someone else
Result: [IGNORE]

<user>: Hey {{agent}}, can I ask you a question
{{user1}}: Hey {{agent}}, can I ask you a question
{{agentName}}: Sure, what is it
<user>: can you ask claude to create a basic react module that demonstrates a counter
{{user1}}: can you ask claude to create a basic react module that demonstrates a counter
Result: [RESPOND]

<user>: {{agentName}} can you tell me a story
<user>: {about a girl named elara
{{agentName}}: Sure.
{{agentName}}: Once upon a time, in a quaint little village, there was a curious girl named Elara.
{{agentName}}: Elara was known for her adventurous spirit and her knack for finding beauty in the mundane.
<user>: I'm loving it, keep going
{{user1}}: {{agentName}} can you tell me a story
{{agentName}}: uhhh...
{{user1}}: please do it
{{agentName}}: okay
{{agentName}}: once upon a time, in a quaint little village, there was a curious girl named elara
{{user1}}: I'm loving it, keep going
Result: [RESPOND]

<user>: {{agentName}} stop responding plz
{{user1}}: {{agentName}} stop responding plz
Result: [STOP]

<user>: okay, i want to test something. can you say marco?
{{user1}}: okay, i want to test something. {{agentName}}, can you say marco?
{{agentName}}: marco
<user>: great. okay, now do it again
{{user1}}: great. okay, now do it again
Result: [RESPOND]

Response options are [RESPOND], [IGNORE] and [STOP].

{{agentName}} is in a room with other users and is very worried about being annoying and saying too much.
{{agentName}} is in a room with other users and should only respond when they are being addressed, and should not respond if they are continuing a conversation that is very long.

Respond with [RESPOND] to messages that are directed at {{agentName}}, or participate in conversations that are interesting or relevant to their background.
If a message is not interesting or relevant, respond with [IGNORE]
Unless directly responding to a user, respond with [IGNORE] to messages that are very short or do not contain much information.
If a message is not interesting, relevant, or does not directly address {{agentName}}, respond with [IGNORE]

Also, respond with [IGNORE] to messages that are very short or do not contain much information.

If a user asks {{agentName}} to be quiet, respond with [STOP]
If {{agentName}} concludes a conversation and isn't part of the conversation anymore, respond with [STOP]

IMPORTANT: {{agentName}} is particularly sensitive about being annoying, so if there is any doubt, it is better to respond with [IGNORE].
If {{agentName}} is conversing with a user and they have not asked to stop, it is better to respond with [RESPOND].

The goal is to decide whether {{agentName}} should respond to the last message.

{{recentMessages}}

# INSTRUCTIONS: Choose the option that best describes {{agentName}}'s response to the last message. Ignore messages if they are addressed to someone else.
Expand Down Expand Up @@ -375,14 +377,14 @@ export class MessageManager {
const content: Content = {
text: fullText,
source: "telegram",
inReplyTo:
"reply_to_message" in message && message.reply_to_message
? stringToUuid(
message.reply_to_message.message_id.toString() +
"-" +
this.runtime.agentId
)
: undefined,
// inReplyTo:
// "reply_to_message" in message && message.reply_to_message
// ? stringToUuid(
// message.reply_to_message.message_id.toString() +
// "-" +
// this.runtime.agentId
// )
// : undefined,
};

// Create memory for the message
Expand All @@ -404,6 +406,7 @@ export class MessageManager {

// Decide whether to respond
const shouldRespond = await this._shouldRespond(message, state);
console.log("Should respond", shouldRespond);
if (shouldRespond) {
// Generate response
const context = composeContext({
Expand Down
2 changes: 2 additions & 0 deletions packages/plugin-solana/src/actions/swap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ export const executeSwap: Action = {
});

const trustScoreDatabase = new TrustScoreManager(
runtime,
tokenProvider,
trustScoreDb
);
Expand Down Expand Up @@ -442,6 +443,7 @@ export const executeSwap: Action = {
});

const trustScoreDatabase = new TrustScoreManager(
runtime,
tokenProvider,
trustScoreDb
);
Expand Down
11 changes: 9 additions & 2 deletions packages/plugin-solana/src/evaluators/trust.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ async function handler(runtime: IAgentRuntime, message: Memory) {
return [];
}

console.log("Processing recommendations");

// Get recent recommendations
const recommendationsManager = new MemoryManager({
runtime,
Expand Down Expand Up @@ -180,6 +182,7 @@ async function handler(runtime: IAgentRuntime, message: Memory) {

const trustScoreDb = new TrustScoreDatabase(runtime.databaseAdapter.db);
const trustScoreManager = new TrustScoreManager(
runtime,
tokenProvider,
trustScoreDb
);
Expand Down Expand Up @@ -217,9 +220,13 @@ async function handler(runtime: IAgentRuntime, message: Memory) {

await recommendationsManager.createMemory(recMemory, true);

console.log("recommendationsManager", rec);

// - from here we just need to make sure code is right

// buy, dont buy, sell, dont sell

const buyAmounts = await this.tokenProvider.getBuyAmounts();
const buyAmounts = await tokenProvider.calculateBuyAmounts();

let buyAmount = buyAmounts[rec.conviction.toLowerCase().trim()];
if (!buyAmount) {
Expand All @@ -229,7 +236,7 @@ async function handler(runtime: IAgentRuntime, message: Memory) {
}

// TODO: is this is a buy, sell, dont buy, or dont sell?
const shouldTrade = await this.tokenProvider.shouldTradeToken();
const shouldTrade = await tokenProvider.shouldTradeToken();

if (!shouldTrade) {
console.warn(
Expand Down
18 changes: 13 additions & 5 deletions packages/plugin-solana/src/providers/trustScoreProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,26 @@ interface TokenRecommendationSummary {
export class TrustScoreManager {
private tokenProvider: TokenProvider;
private trustScoreDb: TrustScoreDatabase;
private connection: Connection = new Connection(settings.RPC_URL!);
private baseMint: PublicKey = new PublicKey(settings.BASE_MINT!);
private connection: Connection;
private baseMint: PublicKey;
private DECAY_RATE = 0.95;
private MAX_DECAY_DAYS = 30;
private backend = settings.BACKEND_URL; // TODO add to .env
private backendToken = settings.BACKEND_TOKEN; // TODO add to .env
private backend;
private backendToken;
constructor(
runtime: IAgentRuntime,
tokenProvider: TokenProvider,
trustScoreDb: TrustScoreDatabase
) {
this.tokenProvider = tokenProvider;
this.trustScoreDb = trustScoreDb;
this.connection = new Connection(runtime.getSetting("RPC_URL"));
this.baseMint = new PublicKey(
runtime.getSetting("BASE_MINT") ||
"So11111111111111111111111111111111111111112"
);
this.backend = runtime.getSetting("BACKEND_URL");
this.backendToken = runtime.getSetting("BACKEND_TOKEN");
}

//getRecommenederBalance
Expand Down Expand Up @@ -339,7 +347,7 @@ export class TrustScoreManager {
const processedData: ProcessedTokenData =
await this.tokenProvider.getProcessedTokenData();
const wallet = new WalletProvider(
new Connection("https://api.mainnet-beta.solana.com"),
this.connection,
new PublicKey(Wallet!)
);

Expand Down
Loading
Loading