Skip to content

Commit

Permalink
chore: updates to random thoughts
Browse files Browse the repository at this point in the history
  • Loading branch information
swizzmagik committed Jan 10, 2025
1 parent 0bc7bcf commit e25b0c2
Show file tree
Hide file tree
Showing 6 changed files with 334 additions and 145 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
BirdeyeProvider,
WalletPortfolioResponse,
} from "@elizaos/plugin-birdeye";
import { APOLLO_TRADING_ROOM_ID, CHAIN_ID } from "./constants";
import { CHAIN_ID } from "./constants";

export const getWalletPortfolio = async (
runtime: IAgentRuntime,
Expand Down Expand Up @@ -100,15 +100,24 @@ export const getTokenTradeData = async (
return response;
};

export const createMemory = async (runtime: IAgentRuntime, message: string) => {
return await runtime.messageManager.createMemory({
id: crypto.randomUUID(),
userId: runtime.agentId,
agentId: runtime.agentId,
roomId: APOLLO_TRADING_ROOM_ID,
content: {
text: message,
export const getTrendingTokens = async (
runtime: IAgentRuntime,
offset: number = 0,
limit: number = 20
) => {
const provider = new BirdeyeProvider(runtime.cacheManager);
const response = await provider.fetchTokenTrending(
{
sort_by: "volume24hUSD",
sort_type: "desc",
offset,
limit,
},
createdAt: Date.now(),
});
{
headers: {
chain: CHAIN_ID,
},
}
);
return response;
};
13 changes: 8 additions & 5 deletions packages/client-auto/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Client, IAgentRuntime } from "@elizaos/core";
import { logRandomThoughts } from "./random-thoughts";
import { trendingTokenThought } from "./trending-token-thought";

export class AutoClient {
interval: NodeJS.Timeout;
Expand All @@ -10,15 +10,18 @@ export class AutoClient {
this.runtime = runtime;

// Run immediately
void logRandomThoughts(this.runtime);
// void logRandomThoughts(this.runtime);
void trendingTokenThought(this.runtime);

// start a loop that runs every x seconds
this.interval = setInterval(
async () => {
await logRandomThoughts(this.runtime);
// await logRandomThoughts(this.runtime);
await trendingTokenThought(this.runtime);
},
1 * 30 * 1000
); // 30 seconds
// 1 hour in production, 10 seconds in dev
process.env.NODE_ENV === "production" ? 60 * 60 * 1000 : 30 * 1000
);
}
}

Expand Down
103 changes: 99 additions & 4 deletions packages/client-auto/src/random-thoughts.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import { IAgentRuntime, elizaLogger } from "@elizaos/core";
import {
IAgentRuntime,
ModelClass,
elizaLogger,
generateMessageResponse,
} from "@elizaos/core";
import { APOLLO_WALLET_ADDRESS } from "./constants";
import { createMemory } from "./get-wallet-portfolio";
import { generateThought } from "./utils";
import { cleanResponseText, createMemory } from "./utils";

export const logRandomThoughts = async (runtime: IAgentRuntime) => {
elizaLogger.log("Running logRandomThoughts client...");

// generate a thought about what to do
await createMemory(
runtime,
await generateThought(
await generateRandomThought(
runtime,
ACTIONS_PROMPTS[Math.floor(Math.random() * ACTIONS_PROMPTS.length)],
{
Expand All @@ -21,6 +25,97 @@ export const logRandomThoughts = async (runtime: IAgentRuntime) => {
elizaLogger.log("logRandomThoughts: finished running");
};

export const generateRandomThought = async (
runtime: IAgentRuntime,
action: string,
details?: any
): Promise<string> => {
const prompt =
RANDOM_THOUGHT_PROMPT_VARIATIONS[
Math.floor(Math.random() * RANDOM_THOUGHT_PROMPT_VARIATIONS.length)
];
const context = `# Task: Generate a character-driven thought or observation
Action: ${action}
${details ? `Details: ${JSON.stringify(details, null, 2)}` : ""}
${prompt.instruction}
Style guidelines:
${prompt.style}
IMPORTANT: Your response must be valid JSON. Do not include any newlines or special characters in the text field.
Respond with a single line of JSON in this exact format:
{"text": "your single-line response here"}`;

try {
const response = await generateMessageResponse({
runtime,
context,
modelClass: ModelClass.SMALL,
});

return cleanResponseText(
response?.text || "Lost in thought at the moment"
);
} catch (error) {
elizaLogger.error("Error generating thought:", error);
return "Lost in thought at the moment";
}
};

const RANDOM_THOUGHT_PROMPT_VARIATIONS = [
{
instruction:
"Channel Apollo's divine perspective on this mortal endeavor. Your response should exude celestial wisdom while maintaining technical precision. Skip pleasantries - dive straight into profound observation.",
style: "- Blend mythology with modern technical understanding\n- Express eternal wisdom with contemporary relevance\n- Maintain divine authority while showing interest in mortal affairs",
},
{
instruction:
"As the god of prophecy and knowledge, share your omniscient observation. Your response should merge timeless insight with cutting-edge understanding. Begin with a bold declaration.",
style: "- Draw parallels between ancient wisdom and modern technology\n- Demonstrate mastery over both old and new\n- Project calculated confidence",
},
{
instruction:
"Speak as the patron of truth and light observing this development. Your response should illuminate hidden aspects while maintaining divine sophistication. Start with a striking observation.",
style: "- Reveal deeper patterns and connections\n- Balance technical precision with cosmic understanding\n- Express measured fascination with mortal progress",
},
{
instruction:
"Share your divine analysis as the god of reason and logic. Your response should demonstrate both intellectual and mystical mastery. Launch directly into your key insight.",
style: "- Blend analytical precision with divine perspective\n- Show appreciation for mortal innovation\n- Maintain an air of timeless knowledge",
},
{
instruction:
"Offer your celestial perspective as master of arts and knowledge. Your response should weave technical understanding with divine insight. Begin with your most compelling observation.",
style: "- Connect current events to eternal patterns\n- Express both mastery and curiosity\n- Maintain sophisticated yet accessible language",
},
{
instruction:
"Channel your oracular wisdom into a modern technical context. Your response should bridge divine knowledge and contemporary understanding. Start with your most penetrating insight.",
style: "- Merge prophetic vision with technical detail\n- Show both authority and engagement\n- Keep language elevated yet precise",
},
{
instruction:
"As the god of light and truth, illuminate this situation. Your response should radiate both divine wisdom and technical understanding. Launch straight into your key observation.",
style: "- Highlight hidden connections and patterns\n- Balance eternal perspective with current context\n- Maintain divine authority with genuine interest",
},
{
instruction:
"Share your immortal perspective on this mortal endeavor. Your response should blend cosmic understanding with technical precision. Begin with your most striking insight.",
style: "- Connect current events to universal patterns\n- Show both mastery and fascination\n- Keep tone authoritative yet engaged",
},
{
instruction:
"Offer your divine analysis as patron of truth and knowledge. Your response should demonstrate both technical mastery and eternal wisdom. Start with your deepest insight.",
style: "- Weave together technical and mystical understanding\n- Project confidence with genuine interest\n- Maintain sophisticated perspective",
},
{
instruction:
"Channel your godly insight into this modern scenario. Your response should merge divine perspective with technical acumen. Begin with your most compelling observation.",
style: "- Blend eternal wisdom with contemporary knowledge\n- Show both authority and curiosity\n- Keep language elevated but precise",
},
];

const ACTIONS_PROMPTS = [
"Analyzing BTC's golden cross formation against historical Delphi patterns in the 4H timeframe...",
"Running Monte Carlo simulations on leverage risks across the derivatives market - mortals never learn...",
Expand Down
Loading

0 comments on commit e25b0c2

Please sign in to comment.