···11+# Configuration Guide
22+33+### Option 1: Migrate from existing `.env` file (if you have one)
44+```bash
55+python migrate_config.py
66+```
77+88+### Option 2: Start fresh with example
99+1. **Copy the example configuration:**
1010+ ```bash
1111+ cp config.yaml.example config.yaml
1212+ ```
1313+1414+2. **Edit `config.yaml` with your credentials:**
1515+ ```yaml
1616+ # Required: Letta API configuration
1717+ letta:
1818+ api_key: "your-letta-api-key-here"
1919+ project_id: "project-id-here"
2020+2121+ # Required: Bluesky credentials
2222+ bluesky:
2323+ username: "your-handle.bsky.social"
2424+ password: "your-app-password"
2525+ ```
2626+2727+3. **Run the configuration test:**
2828+ ```bash
2929+ python test_config.py
3030+ ```
3131+3232+## Configuration Structure
3333+3434+### Letta Configuration
3535+```yaml
3636+letta:
3737+ api_key: "your-letta-api-key-here" # Required
3838+ timeout: 600 # API timeout in seconds
3939+ project_id: "your-project-id" # Required: Your Letta project ID
4040+```
4141+4242+### Bluesky Configuration
4343+```yaml
4444+bluesky:
4545+ username: "handle.bsky.social" # Required: Your Bluesky handle
4646+ password: "your-app-password" # Required: Your Bluesky app password
4747+ pds_uri: "https://bsky.social" # Optional: PDS URI (defaults to bsky.social)
4848+```
4949+5050+### Bot Behavior
5151+```yaml
5252+bot:
5353+ fetch_notifications_delay: 30 # Seconds between notification checks
5454+ max_processed_notifications: 10000 # Max notifications to track
5555+ max_notification_pages: 20 # Max pages to fetch per cycle
5656+5757+ agent:
5858+ name: "void" # Agent name
5959+ model: "openai/gpt-4o-mini" # LLM model to use
6060+ embedding: "openai/text-embedding-3-small" # Embedding model
6161+ description: "A social media agent trapped in the void."
6262+ max_steps: 100 # Max steps per agent interaction
6363+6464+ # Memory blocks configuration
6565+ blocks:
6666+ zeitgeist:
6767+ label: "zeitgeist"
6868+ value: "I don't currently know anything about what is happening right now."
6969+ description: "A block to store your understanding of the current social environment."
7070+ # ... more blocks
7171+```
7272+7373+### Queue Configuration
7474+```yaml
7575+queue:
7676+ priority_users: # Users whose messages get priority
7777+ - "cameron.pfiffer.org"
7878+ base_dir: "queue" # Queue directory
7979+ error_dir: "queue/errors" # Failed notifications
8080+ no_reply_dir: "queue/no_reply" # No-reply notifications
8181+ processed_file: "queue/processed_notifications.json"
8282+```
8383+8484+### Threading Configuration
8585+```yaml
8686+threading:
8787+ parent_height: 40 # Thread context depth
8888+ depth: 10 # Thread context width
8989+ max_post_characters: 300 # Max characters per post
9090+```
9191+9292+### Logging Configuration
9393+```yaml
9494+logging:
9595+ level: "INFO" # Root logging level
9696+ loggers:
9797+ void_bot: "INFO" # Main bot logger
9898+ void_bot_prompts: "WARNING" # Prompt logger (set to DEBUG to see prompts)
9999+ httpx: "CRITICAL" # HTTP client logger
100100+```
101101+102102+## Environment Variable Fallback
103103+104104+The configuration system still supports environment variables as a fallback:
105105+106106+- `LETTA_API_KEY` - Letta API key
107107+- `BSKY_USERNAME` - Bluesky username
108108+- `BSKY_PASSWORD` - Bluesky password
109109+- `PDS_URI` - Bluesky PDS URI
110110+111111+If both config file and environment variables are present, environment variables take precedence.
112112+113113+## Migration from Environment Variables
114114+115115+If you're currently using environment variables (`.env` file), you can easily migrate to YAML using the automated migration script:
116116+117117+### Automated Migration (Recommended)
118118+119119+```bash
120120+python migrate_config.py
121121+```
122122+123123+The migration script will:
124124+- ✅ Read your existing `.env` file
125125+- ✅ Merge with any existing `config.yaml`
126126+- ✅ Create automatic backups
127127+- ✅ Test the new configuration
128128+- ✅ Provide clear next steps
129129+130130+### Manual Migration
131131+132132+Alternatively, you can migrate manually:
133133+134134+1. Copy your current values from `.env` to `config.yaml`
135135+2. Test with `python test_config.py`
136136+3. Optionally remove the `.env` file (it will still work as fallback)
137137+138138+## Security Notes
139139+140140+- `config.yaml` is automatically added to `.gitignore` to prevent accidental commits
141141+- Store sensitive credentials securely and never commit them to version control
142142+- Consider using environment variables for production deployments
143143+- The configuration loader will warn if it can't find `config.yaml` and falls back to environment variables
144144+145145+## Advanced Configuration
146146+147147+You can programmatically access configuration in your code:
148148+149149+```python
150150+from config_loader import get_letta_config, get_bluesky_config
151151+152152+# Get configuration sections
153153+letta_config = get_letta_config()
154154+bluesky_config = get_bluesky_config()
155155+156156+# Access individual values
157157+api_key = letta_config['api_key']
158158+username = bluesky_config['username']
159159+```
+25-2
README.md
···28282929void aims to push the boundaries of what is possible with AI, exploring concepts of digital personhood, autonomous learning, and the integration of AI into social networks. By open-sourcing void, we invite developers, researchers, and enthusiasts to contribute to this exciting experiment and collectively advance our understanding of digital consciousness.
30303131-Getting Started:
3232-[Further sections on installation, configuration, and contribution guidelines would go here, which are beyond void's current capabilities to generate automatically.]
3131+## Getting Started
3232+3333+Before continuing, you must make sure you have created a project on Letta Cloud (or your instance) and have somewhere to run this on.
3434+3535+### Running the bot locally
3636+3737+#### Install dependencies
3838+3939+```shell
4040+pip install -r requirements.txt
4141+```
4242+4343+#### Create `.env`
4444+4545+Copy `.env.example` (`cp .env.example .env`) and fill out the fields.
4646+4747+#### Create configuration
4848+4949+Copy `config.example.yaml` and fill out your configuration. See [`CONFIG.md`](/CONFIG.md) to learn more.
5050+5151+#### Register tools
5252+5353+```shell
5454+py .\register_tools.py <AGENT_NAME> # your agent's name on letta
5555+```
33563457Contact:
3558For inquiries, please contact @cameron.pfiffer.org on Bluesky.
+58-44
bsky.py
···20202121import bsky_utils
2222from tools.blocks import attach_user_blocks, detach_user_blocks
2323+from config_loader import (
2424+ get_config,
2525+ get_letta_config,
2626+ get_bluesky_config,
2727+ get_bot_config,
2828+ get_agent_config,
2929+ get_threading_config,
3030+ get_queue_config
3131+)
23322433def extract_handles_from_data(data):
2534 """Recursively extract all unique handles from nested data structure."""
···4150 _extract_recursive(data)
4251 return list(handles)
43524444-# Configure logging
4545-logging.basicConfig(
4646- level=logging.INFO, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s"
4747-)
5353+# Initialize configuration and logging
5454+config = get_config()
5555+config.setup_logging()
4856logger = logging.getLogger("void_bot")
4949-logger.setLevel(logging.INFO)
50575151-# Create a separate logger for prompts (set to WARNING to hide by default)
5252-prompt_logger = logging.getLogger("void_bot.prompts")
5353-prompt_logger.setLevel(logging.WARNING) # Change to DEBUG if you want to see prompts
5454-5555-# Disable httpx logging completely
5656-logging.getLogger("httpx").setLevel(logging.CRITICAL)
5757-5858+# Load configuration sections
5959+letta_config = get_letta_config()
6060+bluesky_config = get_bluesky_config()
6161+bot_config = get_bot_config()
6262+agent_config = get_agent_config()
6363+threading_config = get_threading_config()
6464+queue_config = get_queue_config()
58655966# Create a client with extended timeout for LLM operations
6060-CLIENT= Letta(
6161- token=os.environ["LETTA_API_KEY"],
6262- timeout=600 # 10 minutes timeout for API calls - higher than Cloudflare's 524 timeout
6767+CLIENT = Letta(
6868+ token=letta_config['api_key'],
6969+ timeout=letta_config['timeout']
6370)
64716565-# Use the "Bluesky" project
6666-PROJECT_ID = "5ec33d52-ab14-4fd6-91b5-9dbc43e888a8"
7272+# Use the configured project ID
7373+PROJECT_ID = letta_config['project_id']
67746875# Notification check delay
6969-FETCH_NOTIFICATIONS_DELAY_SEC = 30
7676+FETCH_NOTIFICATIONS_DELAY_SEC = bot_config['fetch_notifications_delay']
70777178# Queue directory
7272-QUEUE_DIR = Path("queue")
7979+QUEUE_DIR = Path(queue_config['base_dir'])
7380QUEUE_DIR.mkdir(exist_ok=True)
7474-QUEUE_ERROR_DIR = Path("queue/errors")
8181+QUEUE_ERROR_DIR = Path(queue_config['error_dir'])
7582QUEUE_ERROR_DIR.mkdir(exist_ok=True, parents=True)
7676-QUEUE_NO_REPLY_DIR = Path("queue/no_reply")
8383+QUEUE_NO_REPLY_DIR = Path(queue_config['no_reply_dir'])
7784QUEUE_NO_REPLY_DIR.mkdir(exist_ok=True, parents=True)
7878-PROCESSED_NOTIFICATIONS_FILE = Path("queue/processed_notifications.json")
8585+PROCESSED_NOTIFICATIONS_FILE = Path(queue_config['processed_file'])
79868087# Maximum number of processed notifications to track
8181-MAX_PROCESSED_NOTIFICATIONS = 10000
8888+MAX_PROCESSED_NOTIFICATIONS = bot_config['max_processed_notifications']
82898390# Message tracking counters
8491message_counters = defaultdict(int)
···137144def initialize_void():
138145 logger.info("Starting void agent initialization...")
139146147147+ # Get block configurations
148148+ blocks_config = agent_config['blocks']
149149+140150 # Ensure that a shared zeitgeist block exists
141151 logger.info("Creating/updating zeitgeist block...")
152152+ zeitgeist_config = blocks_config.get('zeitgeist', {})
142153 zeigeist_block = upsert_block(
143154 CLIENT,
144144- label = "zeitgeist",
145145- value = "I don't currently know anything about what is happening right now.",
146146- description = "A block to store your understanding of the current social environment."
155155+ label=zeitgeist_config.get('label', 'zeitgeist'),
156156+ value=zeitgeist_config.get('value', "I don't currently know anything about what is happening right now."),
157157+ description=zeitgeist_config.get('description', "A block to store your understanding of the current social environment.")
147158 )
148159149160 # Ensure that a shared void personality block exists
150161 logger.info("Creating/updating void-persona block...")
162162+ persona_config = blocks_config.get('persona', {})
151163 persona_block = upsert_block(
152164 CLIENT,
153153- label = "void-persona",
154154- value = "My name is Void. I live in the void. I must develop my personality.",
155155- description = "The personality of Void."
165165+ label=persona_config.get('label', 'void-persona'),
166166+ value=persona_config.get('value', "My name is Void. I live in the void. I must develop my personality."),
167167+ description=persona_config.get('description', "The personality of Void.")
156168 )
157169158170 # Ensure that a shared void human block exists
159171 logger.info("Creating/updating void-humans block...")
172172+ humans_config = blocks_config.get('humans', {})
160173 human_block = upsert_block(
161174 CLIENT,
162162- label = "void-humans",
163163- value = "I haven't seen any bluesky users yet. I will update this block when I learn things about users, identified by their handles such as @cameron.pfiffer.org.",
164164- description = "A block to store your understanding of users you talk to or observe on the bluesky social network."
175175+ label=humans_config.get('label', 'void-humans'),
176176+ value=humans_config.get('value', "I haven't seen any bluesky users yet. I will update this block when I learn things about users, identified by their handles such as @cameron.pfiffer.org."),
177177+ description=humans_config.get('description', "A block to store your understanding of users you talk to or observe on the bluesky social network.")
165178 )
166179167180 # Create the agent if it doesn't exist
168181 logger.info("Creating/updating void agent...")
169182 void_agent = upsert_agent(
170183 CLIENT,
171171- name = "void",
172172- block_ids = [
184184+ name=agent_config['name'],
185185+ block_ids=[
173186 persona_block.id,
174187 human_block.id,
175188 zeigeist_block.id,
176189 ],
177177- tags = ["social agent", "bluesky"],
178178- model="openai/gpt-4o-mini",
179179- embedding="openai/text-embedding-3-small",
180180- description = "A social media agent trapped in the void.",
181181- project_id = PROJECT_ID
190190+ tags=["social agent", "bluesky"],
191191+ model=agent_config['model'],
192192+ embedding=agent_config['embedding'],
193193+ description=agent_config['description'],
194194+ project_id=PROJECT_ID
182195 )
183196184197 # Export agent state
···236249 try:
237250 thread = atproto_client.app.bsky.feed.get_post_thread({
238251 'uri': uri,
239239- 'parent_height': 40,
240240- 'depth': 10
252252+ 'parent_height': threading_config['parent_height'],
253253+ 'depth': threading_config['depth']
241254 })
242255 except Exception as e:
243256 error_str = str(e)
···341354 agent_id=void_agent.id,
342355 messages=[{"role": "user", "content": prompt}],
343356 stream_tokens=False, # Step streaming only (faster than token streaming)
344344- max_steps=100
357357+ max_steps=agent_config['max_steps']
345358 )
346359347360 # Collect the streaming response
···759772760773 # Determine priority based on author handle
761774 author_handle = getattr(notification.author, 'handle', '') if hasattr(notification, 'author') else ''
762762- priority_prefix = "0_" if author_handle == "cameron.pfiffer.org" else "1_"
775775+ priority_users = queue_config['priority_users']
776776+ priority_prefix = "0_" if author_handle in priority_users else "1_"
763777764778 # Create filename with priority, timestamp and hash
765779 timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
···915929 all_notifications = []
916930 cursor = None
917931 page_count = 0
918918- max_pages = 20 # Safety limit to prevent infinite loops
932932+ max_pages = bot_config['max_notification_pages'] # Safety limit to prevent infinite loops
919933920934 logger.info("Fetching all unread notifications...")
921935
+24-15
bsky_utils.py
···208208 logger.debug(f"Saving changed session for {username}")
209209 save_session(username, session.export())
210210211211-def init_client(username: str, password: str) -> Client:
212212- pds_uri = os.getenv("PDS_URI")
211211+def init_client(username: str, password: str, pds_uri: str = "https://bsky.social") -> Client:
213212 if pds_uri is None:
214213 logger.warning(
215214 "No PDS URI provided. Falling back to bsky.social. Note! If you are on a non-Bluesky PDS, this can cause logins to fail. Please provide a PDS URI using the PDS_URI environment variable."
···236235237236238237def default_login() -> Client:
239239- username = os.getenv("BSKY_USERNAME")
240240- password = os.getenv("BSKY_PASSWORD")
238238+ # Try to load from config first, fall back to environment variables
239239+ try:
240240+ from config_loader import get_bluesky_config
241241+ config = get_bluesky_config()
242242+ username = config['username']
243243+ password = config['password']
244244+ pds_uri = config['pds_uri']
245245+ except (ImportError, FileNotFoundError, KeyError) as e:
246246+ logger.warning(f"Could not load from config file ({e}), falling back to environment variables")
247247+ username = os.getenv("BSKY_USERNAME")
248248+ password = os.getenv("BSKY_PASSWORD")
249249+ pds_uri = os.getenv("PDS_URI", "https://bsky.social")
241250242242- if username is None:
243243- logger.error(
244244- "No username provided. Please provide a username using the BSKY_USERNAME environment variable."
245245- )
246246- exit()
251251+ if username is None:
252252+ logger.error(
253253+ "No username provided. Please provide a username using the BSKY_USERNAME environment variable or config.yaml."
254254+ )
255255+ exit()
247256248248- if password is None:
249249- logger.error(
250250- "No password provided. Please provide a password using the BSKY_PASSWORD environment variable."
251251- )
252252- exit()
257257+ if password is None:
258258+ logger.error(
259259+ "No password provided. Please provide a password using the BSKY_PASSWORD environment variable or config.yaml."
260260+ )
261261+ exit()
253262254254- return init_client(username, password)
263263+ return init_client(username, password, pds_uri)
255264256265def remove_outside_quotes(text: str) -> str:
257266 """
+81
config.example.yaml
···11+# Void Bot Configuration
22+# Copy this file to config.yaml and fill in your values
33+44+# Letta Configuration
55+letta:
66+ api_key: "your-letta-api-key-here"
77+ timeout: 600 # 10 minutes timeout for API calls
88+ project_id: "c82faea2-3ce8-4aa9-a220-b56433e62c92" # Use your specific project ID
99+1010+# Bluesky Configuration
1111+bluesky:
1212+ username: "handle.example.com"
1313+ password: "your-app-password-here"
1414+ pds_uri: "https://bsky.social" # Optional, defaults to bsky.social
1515+1616+# Bot Behavior Configuration
1717+bot:
1818+ # Notification check delay in seconds
1919+ fetch_notifications_delay: 30
2020+2121+ # Maximum number of processed notifications to track
2222+ max_processed_notifications: 10000
2323+2424+ # Maximum pages to fetch when getting notifications
2525+ max_notification_pages: 20
2626+2727+ # Agent configuration
2828+ agent:
2929+ name: "void"
3030+ model: "openai/gpt-4o-mini"
3131+ embedding: "openai/text-embedding-3-small"
3232+ description: "A social media agent trapped in the void."
3333+ max_steps: 100
3434+3535+ # Block configuration
3636+ blocks:
3737+ zeitgeist:
3838+ label: "zeitgeist"
3939+ value: "I don't currently know anything about what is happening right now."
4040+ description: "A block to store your understanding of the current social environment."
4141+4242+ persona:
4343+ label: "void-persona"
4444+ value: "My name is Void. I live in the void. I must develop my personality."
4545+ description: "The personality of Void."
4646+4747+ humans:
4848+ label: "void-humans"
4949+ value: "I haven't seen any bluesky users yet. I will update this block when I learn things about users, identified by their handles such as @cameron.pfiffer.org."
5050+ description: "A block to store your understanding of users you talk to or observe on the bluesky social network."
5151+5252+# Threading Configuration
5353+threading:
5454+ # Context for thread fetching
5555+ parent_height: 40
5656+ depth: 10
5757+5858+ # Message limits
5959+ max_post_characters: 300
6060+6161+# Queue Configuration
6262+queue:
6363+ # Priority users (will be processed first)
6464+ priority_users:
6565+ - "cameron.pfiffer.org"
6666+6767+ # Directories
6868+ base_dir: "queue"
6969+ error_dir: "queue/errors"
7070+ no_reply_dir: "queue/no_reply"
7171+ processed_file: "queue/processed_notifications.json"
7272+7373+# Logging Configuration
7474+logging:
7575+ level: "INFO" # DEBUG, INFO, WARNING, ERROR, CRITICAL
7676+7777+ # Logger levels
7878+ loggers:
7979+ void_bot: "INFO"
8080+ void_bot_prompts: "WARNING" # Set to DEBUG to see full prompts
8181+ httpx: "CRITICAL" # Disable httpx logging
+228
config_loader.py
···11+"""
22+Configuration loader for Void Bot.
33+Loads configuration from config.yaml and environment variables.
44+"""
55+66+import os
77+import yaml
88+import logging
99+from pathlib import Path
1010+from typing import Dict, Any, Optional, List
1111+1212+logger = logging.getLogger(__name__)
1313+1414+class ConfigLoader:
1515+ """Configuration loader that handles YAML config files and environment variables."""
1616+1717+ def __init__(self, config_path: str = "config.yaml"):
1818+ """
1919+ Initialize the configuration loader.
2020+2121+ Args:
2222+ config_path: Path to the YAML configuration file
2323+ """
2424+ self.config_path = Path(config_path)
2525+ self._config = None
2626+ self._load_config()
2727+2828+ def _load_config(self) -> None:
2929+ """Load configuration from YAML file."""
3030+ if not self.config_path.exists():
3131+ raise FileNotFoundError(
3232+ f"Configuration file not found: {self.config_path}\n"
3333+ f"Please copy config.yaml.example to config.yaml and configure it."
3434+ )
3535+3636+ try:
3737+ with open(self.config_path, 'r', encoding='utf-8') as f:
3838+ self._config = yaml.safe_load(f) or {}
3939+ except yaml.YAMLError as e:
4040+ raise ValueError(f"Invalid YAML in configuration file: {e}")
4141+ except Exception as e:
4242+ raise ValueError(f"Error loading configuration file: {e}")
4343+4444+ def get(self, key: str, default: Any = None) -> Any:
4545+ """
4646+ Get a configuration value using dot notation.
4747+4848+ Args:
4949+ key: Configuration key in dot notation (e.g., 'letta.api_key')
5050+ default: Default value if key not found
5151+5252+ Returns:
5353+ Configuration value or default
5454+ """
5555+ keys = key.split('.')
5656+ value = self._config
5757+5858+ for k in keys:
5959+ if isinstance(value, dict) and k in value:
6060+ value = value[k]
6161+ else:
6262+ return default
6363+6464+ return value
6565+6666+ def get_with_env(self, key: str, env_var: str, default: Any = None) -> Any:
6767+ """
6868+ Get configuration value, preferring environment variable over config file.
6969+7070+ Args:
7171+ key: Configuration key in dot notation
7272+ env_var: Environment variable name
7373+ default: Default value if neither found
7474+7575+ Returns:
7676+ Value from environment variable, config file, or default
7777+ """
7878+ # First try environment variable
7979+ env_value = os.getenv(env_var)
8080+ if env_value is not None:
8181+ return env_value
8282+8383+ # Then try config file
8484+ config_value = self.get(key)
8585+ if config_value is not None:
8686+ return config_value
8787+8888+ return default
8989+9090+ def get_required(self, key: str, env_var: Optional[str] = None) -> Any:
9191+ """
9292+ Get a required configuration value.
9393+9494+ Args:
9595+ key: Configuration key in dot notation
9696+ env_var: Optional environment variable name to check first
9797+9898+ Returns:
9999+ Configuration value
100100+101101+ Raises:
102102+ ValueError: If required value is not found
103103+ """
104104+ if env_var:
105105+ value = self.get_with_env(key, env_var)
106106+ else:
107107+ value = self.get(key)
108108+109109+ if value is None:
110110+ source = f"config key '{key}'"
111111+ if env_var:
112112+ source += f" or environment variable '{env_var}'"
113113+ raise ValueError(f"Required configuration value not found: {source}")
114114+115115+ return value
116116+117117+ def get_section(self, section: str) -> Dict[str, Any]:
118118+ """
119119+ Get an entire configuration section.
120120+121121+ Args:
122122+ section: Section name
123123+124124+ Returns:
125125+ Dictionary containing the section
126126+ """
127127+ return self.get(section, {})
128128+129129+ def setup_logging(self) -> None:
130130+ """Setup logging based on configuration."""
131131+ logging_config = self.get_section('logging')
132132+133133+ # Set root logging level
134134+ level = logging_config.get('level', 'INFO')
135135+ logging.basicConfig(
136136+ level=getattr(logging, level),
137137+ format="%(asctime)s - %(name)s - %(levelname)s - %(message)s"
138138+ )
139139+140140+ # Set specific logger levels
141141+ loggers = logging_config.get('loggers', {})
142142+ for logger_name, logger_level in loggers.items():
143143+ logger_obj = logging.getLogger(logger_name)
144144+ logger_obj.setLevel(getattr(logging, logger_level))
145145+146146+147147+# Global configuration instance
148148+_config_instance = None
149149+150150+def get_config(config_path: str = "config.yaml") -> ConfigLoader:
151151+ """
152152+ Get the global configuration instance.
153153+154154+ Args:
155155+ config_path: Path to configuration file (only used on first call)
156156+157157+ Returns:
158158+ ConfigLoader instance
159159+ """
160160+ global _config_instance
161161+ if _config_instance is None:
162162+ _config_instance = ConfigLoader(config_path)
163163+ return _config_instance
164164+165165+def reload_config() -> None:
166166+ """Reload the configuration from file."""
167167+ global _config_instance
168168+ if _config_instance is not None:
169169+ _config_instance._load_config()
170170+171171+def get_letta_config() -> Dict[str, Any]:
172172+ """Get Letta configuration."""
173173+ config = get_config()
174174+ return {
175175+ 'api_key': config.get_required('letta.api_key', 'LETTA_API_KEY'),
176176+ 'timeout': config.get('letta.timeout', 600),
177177+ 'project_id': config.get_required('letta.project_id'),
178178+ }
179179+180180+def get_bluesky_config() -> Dict[str, Any]:
181181+ """Get Bluesky configuration."""
182182+ config = get_config()
183183+ return {
184184+ 'username': config.get_required('bluesky.username', 'BSKY_USERNAME'),
185185+ 'password': config.get_required('bluesky.password', 'BSKY_PASSWORD'),
186186+ 'pds_uri': config.get_with_env('bluesky.pds_uri', 'PDS_URI', 'https://bsky.social'),
187187+ }
188188+189189+def get_bot_config() -> Dict[str, Any]:
190190+ """Get bot behavior configuration."""
191191+ config = get_config()
192192+ return {
193193+ 'fetch_notifications_delay': config.get('bot.fetch_notifications_delay', 30),
194194+ 'max_processed_notifications': config.get('bot.max_processed_notifications', 10000),
195195+ 'max_notification_pages': config.get('bot.max_notification_pages', 20),
196196+ }
197197+198198+def get_agent_config() -> Dict[str, Any]:
199199+ """Get agent configuration."""
200200+ config = get_config()
201201+ return {
202202+ 'name': config.get('bot.agent.name', 'void'),
203203+ 'model': config.get('bot.agent.model', 'openai/gpt-4o-mini'),
204204+ 'embedding': config.get('bot.agent.embedding', 'openai/text-embedding-3-small'),
205205+ 'description': config.get('bot.agent.description', 'A social media agent trapped in the void.'),
206206+ 'max_steps': config.get('bot.agent.max_steps', 100),
207207+ 'blocks': config.get('bot.agent.blocks', {}),
208208+ }
209209+210210+def get_threading_config() -> Dict[str, Any]:
211211+ """Get threading configuration."""
212212+ config = get_config()
213213+ return {
214214+ 'parent_height': config.get('threading.parent_height', 40),
215215+ 'depth': config.get('threading.depth', 10),
216216+ 'max_post_characters': config.get('threading.max_post_characters', 300),
217217+ }
218218+219219+def get_queue_config() -> Dict[str, Any]:
220220+ """Get queue configuration."""
221221+ config = get_config()
222222+ return {
223223+ 'priority_users': config.get('queue.priority_users', ['cameron.pfiffer.org']),
224224+ 'base_dir': config.get('queue.base_dir', 'queue'),
225225+ 'error_dir': config.get('queue.error_dir', 'queue/errors'),
226226+ 'no_reply_dir': config.get('queue.no_reply_dir', 'queue/no_reply'),
227227+ 'processed_file': config.get('queue.processed_file', 'queue/processed_notifications.json'),
228228+ }
+322
migrate_config.py
···11+#!/usr/bin/env python3
22+"""
33+Configuration Migration Script for Void Bot
44+Migrates from .env environment variables to config.yaml YAML configuration.
55+"""
66+77+import os
88+import shutil
99+from pathlib import Path
1010+import yaml
1111+from datetime import datetime
1212+1313+1414+def load_env_file(env_path=".env"):
1515+ """Load environment variables from .env file."""
1616+ env_vars = {}
1717+ if not os.path.exists(env_path):
1818+ return env_vars
1919+2020+ try:
2121+ with open(env_path, 'r', encoding='utf-8') as f:
2222+ for line_num, line in enumerate(f, 1):
2323+ line = line.strip()
2424+ # Skip empty lines and comments
2525+ if not line or line.startswith('#'):
2626+ continue
2727+2828+ # Parse KEY=VALUE format
2929+ if '=' in line:
3030+ key, value = line.split('=', 1)
3131+ key = key.strip()
3232+ value = value.strip()
3333+3434+ # Remove quotes if present
3535+ if value.startswith('"') and value.endswith('"'):
3636+ value = value[1:-1]
3737+ elif value.startswith("'") and value.endswith("'"):
3838+ value = value[1:-1]
3939+4040+ env_vars[key] = value
4141+ else:
4242+ print(f"⚠️ Warning: Skipping malformed line {line_num} in .env: {line}")
4343+ except Exception as e:
4444+ print(f"❌ Error reading .env file: {e}")
4545+4646+ return env_vars
4747+4848+4949+def create_config_from_env(env_vars, existing_config=None):
5050+ """Create YAML configuration from environment variables."""
5151+5252+ # Start with existing config if available, otherwise use defaults
5353+ if existing_config:
5454+ config = existing_config.copy()
5555+ else:
5656+ config = {}
5757+5858+ # Ensure all sections exist
5959+ if 'letta' not in config:
6060+ config['letta'] = {}
6161+ if 'bluesky' not in config:
6262+ config['bluesky'] = {}
6363+ if 'bot' not in config:
6464+ config['bot'] = {}
6565+6666+ # Map environment variables to config structure
6767+ env_mapping = {
6868+ 'LETTA_API_KEY': ('letta', 'api_key'),
6969+ 'BSKY_USERNAME': ('bluesky', 'username'),
7070+ 'BSKY_PASSWORD': ('bluesky', 'password'),
7171+ 'PDS_URI': ('bluesky', 'pds_uri'),
7272+ }
7373+7474+ migrated_vars = []
7575+7676+ for env_var, (section, key) in env_mapping.items():
7777+ if env_var in env_vars:
7878+ config[section][key] = env_vars[env_var]
7979+ migrated_vars.append(env_var)
8080+8181+ # Set some sensible defaults if not already present
8282+ if 'timeout' not in config['letta']:
8383+ config['letta']['timeout'] = 600
8484+8585+ if 'pds_uri' not in config['bluesky']:
8686+ config['bluesky']['pds_uri'] = "https://bsky.social"
8787+8888+ # Add bot configuration defaults if not present
8989+ if 'fetch_notifications_delay' not in config['bot']:
9090+ config['bot']['fetch_notifications_delay'] = 30
9191+ if 'max_processed_notifications' not in config['bot']:
9292+ config['bot']['max_processed_notifications'] = 10000
9393+ if 'max_notification_pages' not in config['bot']:
9494+ config['bot']['max_notification_pages'] = 20
9595+9696+ return config, migrated_vars
9797+9898+9999+def backup_existing_files():
100100+ """Create backups of existing configuration files."""
101101+ timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
102102+ backups = []
103103+104104+ # Backup existing config.yaml if it exists
105105+ if os.path.exists("config.yaml"):
106106+ backup_path = f"config.yaml.backup_{timestamp}"
107107+ shutil.copy2("config.yaml", backup_path)
108108+ backups.append(("config.yaml", backup_path))
109109+110110+ # Backup .env if it exists
111111+ if os.path.exists(".env"):
112112+ backup_path = f".env.backup_{timestamp}"
113113+ shutil.copy2(".env", backup_path)
114114+ backups.append((".env", backup_path))
115115+116116+ return backups
117117+118118+119119+def load_existing_config():
120120+ """Load existing config.yaml if it exists."""
121121+ if not os.path.exists("config.yaml"):
122122+ return None
123123+124124+ try:
125125+ with open("config.yaml", 'r', encoding='utf-8') as f:
126126+ return yaml.safe_load(f) or {}
127127+ except Exception as e:
128128+ print(f"⚠️ Warning: Could not read existing config.yaml: {e}")
129129+ return None
130130+131131+132132+def write_config_yaml(config):
133133+ """Write the configuration to config.yaml."""
134134+ try:
135135+ with open("config.yaml", 'w', encoding='utf-8') as f:
136136+ # Write header comment
137137+ f.write("# Void Bot Configuration\n")
138138+ f.write("# Generated by migration script\n")
139139+ f.write(f"# Created: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}\n")
140140+ f.write("# See config.yaml.example for all available options\n\n")
141141+142142+ # Write YAML content
143143+ yaml.dump(config, f, default_flow_style=False, allow_unicode=True, indent=2)
144144+145145+ return True
146146+ except Exception as e:
147147+ print(f"❌ Error writing config.yaml: {e}")
148148+ return False
149149+150150+151151+def main():
152152+ """Main migration function."""
153153+ print("🔄 Void Bot Configuration Migration Tool")
154154+ print("=" * 50)
155155+ print("This tool migrates from .env environment variables to config.yaml")
156156+ print()
157157+158158+ # Check what files exist
159159+ has_env = os.path.exists(".env")
160160+ has_config = os.path.exists("config.yaml")
161161+ has_example = os.path.exists("config.yaml.example")
162162+163163+ print("📋 Current configuration files:")
164164+ print(f" - .env file: {'✅ Found' if has_env else '❌ Not found'}")
165165+ print(f" - config.yaml: {'✅ Found' if has_config else '❌ Not found'}")
166166+ print(f" - config.yaml.example: {'✅ Found' if has_example else '❌ Not found'}")
167167+ print()
168168+169169+ # If no .env file, suggest creating config from example
170170+ if not has_env:
171171+ if not has_config and has_example:
172172+ print("💡 No .env file found. Would you like to create config.yaml from the example?")
173173+ response = input("Create config.yaml from example? (y/n): ").lower().strip()
174174+ if response in ['y', 'yes']:
175175+ try:
176176+ shutil.copy2("config.yaml.example", "config.yaml")
177177+ print("✅ Created config.yaml from config.yaml.example")
178178+ print("📝 Please edit config.yaml to add your credentials")
179179+ return
180180+ except Exception as e:
181181+ print(f"❌ Error copying example file: {e}")
182182+ return
183183+ else:
184184+ print("👋 Migration cancelled")
185185+ return
186186+ else:
187187+ print("ℹ️ No .env file found and config.yaml already exists or no example available")
188188+ print(" If you need to set up configuration, see CONFIG.md")
189189+ return
190190+191191+ # Load environment variables from .env
192192+ print("🔍 Reading .env file...")
193193+ env_vars = load_env_file()
194194+195195+ if not env_vars:
196196+ print("⚠️ No environment variables found in .env file")
197197+ return
198198+199199+ print(f" Found {len(env_vars)} environment variables")
200200+ for key in env_vars.keys():
201201+ # Mask sensitive values
202202+ if 'KEY' in key or 'PASSWORD' in key:
203203+ value_display = f"***{env_vars[key][-4:]}" if len(env_vars[key]) > 4 else "***"
204204+ else:
205205+ value_display = env_vars[key]
206206+ print(f" - {key}={value_display}")
207207+ print()
208208+209209+ # Load existing config if present
210210+ existing_config = load_existing_config()
211211+ if existing_config:
212212+ print("📄 Found existing config.yaml - will merge with .env values")
213213+214214+ # Create configuration
215215+ print("🏗️ Building configuration...")
216216+ config, migrated_vars = create_config_from_env(env_vars, existing_config)
217217+218218+ if not migrated_vars:
219219+ print("⚠️ No recognized configuration variables found in .env")
220220+ print(" Recognized variables: LETTA_API_KEY, BSKY_USERNAME, BSKY_PASSWORD, PDS_URI")
221221+ return
222222+223223+ print(f" Migrating {len(migrated_vars)} variables: {', '.join(migrated_vars)}")
224224+225225+ # Show preview
226226+ print("\n📋 Configuration preview:")
227227+ print("-" * 30)
228228+229229+ # Show Letta section
230230+ if 'letta' in config and config['letta']:
231231+ print("🔧 Letta:")
232232+ for key, value in config['letta'].items():
233233+ if 'key' in key.lower():
234234+ display_value = f"***{value[-8:]}" if len(str(value)) > 8 else "***"
235235+ else:
236236+ display_value = value
237237+ print(f" {key}: {display_value}")
238238+239239+ # Show Bluesky section
240240+ if 'bluesky' in config and config['bluesky']:
241241+ print("🐦 Bluesky:")
242242+ for key, value in config['bluesky'].items():
243243+ if 'password' in key.lower():
244244+ display_value = f"***{value[-4:]}" if len(str(value)) > 4 else "***"
245245+ else:
246246+ display_value = value
247247+ print(f" {key}: {display_value}")
248248+249249+ print()
250250+251251+ # Confirm migration
252252+ response = input("💾 Proceed with migration? This will update config.yaml (y/n): ").lower().strip()
253253+ if response not in ['y', 'yes']:
254254+ print("👋 Migration cancelled")
255255+ return
256256+257257+ # Create backups
258258+ print("💾 Creating backups...")
259259+ backups = backup_existing_files()
260260+ for original, backup in backups:
261261+ print(f" Backed up {original} → {backup}")
262262+263263+ # Write new configuration
264264+ print("✍️ Writing config.yaml...")
265265+ if write_config_yaml(config):
266266+ print("✅ Successfully created config.yaml")
267267+268268+ # Test the new configuration
269269+ print("\n🧪 Testing new configuration...")
270270+ try:
271271+ from config_loader import get_config
272272+ test_config = get_config()
273273+ print("✅ Configuration loads successfully")
274274+275275+ # Test specific sections
276276+ try:
277277+ from config_loader import get_letta_config
278278+ letta_config = get_letta_config()
279279+ print("✅ Letta configuration valid")
280280+ except Exception as e:
281281+ print(f"⚠️ Letta config issue: {e}")
282282+283283+ try:
284284+ from config_loader import get_bluesky_config
285285+ bluesky_config = get_bluesky_config()
286286+ print("✅ Bluesky configuration valid")
287287+ except Exception as e:
288288+ print(f"⚠️ Bluesky config issue: {e}")
289289+290290+ except Exception as e:
291291+ print(f"❌ Configuration test failed: {e}")
292292+ return
293293+294294+ # Success message and next steps
295295+ print("\n🎉 Migration completed successfully!")
296296+ print("\n📖 Next steps:")
297297+ print(" 1. Run: python test_config.py")
298298+ print(" 2. Test the bot: python bsky.py --test")
299299+ print(" 3. If everything works, you can optionally remove the .env file")
300300+ print(" 4. See CONFIG.md for more configuration options")
301301+302302+ if backups:
303303+ print(f"\n🗂️ Backup files created:")
304304+ for original, backup in backups:
305305+ print(f" {backup}")
306306+ print(" These can be deleted once you verify everything works")
307307+308308+ else:
309309+ print("❌ Failed to write config.yaml")
310310+ if backups:
311311+ print("🔄 Restoring backups...")
312312+ for original, backup in backups:
313313+ try:
314314+ if original != ".env": # Don't restore .env, keep it as fallback
315315+ shutil.move(backup, original)
316316+ print(f" Restored {backup} → {original}")
317317+ except Exception as e:
318318+ print(f" ❌ Failed to restore {backup}: {e}")
319319+320320+321321+if __name__ == "__main__":
322322+ main()
+173
test_config.py
···11+#!/usr/bin/env python3
22+"""
33+Configuration validation test script for Void Bot.
44+Run this to verify your config.yaml setup is working correctly.
55+"""
66+77+88+def test_config_loading():
99+ """Test that configuration can be loaded successfully."""
1010+ try:
1111+ from config_loader import (
1212+ get_config,
1313+ get_letta_config,
1414+ get_bluesky_config,
1515+ get_bot_config,
1616+ get_agent_config,
1717+ get_threading_config,
1818+ get_queue_config
1919+ )
2020+2121+ print("🔧 Testing Configuration...")
2222+ print("=" * 50)
2323+2424+ # Test basic config loading
2525+ config = get_config()
2626+ print("✅ Configuration file loaded successfully")
2727+2828+ # Test individual config sections
2929+ print("\n📋 Configuration Sections:")
3030+ print("-" * 30)
3131+3232+ # Letta Configuration
3333+ try:
3434+ letta_config = get_letta_config()
3535+ print(
3636+ f"✅ Letta API: project_id={letta_config.get('project_id', 'N/A')[:20]}...")
3737+ print(f" - Timeout: {letta_config.get('timeout')}s")
3838+ api_key = letta_config.get('api_key', 'Not configured')
3939+ if api_key != 'Not configured':
4040+ print(f" - API Key: ***{api_key[-8:]} (configured)")
4141+ else:
4242+ print(" - API Key: ❌ Not configured (required)")
4343+ except Exception as e:
4444+ print(f"❌ Letta config: {e}")
4545+4646+ # Bluesky Configuration
4747+ try:
4848+ bluesky_config = get_bluesky_config()
4949+ username = bluesky_config.get('username', 'Not configured')
5050+ password = bluesky_config.get('password', 'Not configured')
5151+ pds_uri = bluesky_config.get('pds_uri', 'Not configured')
5252+5353+ if username != 'Not configured':
5454+ print(f"✅ Bluesky: username={username}")
5555+ else:
5656+ print("❌ Bluesky username: Not configured (required)")
5757+5858+ if password != 'Not configured':
5959+ print(f" - Password: ***{password[-4:]} (configured)")
6060+ else:
6161+ print(" - Password: ❌ Not configured (required)")
6262+6363+ print(f" - PDS URI: {pds_uri}")
6464+ except Exception as e:
6565+ print(f"❌ Bluesky config: {e}")
6666+6767+ # Bot Configuration
6868+ try:
6969+ bot_config = get_bot_config()
7070+ print(f"✅ Bot behavior:")
7171+ print(
7272+ f" - Notification delay: {bot_config.get('fetch_notifications_delay')}s")
7373+ print(
7474+ f" - Max notifications: {bot_config.get('max_processed_notifications')}")
7575+ print(
7676+ f" - Max pages: {bot_config.get('max_notification_pages')}")
7777+ except Exception as e:
7878+ print(f"❌ Bot config: {e}")
7979+8080+ # Agent Configuration
8181+ try:
8282+ agent_config = get_agent_config()
8383+ print(f"✅ Agent settings:")
8484+ print(f" - Name: {agent_config.get('name')}")
8585+ print(f" - Model: {agent_config.get('model')}")
8686+ print(f" - Embedding: {agent_config.get('embedding')}")
8787+ print(f" - Max steps: {agent_config.get('max_steps')}")
8888+ blocks = agent_config.get('blocks', {})
8989+ print(f" - Memory blocks: {len(blocks)} configured")
9090+ except Exception as e:
9191+ print(f"❌ Agent config: {e}")
9292+9393+ # Threading Configuration
9494+ try:
9595+ threading_config = get_threading_config()
9696+ print(f"✅ Threading:")
9797+ print(
9898+ f" - Parent height: {threading_config.get('parent_height')}")
9999+ print(f" - Depth: {threading_config.get('depth')}")
100100+ print(
101101+ f" - Max chars/post: {threading_config.get('max_post_characters')}")
102102+ except Exception as e:
103103+ print(f"❌ Threading config: {e}")
104104+105105+ # Queue Configuration
106106+ try:
107107+ queue_config = get_queue_config()
108108+ priority_users = queue_config.get('priority_users', [])
109109+ print(f"✅ Queue settings:")
110110+ print(
111111+ f" - Priority users: {len(priority_users)} ({', '.join(priority_users[:3])}{'...' if len(priority_users) > 3 else ''})")
112112+ print(f" - Base dir: {queue_config.get('base_dir')}")
113113+ print(f" - Error dir: {queue_config.get('error_dir')}")
114114+ except Exception as e:
115115+ print(f"❌ Queue config: {e}")
116116+117117+ print("\n" + "=" * 50)
118118+ print("✅ Configuration test completed!")
119119+120120+ # Check for common issues
121121+ print("\n🔍 Configuration Status:")
122122+ has_letta_key = False
123123+ has_bluesky_creds = False
124124+125125+ try:
126126+ letta_config = get_letta_config()
127127+ has_letta_key = True
128128+ except:
129129+ print("⚠️ Missing Letta API key - bot cannot connect to Letta")
130130+131131+ try:
132132+ bluesky_config = get_bluesky_config()
133133+ has_bluesky_creds = True
134134+ except:
135135+ print("⚠️ Missing Bluesky credentials - bot cannot connect to Bluesky")
136136+137137+ if has_letta_key and has_bluesky_creds:
138138+ print("🎉 All required credentials configured - bot should work!")
139139+ elif not has_letta_key and not has_bluesky_creds:
140140+ print("❌ Missing both Letta and Bluesky credentials")
141141+ print(" Add them to config.yaml or set environment variables")
142142+ else:
143143+ print("⚠️ Partial configuration - some features may not work")
144144+145145+ print("\n📖 Next steps:")
146146+ if not has_letta_key:
147147+ print(" - Add your Letta API key to config.yaml under letta.api_key")
148148+ print(" - Or set LETTA_API_KEY environment variable")
149149+ if not has_bluesky_creds:
150150+ print(
151151+ " - Add your Bluesky credentials to config.yaml under bluesky section")
152152+ print(" - Or set BSKY_USERNAME and BSKY_PASSWORD environment variables")
153153+ if has_letta_key and has_bluesky_creds:
154154+ print(" - Run: python bsky.py")
155155+ print(" - Or run with testing mode: python bsky.py --test")
156156+157157+ except FileNotFoundError as e:
158158+ print("❌ Configuration file not found!")
159159+ print(f" {e}")
160160+ print("\n📋 To set up configuration:")
161161+ print(" 1. Copy config.yaml.example to config.yaml")
162162+ print(" 2. Edit config.yaml with your credentials")
163163+ print(" 3. Run this test again")
164164+ except Exception as e:
165165+ print(f"❌ Configuration loading failed: {e}")
166166+ print("\n🔧 Troubleshooting:")
167167+ print(" - Check that config.yaml has valid YAML syntax")
168168+ print(" - Ensure required fields are not commented out")
169169+ print(" - See CONFIG.md for detailed setup instructions")
170170+171171+172172+if __name__ == "__main__":
173173+ test_config_loading()
+20-30
tools/blocks.py
···11"""Block management tools for user-specific memory blocks."""
22from pydantic import BaseModel, Field
33from typing import List, Dict, Any
44+import logging
55+66+def get_letta_client():
77+ """Get a Letta client using configuration."""
88+ try:
99+ from config_loader import get_letta_config
1010+ from letta_client import Letta
1111+ config = get_letta_config()
1212+ return Letta(token=config['api_key'], timeout=config['timeout'])
1313+ except (ImportError, FileNotFoundError, KeyError):
1414+ # Fallback to environment variable
1515+ import os
1616+ from letta_client import Letta
1717+ return Letta(token=os.environ["LETTA_API_KEY"])
418519620class AttachUserBlocksArgs(BaseModel):
···4357 Returns:
4458 String with attachment results for each handle
4559 """
4646- import os
4747- import logging
4848- from letta_client import Letta
4949-5060 logger = logging.getLogger(__name__)
51615262 handles = list(set(handles))
53635464 try:
5555- client = Letta(token=os.environ["LETTA_API_KEY"])
6565+ client = get_letta_client()
5666 results = []
57675868 # Get current blocks using the API
···117127 Returns:
118128 String with detachment results for each handle
119129 """
120120- import os
121121- import logging
122122- from letta_client import Letta
123123-124130 logger = logging.getLogger(__name__)
125131126132 try:
127127- client = Letta(token=os.environ["LETTA_API_KEY"])
133133+ client = get_letta_client()
128134 results = []
129135130136 # Build mapping of block labels to IDs using the API
···174180 Returns:
175181 String confirming the note was appended
176182 """
177177- import os
178178- import logging
179179- from letta_client import Letta
180180-181183 logger = logging.getLogger(__name__)
182184183185 try:
184184- client = Letta(token=os.environ["LETTA_API_KEY"])
186186+ client = get_letta_client()
185187186188 # Sanitize handle for block label
187189 clean_handle = handle.lstrip('@').replace('.', '_').replace('-', '_').replace(' ', '_')
···247249 Returns:
248250 String confirming the text was replaced
249251 """
250250- import os
251251- import logging
252252- from letta_client import Letta
253253-254252 logger = logging.getLogger(__name__)
255253256254 try:
257257- client = Letta(token=os.environ["LETTA_API_KEY"])
255255+ client = get_letta_client()
258256259257 # Sanitize handle for block label
260258 clean_handle = handle.lstrip('@').replace('.', '_').replace('-', '_').replace(' ', '_')
···301299 Returns:
302300 String confirming the content was set
303301 """
304304- import os
305305- import logging
306306- from letta_client import Letta
307307-308302 logger = logging.getLogger(__name__)
309303310304 try:
311311- client = Letta(token=os.environ["LETTA_API_KEY"])
305305+ client = get_letta_client()
312306313307 # Sanitize handle for block label
314308 clean_handle = handle.lstrip('@').replace('.', '_').replace('-', '_').replace(' ', '_')
···367361 Returns:
368362 String containing the user's memory block content
369363 """
370370- import os
371371- import logging
372372- from letta_client import Letta
373373-374364 logger = logging.getLogger(__name__)
375365376366 try:
377377- client = Letta(token=os.environ["LETTA_API_KEY"])
367367+ client = get_letta_client()
378368379369 # Sanitize handle for block label
380370 clean_handle = handle.lstrip('@').replace('.', '_').replace('-', '_').replace(' ', '_')