From c1889575ba171525b653c27c4593fefd0c1b032b Mon Sep 17 00:00:00 2001 From: xm0onh Date: Tue, 7 Jan 2025 15:59:33 -0800 Subject: [PATCH 1/7] refactoring .env vars - remove unconfidential vars --- auto-agents-framework/.env.sample | 14 +--------- auto-agents-framework/src/config/index.ts | 31 ++------------------- auto-agents-framework/src/config/schema.ts | 1 - auto-agents-framework/src/config/twitter.ts | 12 ++++++++ 4 files changed, 16 insertions(+), 42 deletions(-) create mode 100644 auto-agents-framework/src/config/twitter.ts diff --git a/auto-agents-framework/.env.sample b/auto-agents-framework/.env.sample index f78f26d..1142598 100644 --- a/auto-agents-framework/.env.sample +++ b/auto-agents-framework/.env.sample @@ -3,16 +3,7 @@ TWITTER_USERNAME= TWITTER_PASSWORD= # Twitter data fetch and post configuration -NUM_TIMELINE_TWEETS=10 -NUM_FOLLOWING_RECENT_TWEETS=10 -NUM_RANDOM_FOLLOWERS=5 -MAX_MENTIONS=20 -MAX_THREAD_LENGTH=20 -MAX_MY_RECENT_TWEETS=10 -MAX_MY_RECENT_REPLIES=10 -POST_TWEETS=false -RESPONSE_INTERVAL_MINUTES=26 -POST_INTERVAL_MINUTES=30 +# See src/config/twitter.ts for more details # LLM Configuration OPENAI_API_KEY= @@ -36,8 +27,5 @@ SERPAPI_API_KEY= # Environment NODE_ENV= -# Retry Limit -RETRY_LIMIT= - # Agent Version AGENT_VERSION= \ No newline at end of file diff --git a/auto-agents-framework/src/config/index.ts b/auto-agents-framework/src/config/index.ts index e4b1d84..158b18f 100644 --- a/auto-agents-framework/src/config/index.ts +++ b/auto-agents-framework/src/config/index.ts @@ -5,7 +5,7 @@ import path from 'path'; import { fileURLToPath } from 'url'; import { mkdir } from 'fs/promises'; import { llmConfig } from './llm.js'; - +import { twitterConfig } from './twitter.js'; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); const workspaceRoot = path.resolve(__dirname, '../..'); @@ -41,34 +41,10 @@ export const config = (() => { USERNAME: username, PASSWORD: process.env.TWITTER_PASSWORD || '', COOKIES_PATH: cookiesPath, - NUM_TIMELINE_TWEETS: Number(process.env.NUM_TIMELINE_TWEETS) || 10, - NUM_FOLLOWING_RECENT_TWEETS: Number(process.env.NUM_FOLLOWING_RECENT_TWEETS) || 10, - NUM_RANDOM_FOLLOWERS: Number(process.env.NUM_RANDOM_FOLLOWERS) || 5, - MAX_MENTIONS: Number(process.env.MAX_MENTIONS) || 5, - MAX_THREAD_LENGTH: Number(process.env.MAX_THREAD_LENGTH) || 20, - MAX_MY_RECENT_TWEETS: Number(process.env.MAX_MY_RECENT_TWEETS) || 10, - MAX_MY_RECENT_REPLIES: Number(process.env.MAX_MY_RECENT_REPLIES) || 10, - POST_TWEETS: process.env.POST_TWEETS === 'true', - RESPONSE_INTERVAL_MS: (Number(process.env.RESPONSE_INTERVAL_MINUTES) || 60) * 60 * 1000, - POST_INTERVAL_MS: (Number(process.env.POST_INTERVAL_MINUTES) || 90) * 60 * 1000, + ...twitterConfig, }, llmConfig: { - configuration: { - large: { - provider: llmConfig.configuration.large.provider, - model: llmConfig.configuration.large.model, - }, - small: { - provider: llmConfig.configuration.small.provider, - model: llmConfig.configuration.small.model, - }, - }, - nodes: { - decision: llmConfig.nodes.decision, - analyze: llmConfig.nodes.analyze, - generation: llmConfig.nodes.generation, - response: llmConfig.nodes.response, - }, + ...llmConfig, OPENAI_API_KEY: process.env.OPENAI_API_KEY || '', ANTHROPIC_API_KEY: process.env.ANTHROPIC_API_KEY || '', LLAMA_API_URL: process.env.LLAMA_API_URL || '', @@ -85,7 +61,6 @@ export const config = (() => { }, SERPAPI_API_KEY: process.env.SERPAPI_API_KEY || '', NODE_ENV: process.env.NODE_ENV || 'development', - RETRY_LIMIT: Number(process.env.RETRY_LIMIT) || 2, }; return configSchema.parse(rawConfig); diff --git a/auto-agents-framework/src/config/schema.ts b/auto-agents-framework/src/config/schema.ts index 11dddc8..adf1d70 100644 --- a/auto-agents-framework/src/config/schema.ts +++ b/auto-agents-framework/src/config/schema.ts @@ -135,5 +135,4 @@ export const configSchema = z.object({ blockchainConfig: blockchainConfigSchema, SERPAPI_API_KEY: SERPAPI_API_KEY, NODE_ENV: z.enum(['development', 'production', 'test']), - RETRY_LIMIT: z.number().int().nonnegative(), }); diff --git a/auto-agents-framework/src/config/twitter.ts b/auto-agents-framework/src/config/twitter.ts new file mode 100644 index 0000000..ce3df7f --- /dev/null +++ b/auto-agents-framework/src/config/twitter.ts @@ -0,0 +1,12 @@ +export const twitterConfig = { + NUM_TIMELINE_TWEETS: 10, + NUM_FOLLOWING_RECENT_TWEETS: 10, + NUM_RANDOM_FOLLOWERS: 5, + MAX_MENTIONS: 20, + MAX_THREAD_LENGTH: 20, + MAX_MY_RECENT_TWEETS: 10, + MAX_MY_RECENT_REPLIES: 10, + RESPONSE_INTERVAL_MS: 60 * 60 * 1000, + POST_INTERVAL_MS: 90 * 60 * 1000, + POST_TWEETS: false, +}; From a3a1caeaf3085240f646c38de08ce6342c8b43d0 Mon Sep 17 00:00:00 2001 From: xm0onh Date: Wed, 8 Jan 2025 13:01:14 -0800 Subject: [PATCH 2/7] Add YAML file for configuration --- auto-agents-framework/.gitignore | 4 ++- .../src/config/config.example.yaml | 34 +++++++++++++++++++ auto-agents-framework/src/config/index.ts | 18 +++++++++- .../src/services/llm/factory.ts | 3 +- 4 files changed, 55 insertions(+), 4 deletions(-) create mode 100644 auto-agents-framework/src/config/config.example.yaml diff --git a/auto-agents-framework/.gitignore b/auto-agents-framework/.gitignore index 3a17a8a..cd91a1a 100644 --- a/auto-agents-framework/.gitignore +++ b/auto-agents-framework/.gitignore @@ -1,4 +1,6 @@ characters/ !characters/character.example.ts +*.yaml +!src/config/config.example.yaml .cookies/ -dsn-kol-schemas.json \ No newline at end of file +dsn-kol-schemas.json diff --git a/auto-agents-framework/src/config/config.example.yaml b/auto-agents-framework/src/config/config.example.yaml new file mode 100644 index 0000000..cf89745 --- /dev/null +++ b/auto-agents-framework/src/config/config.example.yaml @@ -0,0 +1,34 @@ +twitter: + NUM_TIMELINE_TWEETS: 10 + NUM_FOLLOWING_RECENT_TWEETS: 10 + NUM_RANDOM_FOLLOWERS: 5 + MAX_MENTIONS: 20 + MAX_THREAD_LENGTH: 20 + MAX_MY_RECENT_TWEETS: 10 + MAX_MY_RECENT_REPLIES: 10 + RESPONSE_INTERVAL_MS: 3600000 + POST_INTERVAL_MS: 5400000 + POST_TWEETS: false + +llm: + configuration: + large: + provider: "anthropic" + model: "claude-3-5-sonnet-latest" + small: + provider: "openai" + model: "gpt-4o-mini" + + nodes: + decision: + size: "large" + temperature: 0.2 + analyze: + size: "large" + temperature: 0.5 + generation: + size: "large" + temperature: 0.8 + response: + size: "small" + temperature: 0.8 \ No newline at end of file diff --git a/auto-agents-framework/src/config/index.ts b/auto-agents-framework/src/config/index.ts index 158b18f..e449b10 100644 --- a/auto-agents-framework/src/config/index.ts +++ b/auto-agents-framework/src/config/index.ts @@ -6,6 +6,9 @@ import { fileURLToPath } from 'url'; import { mkdir } from 'fs/promises'; import { llmConfig } from './llm.js'; import { twitterConfig } from './twitter.js'; +import yaml from 'yaml'; +import { readFileSync } from 'fs'; + const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); const workspaceRoot = path.resolve(__dirname, '../..'); @@ -31,6 +34,17 @@ function formatZodError(error: z.ZodError) { export const agentVersion = process.env.AGENT_VERSION || '1.0.0'; +const yamlConfig = (() => { + try { + const configPath = path.join(workspaceRoot, 'src', 'config', 'config.yaml'); + const fileContents = readFileSync(configPath, 'utf8'); + return yaml.parse(fileContents); + } catch (error) { + console.info('No YAML config found, falling back to environment variables'); + return {}; + } +})(); + export const config = (() => { try { const username = process.env.TWITTER_USERNAME || ''; @@ -42,9 +56,11 @@ export const config = (() => { PASSWORD: process.env.TWITTER_PASSWORD || '', COOKIES_PATH: cookiesPath, ...twitterConfig, + ...(yamlConfig.twitter || {}), }, llmConfig: { ...llmConfig, + ...(yamlConfig.llm || {}), OPENAI_API_KEY: process.env.OPENAI_API_KEY || '', ANTHROPIC_API_KEY: process.env.ANTHROPIC_API_KEY || '', LLAMA_API_URL: process.env.LLAMA_API_URL || '', @@ -62,7 +78,7 @@ export const config = (() => { SERPAPI_API_KEY: process.env.SERPAPI_API_KEY || '', NODE_ENV: process.env.NODE_ENV || 'development', }; - + return configSchema.parse(rawConfig); } catch (error) { if (error instanceof z.ZodError) { diff --git a/auto-agents-framework/src/services/llm/factory.ts b/auto-agents-framework/src/services/llm/factory.ts index d916841..61786d0 100644 --- a/auto-agents-framework/src/services/llm/factory.ts +++ b/auto-agents-framework/src/services/llm/factory.ts @@ -2,12 +2,11 @@ import { ChatOpenAI } from '@langchain/openai'; import { ChatAnthropic } from '@langchain/anthropic'; import { ChatOllama } from '@langchain/ollama'; import { LLMProvider, LLMConfiguration, LLMNodeConfiguration } from './types.js'; -import { llmConfig } from '../../config/llm.js'; import { config as appConfig } from '../../config/index.js'; export class LLMFactory { static createModel(node: LLMNodeConfiguration) { - const cfg = llmConfig.configuration[node.size]; + const cfg = appConfig.llmConfig.configuration[node.size]; return this.createModelFromConfig(cfg, node.temperature); } From 888b2be507e63af979b1108666c81a04615b3c65 Mon Sep 17 00:00:00 2001 From: xm0onh Date: Wed, 8 Jan 2025 13:16:37 -0800 Subject: [PATCH 3/7] update readme and .env.sample --- auto-agents-framework/.env.sample | 4 -- auto-agents-framework/README.md | 66 +++++++++++++++++-- .../src/config/config.example.yaml | 4 +- auto-agents-framework/src/config/index.ts | 2 +- 4 files changed, 63 insertions(+), 13 deletions(-) diff --git a/auto-agents-framework/.env.sample b/auto-agents-framework/.env.sample index 1142598..7a7a179 100644 --- a/auto-agents-framework/.env.sample +++ b/auto-agents-framework/.env.sample @@ -2,14 +2,10 @@ TWITTER_USERNAME= TWITTER_PASSWORD= -# Twitter data fetch and post configuration -# See src/config/twitter.ts for more details - # LLM Configuration OPENAI_API_KEY= ANTHROPIC_API_KEY= LLAMA_API_URL= -# Config the models and sizes in src/config/llm.ts # AutoDrive Configuration AUTO_DRIVE_API_KEY= diff --git a/auto-agents-framework/README.md b/auto-agents-framework/README.md index 695b900..4c8a9d8 100644 --- a/auto-agents-framework/README.md +++ b/auto-agents-framework/README.md @@ -14,19 +14,73 @@ Auto-Agents-Framework is an experimental framework for building AI agents that c ## Getting Started 1. Install dependencies: - `yarn install -` + `yarn install` 2. Copy the environment file and configure your credentials: `cp .env.sample .env` 3. Configure your `.env` file with required credentials: - ``env + + ```env TWITTER_USERNAME=your_twitter_username TWITTER_PASSWORD=your_twitter_password OPENAI_API_KEY=your_openai_key - # See .env.sample for other configuration options - `` + See .env.sample for other configuration options + ``` + +4. The framework supports multiple levels of configuration with the following priority (highest to lowest): + + 1. Environment variables (`.env` file) + 2. YAML configuration (`config/default.yaml`) + 3. Default values in code + +This means you can: +- Use YAML for most settings +- Override sensitive data (like API keys) using environment variables +- Fall back to default values if nothing is specified +### YAML Configuration + +1. Copy the example configuration file: + ```bash + cp src/config/config.example.yaml config/default.yaml + ``` + +2. Customize the settings in `config/default.yaml`: + ```yaml + twitter: + NUM_TIMELINE_TWEETS: 10 + NUM_FOLLOWING_RECENT_TWEETS: 10 + NUM_RANDOM_FOLLOWERS: 5 + MAX_MENTIONS: 20 + MAX_THREAD_LENGTH: 20 + MAX_MY_RECENT_TWEETS: 10 + MAX_MY_RECENT_REPLIES: 10 + RESPONSE_INTERVAL_MS: 3600000 # 1 hour + POST_INTERVAL_MS: 5400000 # 1.5 hours + POST_TWEETS: false + + llm: + configuration: + large: + provider: "anthropic" + model: "claude-3-5-sonnet-latest" + small: + provider: "openai" + model: "gpt-4o-mini" + nodes: + decision: + size: "small" + temperature: 0.2 + analyze: + size: "large" + temperature: 0.5 + generation: + size: "large" + temperature: 0.8 + response: + size: "small" + temperature: 0.8 + ``` ## Character System @@ -156,4 +210,4 @@ Monitor the agent's activity in the console and configured log files. ## License -MIT +MIT \ No newline at end of file diff --git a/auto-agents-framework/src/config/config.example.yaml b/auto-agents-framework/src/config/config.example.yaml index cf89745..a4e49d2 100644 --- a/auto-agents-framework/src/config/config.example.yaml +++ b/auto-agents-framework/src/config/config.example.yaml @@ -18,10 +18,10 @@ llm: small: provider: "openai" model: "gpt-4o-mini" - + nodes: decision: - size: "large" + size: "small" temperature: 0.2 analyze: size: "large" diff --git a/auto-agents-framework/src/config/index.ts b/auto-agents-framework/src/config/index.ts index e449b10..5e79376 100644 --- a/auto-agents-framework/src/config/index.ts +++ b/auto-agents-framework/src/config/index.ts @@ -78,7 +78,7 @@ export const config = (() => { SERPAPI_API_KEY: process.env.SERPAPI_API_KEY || '', NODE_ENV: process.env.NODE_ENV || 'development', }; - + return configSchema.parse(rawConfig); } catch (error) { if (error instanceof z.ZodError) { From 525ea24cab872ed209565bbc8ff6b811fae443f1 Mon Sep 17 00:00:00 2001 From: xm0onh Date: Wed, 8 Jan 2025 13:22:52 -0800 Subject: [PATCH 4/7] clean coding config --- auto-agents-framework/src/config/index.ts | 8 ++++---- auto-agents-framework/src/config/llm.ts | 2 +- auto-agents-framework/src/config/twitter.ts | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/auto-agents-framework/src/config/index.ts b/auto-agents-framework/src/config/index.ts index 5e79376..db058fe4 100644 --- a/auto-agents-framework/src/config/index.ts +++ b/auto-agents-framework/src/config/index.ts @@ -4,8 +4,8 @@ import { configSchema } from './schema.js'; import path from 'path'; import { fileURLToPath } from 'url'; import { mkdir } from 'fs/promises'; -import { llmConfig } from './llm.js'; -import { twitterConfig } from './twitter.js'; +import { llmDefaultConfig } from './llm.js'; +import { twitterDefaultConfig } from './twitter.js'; import yaml from 'yaml'; import { readFileSync } from 'fs'; @@ -55,11 +55,11 @@ export const config = (() => { USERNAME: username, PASSWORD: process.env.TWITTER_PASSWORD || '', COOKIES_PATH: cookiesPath, - ...twitterConfig, + ...twitterDefaultConfig, ...(yamlConfig.twitter || {}), }, llmConfig: { - ...llmConfig, + ...llmDefaultConfig, ...(yamlConfig.llm || {}), OPENAI_API_KEY: process.env.OPENAI_API_KEY || '', ANTHROPIC_API_KEY: process.env.ANTHROPIC_API_KEY || '', diff --git a/auto-agents-framework/src/config/llm.ts b/auto-agents-framework/src/config/llm.ts index 9299c19..f144a6f 100644 --- a/auto-agents-framework/src/config/llm.ts +++ b/auto-agents-framework/src/config/llm.ts @@ -1,6 +1,6 @@ import { LLMNodeConfiguration, LLMSize, LLMProvider, llmModels } from '../services/llm/types.js'; -export const llmConfig = { +export const llmDefaultConfig = { configuration: { large: { provider: LLMProvider.ANTHROPIC, diff --git a/auto-agents-framework/src/config/twitter.ts b/auto-agents-framework/src/config/twitter.ts index ce3df7f..7ce2283 100644 --- a/auto-agents-framework/src/config/twitter.ts +++ b/auto-agents-framework/src/config/twitter.ts @@ -1,4 +1,4 @@ -export const twitterConfig = { +export const twitterDefaultConfig = { NUM_TIMELINE_TWEETS: 10, NUM_FOLLOWING_RECENT_TWEETS: 10, NUM_RANDOM_FOLLOWERS: 5, From 49d139b9ffdbd2ef2739b9f6a31afce38f70a0c4 Mon Sep 17 00:00:00 2001 From: xm0onh Date: Wed, 8 Jan 2025 19:20:11 -0800 Subject: [PATCH 5/7] Update example yaml location --- .../src/config/config.example.yaml | 34 ------------------- auto-agents-framework/src/config/index.ts | 2 +- 2 files changed, 1 insertion(+), 35 deletions(-) delete mode 100644 auto-agents-framework/src/config/config.example.yaml diff --git a/auto-agents-framework/src/config/config.example.yaml b/auto-agents-framework/src/config/config.example.yaml deleted file mode 100644 index a4e49d2..0000000 --- a/auto-agents-framework/src/config/config.example.yaml +++ /dev/null @@ -1,34 +0,0 @@ -twitter: - NUM_TIMELINE_TWEETS: 10 - NUM_FOLLOWING_RECENT_TWEETS: 10 - NUM_RANDOM_FOLLOWERS: 5 - MAX_MENTIONS: 20 - MAX_THREAD_LENGTH: 20 - MAX_MY_RECENT_TWEETS: 10 - MAX_MY_RECENT_REPLIES: 10 - RESPONSE_INTERVAL_MS: 3600000 - POST_INTERVAL_MS: 5400000 - POST_TWEETS: false - -llm: - configuration: - large: - provider: "anthropic" - model: "claude-3-5-sonnet-latest" - small: - provider: "openai" - model: "gpt-4o-mini" - - nodes: - decision: - size: "small" - temperature: 0.2 - analyze: - size: "large" - temperature: 0.5 - generation: - size: "large" - temperature: 0.8 - response: - size: "small" - temperature: 0.8 \ No newline at end of file diff --git a/auto-agents-framework/src/config/index.ts b/auto-agents-framework/src/config/index.ts index db058fe4..a19a3d5 100644 --- a/auto-agents-framework/src/config/index.ts +++ b/auto-agents-framework/src/config/index.ts @@ -36,7 +36,7 @@ export const agentVersion = process.env.AGENT_VERSION || '1.0.0'; const yamlConfig = (() => { try { - const configPath = path.join(workspaceRoot, 'src', 'config', 'config.yaml'); + const configPath = path.join(workspaceRoot, 'config', 'config.yaml'); const fileContents = readFileSync(configPath, 'utf8'); return yaml.parse(fileContents); } catch (error) { From 60e4324b5d73119fd32d48289ec9581881ccf741 Mon Sep 17 00:00:00 2001 From: xm0onh Date: Wed, 8 Jan 2025 19:22:55 -0800 Subject: [PATCH 6/7] update readme file --- auto-agents-framework/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/auto-agents-framework/README.md b/auto-agents-framework/README.md index 4c8a9d8..1539b92 100644 --- a/auto-agents-framework/README.md +++ b/auto-agents-framework/README.md @@ -31,7 +31,7 @@ Auto-Agents-Framework is an experimental framework for building AI agents that c 4. The framework supports multiple levels of configuration with the following priority (highest to lowest): 1. Environment variables (`.env` file) - 2. YAML configuration (`config/default.yaml`) + 2. YAML configuration (`config/config.yaml`) 3. Default values in code This means you can: @@ -42,10 +42,10 @@ This means you can: 1. Copy the example configuration file: ```bash - cp src/config/config.example.yaml config/default.yaml + cp config/config.example.yaml config/config.yaml ``` -2. Customize the settings in `config/default.yaml`: +2. Customize the settings in `config/config.yaml`: ```yaml twitter: NUM_TIMELINE_TWEETS: 10 From 461c33a584b1a221d6f9f36fc117b73caf1cce62 Mon Sep 17 00:00:00 2001 From: xm0onh Date: Wed, 8 Jan 2025 19:27:31 -0800 Subject: [PATCH 7/7] update .gitignore --- auto-agents-framework/.gitignore | 2 +- .../config/config.example.yaml | 34 +++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 auto-agents-framework/config/config.example.yaml diff --git a/auto-agents-framework/.gitignore b/auto-agents-framework/.gitignore index cd91a1a..5effeac 100644 --- a/auto-agents-framework/.gitignore +++ b/auto-agents-framework/.gitignore @@ -1,6 +1,6 @@ characters/ !characters/character.example.ts *.yaml -!src/config/config.example.yaml +!config/config.example.yaml .cookies/ dsn-kol-schemas.json diff --git a/auto-agents-framework/config/config.example.yaml b/auto-agents-framework/config/config.example.yaml new file mode 100644 index 0000000..a4e49d2 --- /dev/null +++ b/auto-agents-framework/config/config.example.yaml @@ -0,0 +1,34 @@ +twitter: + NUM_TIMELINE_TWEETS: 10 + NUM_FOLLOWING_RECENT_TWEETS: 10 + NUM_RANDOM_FOLLOWERS: 5 + MAX_MENTIONS: 20 + MAX_THREAD_LENGTH: 20 + MAX_MY_RECENT_TWEETS: 10 + MAX_MY_RECENT_REPLIES: 10 + RESPONSE_INTERVAL_MS: 3600000 + POST_INTERVAL_MS: 5400000 + POST_TWEETS: false + +llm: + configuration: + large: + provider: "anthropic" + model: "claude-3-5-sonnet-latest" + small: + provider: "openai" + model: "gpt-4o-mini" + + nodes: + decision: + size: "small" + temperature: 0.2 + analyze: + size: "large" + temperature: 0.5 + generation: + size: "large" + temperature: 0.8 + response: + size: "small" + temperature: 0.8 \ No newline at end of file