/ docs / lm-studio-insight-agent.md
lm-studio-insight-agent.md
  1  # LM Studio Insight Agent
  2  
  3  The LM Studio Insight Agent is an AI-powered actor that extracts interesting insights from Discord message sequences using a local LM Studio instance with the gemma-3-12b model.
  4  
  5  ## Overview
  6  
  7  This agent:
  8  - Selects random sequences of messages from indexed Discord channels
  9  - Extracts ONE key insight using LM Studio's gemma-3-12b model
 10  - Posts insights to a configured Discord channel
 11  - Runs on a 10-minute polling interval
 12  
 13  ## Prerequisites
 14  
 15  1. **LM Studio**: Download and install [LM Studio](https://lmstudio.ai/)
 16  2. **Model**: Download the `gemma-3-12b` model in LM Studio
 17  3. **Server**: Start the LM Studio server (default port: 1234)
 18  4. **Discord Bot**: Ensure your Discord bot has message posting permissions
 19  
 20  ## Configuration
 21  
 22  Add these environment variables to your `.env` file:
 23  
 24  ```env
 25  # LM Studio Configuration
 26  LM_STUDIO_BASE_URL=http://localhost:1234/v1
 27  LM_STUDIO_MODEL=gemma-3-12b
 28  
 29  # Insight Generation Settings
 30  LM_STUDIO_TEMPERATURE=0.8
 31  LM_STUDIO_TIMEOUT=90000
 32  LM_STUDIO_MESSAGE_SEQUENCE_LENGTH=7
 33  LM_STUDIO_MIN_MESSAGE_LENGTH=20
 34  LM_STUDIO_EXCLUDE_BOT_MESSAGES=true
 35  LM_STUDIO_MAX_MESSAGE_AGE_HOURS=168
 36  
 37  # Discord Posting
 38  LM_STUDIO_ENABLE_DISCORD_POSTING=true
 39  LM_STUDIO_INSIGHT_CHANNEL_ID=your_channel_id_here
 40  ```
 41  
 42  ## Running the Agent
 43  
 44  ### Standalone
 45  ```bash
 46  deno run actors-main.ts --preset lm-studio-insight
 47  ```
 48  
 49  ### With Other Discord Features
 50  ```bash
 51  deno run actors-main.ts --preset discord-all
 52  ```
 53  
 54  ### Custom Configuration
 55  ```bash
 56  deno run actors-main.ts --lm-studio-insight-agent 1
 57  ```
 58  
 59  ## How It Works
 60  
 61  1. **Message Selection**: The agent fetches recent messages from the database and selects a random sequence of 7 messages (configurable) from the same channel.
 62  
 63  2. **Insight Extraction**: Using LM Studio's gemma-3-12b model, it analyzes the message sequence to extract one interesting insight about:
 64     - Conversation patterns
 65     - Emerging themes
 66     - Social dynamics
 67     - Creative ideas
 68     - Community mood
 69  
 70  3. **Discord Posting**: The insight is formatted and posted to the configured Discord channel with proper attribution.
 71  
 72  ## Insights Focus
 73  
 74  The agent is designed to extract insights that are:
 75  - **Specific**: Grounded in the actual conversation
 76  - **Interesting**: Highlighting unexpected patterns or connections
 77  - **Thoughtful**: Going beyond simple summaries
 78  - **Community-focused**: Relevant to the Discord community
 79  
 80  ## Troubleshooting
 81  
 82  ### LM Studio Connection Issues
 83  - Ensure LM Studio server is running
 84  - Check the base URL matches your LM Studio settings
 85  - Verify the model is loaded in LM Studio
 86  
 87  ### No Insights Generated
 88  - Check if there are enough messages in the database
 89  - Verify message length requirements are met
 90  - Ensure the Discord indexer has run recently
 91  
 92  ### Discord Posting Failed
 93  - Verify the bot has permissions in the target channel
 94  - Check the channel ID is correct
 95  - Ensure `LM_STUDIO_ENABLE_DISCORD_POSTING=true`
 96  
 97  ## Example Output
 98  
 99  ```
100  🔮 **Community Insight**
101  
102  The conversation reveals an interesting shift from technical troubleshooting to philosophical discussion about AI consciousness, sparked by a simple typo that made the bot seem more "human." This suggests the community values both technical expertise and deeper reflections on technology's impact.
103  
104  *Generated by LM Studio (gemma-3-12b)*
105  ```
106  
107  ## Performance Considerations
108  
109  - The agent runs every 10 minutes by default
110  - Each insight generation takes 30-90 seconds depending on LM Studio performance
111  - Message sequence selection is optimized for chronological coherence
112  - The agent excludes bot messages by default to focus on human conversations