MouseTron is an intelligent task automation system that combines a LangGraph-based agent, a Logitech Loupedeck plugin, and an Efficient Memory Algorithm (EMA) to learn from user interactions and automate repetitive tasks.
MouseTron consists of three main components:
- Agent - A LangGraph-based agent that breaks down tasks into steps and executes them using MCP (Model Context Protocol) tools
- Logitech Plugin (C#) - A Loupedeck plugin that tracks text selection, sends commands to the server, and displays recommendations
- EMA Algorithm - An Efficient Memory Algorithm that finds patterns in user interactions and generates personalized recommendations
┌─────────────────────────────────────────────────────────────┐
│ Logitech Loupedeck Plugin (C#) │
│ - Tracks selected text from applications │
│ - Sends commands to Python server │
│ - Displays recommendations from EMA │
│ - Manages server lifecycle │
└──────────────────────┬──────────────────────────────────────┘
│ HTTP POST/GET
▼
┌─────────────────────────────────────────────────────────────┐
│ Python Server (server.py) │
│ - Receives commands from plugin │
│ - Orchestrates agent execution │
│ - Updates EMA with tool usage patterns │
│ - Generates recommendations │
└──────────────────────┬──────────────────────────────────────┘
│
┌──────────────┴──────────────┐
│ │
▼ ▼
┌──────────────┐ ┌──────────────────┐
│ Agent │ │ EMA Algorithm │
│ (agent.py) │ │ (EMA.py) │
│ │ │ │
│ - Plans │ │ - Tracks patterns│
│ - Executes │ │ - Generates │
│ - Uses MCPs │ │ recommendations│
└──────────────┘ └──────────────────┘
The agent system (agent/) is a LangGraph-based intelligent agent that:
- Breaks down natural language commands into executable steps
- Executes tasks using Zapier MCP (Model Context Protocol) tools
- Maintains execution context across steps
- Validates plans before execution
agent/agent.py- Main agent implementation with LangGraph workflowagent/main.py- Entry point for testing the agentagent/graph.py- Exposes the graph for LangGraph Studio
-
Tool Discovery (
fetch_tools):- Queries the Zapier MCP server to discover available tools
- Caches tool schemas for planning and execution
- Falls back to local tool definitions if MCP is unavailable
-
Command Summarization (
summarize_command):- Analyzes long or unclear commands
- Extracts actionable tasks from conversations
- Preserves important details (dates, emails, names)
-
Planning Phase (
plan_phase):- Analyzes the command and available tools
- Creates a step-by-step execution plan
- Each step includes:
id: Sequential step numberdescription: Human-readable descriptiontool_name: Exact tool name to executetool_args: Parameters for the toolstatus: Execution status (pending/in_progress/completed/failed)
-
Plan Validation (
validate_plan):- Checks for missing intermediate steps
- Verifies tool names match available tools
- Ensures logical flow between steps
- Can trigger replanning if issues are found
-
Execution Phase (
execute_phase):- Executes each step sequentially
- Updates step status as execution progresses
- Passes results from previous steps as context to subsequent steps
- Stops execution if any step fails
- Tool Name Detection: Automatically detects when commands contain explicit tool names
- Context Summarization: Reduces token usage by summarizing large execution contexts
- Structured Output Extraction: Extracts JSON data from tool responses for use in subsequent steps
- LangSmith Tracing: All operations are automatically traced for observability
Input: "create a meeting for tuesday 13:00 and send the link to example@gmail.com"
Plan:
- Create calendar event for Tuesday 13:00 →
zapier_google_calendar_create_event - Get meeting link from created event →
zapier_google_calendar_get_event - Send email with meeting link →
zapier_gmail_send_email
Execution: Each step executes sequentially, with step 2 using the event ID from step 1, and step 3 using the link from step 2.
The Logitech plugin (MouseTronPlugin/) is a Loupedeck plugin written in C# that:
- Tracks text selection from any application
- Sends selected text and application context to the Python server
- Displays recommendations from the EMA algorithm
- Manages the Python server lifecycle
MouseTronPlugin/src/MouseTronPlugin.cs- Main plugin classMouseTronPlugin/src/Services/ServerManagementService.cs- Manages Python server processMouseTronPlugin/src/Services/StepsPollingService.cs- Polls server for execution statusMouseTronPlugin/src/Actions/SendTextAction.cs- Sends selected text to serverMouseTronPlugin/src/Actions/FirstRecentAction.cs- Displays most recent recommendationMouseTronPlugin/src/Actions/FirstMostUsedAction.cs- Displays most used recommendation
-
Server Management:
- Automatically starts
server.pywhen plugin loads - Finds Python executable (checks virtual environment first, then system Python)
- Finds a free port and starts the server
- Monitors server health and restarts if needed
- Stops server when plugin unloads
- Automatically starts
-
Text Selection Tracking:
SendTextAction: User selects text and triggers the action- Copies selected text using platform-specific methods (AppleScript on macOS, PowerShell on Windows)
- Gets current application name
- Sends POST request to server with:
{ "selectedText": "selected text here", "applicationName": "Chrome", "input": "optional user feedback" }
-
Recommendation Display:
FirstRecentAction: Readsrecommendations/recent_tool_single_1.jsonFirstMostUsedAction: Readsrecommendations/stable_tools_combo_1.json- Updates action display names and descriptions dynamically
- Allows users to execute recommended actions with additional input
-
Status Polling:
StepsPollingService: Polls/api/stepsendpoint every 2 seconds- Displays current execution status in plugin notifications
- Shows step-by-step progress as agent executes
- macOS: Uses AppleScript for text selection and clipboard operations
- Windows: Uses PowerShell for text selection and clipboard operations
- Cross-platform: Server management works on both platforms
The EMA (Efficient Memory Algorithm) (EMA.py) is a pattern recognition system that:
- Tracks tool usage patterns from agent executions
- Identifies frequently used tool combinations
- Generates personalized recommendations based on:
- Recent usage patterns (last k blocks)
- Stable patterns from frequency table
- Recently used single tools
- Blocks: A sequence of tools executed together (e.g., "zapier_gmail_send_email, zapier_google_calendar_create_event")
- Subsequences: Ordered subsets of tools from a block (maintains order but allows skipping)
- Frequency Table: Tracks how often each subsequence appears across all blocks
- Recent Blocks: Last k blocks (default: 10) for short-term pattern recognition
- Estimation Function: Combines frequency and recency to prioritize patterns
- k: Number of recent blocks to track (default: 10)
- t: Maximum size of frequency table (default: 50)
- nr: Number of recommendations from recent blocks (default: 2)
- nf: Number of recommendations from frequency table (default: 5)
- ns: Number of single tool recommendations (default: 5)
-
Block Addition:
- When agent completes execution, tool names are extracted
- Tools are converted to a comma-separated block string
- Block is added to recent blocks (deque with maxlen=k)
- All subsequences are generated and tracked
-
Subsequence Generation:
- For block [A, B, C], generates: [A], [B], [C], [A,B], [A,C], [B,C], [A,B,C]
- Maintains order but allows skipping elements
- Tracks both single tools and combinations
-
Frequency Tracking:
- Updates frequency table for all subsequences across all blocks
- Tracks frequency count and last usage index
- Uses estimation function for eviction when table exceeds size t
-
Recommendation Generation:
-
Recent Recommendations (
pick_from_recent):- Analyzes subsequences from last k blocks
- Sorts by frequency × length (prioritizes longer, frequent patterns)
- Returns top nr recommendations
-
Stable Recommendations (
pick_from_frequency):- Analyzes all subsequences in frequency table
- Sorts by frequency × length
- Returns top nf recommendations
-
Single Tool Recommendations (
get_recent_single_tools):- Tracks recently used individual tools
- Returns ns most recently used tools
-
-
Persistence:
- Saves all containers to JSON files in
containers/directory:name_to_number.json- Tool name to number mappingnumber_to_name.json- Reverse mappingrecent_blocks.json- Recent k blocksfrequency_table.json- Frequency tableall_blocks.json- All blocks ever processedrecent_single_tools.json- Recently used single tools
- Loads containers on initialization for persistence across sessions
- Saves all containers to JSON files in
EMA generates JSON files in recommendations/ directory:
recent_tools_combo_1.jsontorecent_tools_combo_{nr}.json- Recent tool combinationsrecent_tool_single_1.jsontorecent_tool_single_{ns}.json- Recent single toolsstable_tools_combo_1.jsontostable_tools_combo_{nf}.json- Stable tool combinations
Each file contains:
[
{
"tool_name": "zapier_gmail_send_email",
"description": "Send an email message"
}
]- Python 3.8+ with pip
- Node.js and npm (for Electron popup)
- .NET 8.0 SDK (for building the C# plugin)
- Logitech Loupedeck device and Logi Plugin Service installed
- API Keys:
- Anthropic API key (for Claude API)
- Zapier Authorization Token (for MCP tools)
- LangSmith API key (optional, for tracing)
-
Clone or navigate to the project directory:
cd MouseTron -
Create a virtual environment (recommended):
python -m venv venv # On macOS/Linux: source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install Python dependencies:
pip install -r requirements.txt
-
Create
.envfile in the project root:ANTHROPIC_API_KEY=your_anthropic_api_key_here ZAPIER_AUTHORIZATION_TOKEN=your_zapier_authorization_token_here LANGSMITH_TRACING=true LANGSMITH_API_KEY=your_langsmith_api_key_here LANGSMITH_PROJECT=MouseTron
Note: Get your LangSmith API key from https://smith.langchain.com
-
Install .NET 8.0 SDK:
- Download from https://dotnet.microsoft.com/download
-
Build the plugin:
cd MouseTronPlugin dotnet buildThe build process will:
- Compile the plugin DLL
- Copy package files
- Create a plugin link file in the Logi Plugin Service directory
- Attempt to reload the plugin automatically
-
Verify plugin installation:
- Open Logi Plugin Service
- Check that "MouseTron" plugin appears in the list
- Plugin should automatically start the Python server on load
The Electron popup provides a UI for viewing agent execution status.
-
Navigate to electron-popup directory:
cd electron-popup -
Install dependencies:
npm install
-
The popup will be launched automatically by the server when a request is received.
If you have a dataset/recommendation_showcase_patterns.txt file with example patterns:
- The server will automatically load patterns on startup if the file exists
- Patterns should be one per line, comma-separated tool names:
zapier_gmail_send_email, zapier_google_calendar_create_event zapier_slack_send_message zapier_gmail_send_email, zapier_google_drive_create_file
-
Start the server manually (for testing):
python server.py -p 8080
-
Check that the server starts and shows:
Listening on http://localhost:8080 EMA initialized successfully -
Test the agent:
python agent/main.py
-
In Logi Plugin Service:
- Verify MouseTron plugin is loaded
- Check that actions are available:
- "Send Text"
- "Most Recent Action"
- "Most Used Action"
- Select text in any application (browser, email, chat, etc.)
- Press the "Send Text" action on your Loupedeck device
- Optionally provide feedback in the popup dialog (e.g., "meeting duration is 1 hour")
- Agent executes the task step-by-step
- View progress in plugin notifications or Electron popup
-
Most Recent Action: Shows the most recently used tool/pattern
- Press the action button
- Enter additional context if needed
- Agent executes with the recommended tool
-
Most Used Action: Shows the most frequently used stable pattern
- Press the action button
- Enter additional context if needed
- Agent executes with the recommended pattern
You can also interact with the server directly via HTTP:
Send a command:
curl -X POST http://localhost:8080 \
-H "Content-Type: application/json" \
-d '{
"selectedText": "create a meeting for tomorrow at 2pm",
"applicationName": "Chrome",
"input": "meeting duration is 1 hour"
}'Check execution status:
curl http://localhost:8080/api/stepsServer configuration is done via command-line arguments:
python server.py -p 8080 # Specify port (default: 8080)Plugin settings can be configured in Logi Plugin Service:
PostUrl: Custom POST endpoint URLGetUrl: Custom GET endpoint URL for stepsPollingInterval: Polling interval in milliseconds (default: 2000)InputPostUrl: Custom POST endpoint for input actions
EMA parameters can be adjusted in server.py:
_ema = EMA(
k=10, # Recent blocks to track
t=50, # Max frequency table size
nr=2, # Recent recommendations
nf=5, # Stable recommendations
ns=5 # Single tool recommendations
)MouseTron/
├── agent/ # Agent system
│ ├── agent.py # Main agent implementation
│ ├── main.py # Entry point
│ ├── graph.py # LangGraph export
│ └── studio/ # LangGraph Studio config
├── MouseTronPlugin/ # C# Loupedeck plugin
│ ├── src/
│ │ ├── MouseTronPlugin.cs
│ │ ├── Actions/ # Plugin actions
│ │ ├── Services/ # Server management
│ │ └── Helpers/ # Utility classes
│ └── package/ # Plugin metadata
├── containers/ # EMA persistence files
│ ├── name_to_number.json
│ ├── frequency_table.json
│ └── ...
├── recommendations/ # Generated recommendations
│ ├── recent_tools_combo_1.json
│ ├── stable_tools_combo_1.json
│ └── ...
├── dataset/ # Tool definitions and patterns
│ ├── zapier_tools.json
│ └── recommendation_showcase_patterns.txt
├── electron-popup/ # Electron UI for status
├── EMA.py # EMA algorithm
├── server.py # HTTP server
├── requirements.txt # Python dependencies
└── README.md # This file
-
Check Python installation:
python --version # Should be 3.8+ -
Check virtual environment (if using):
which python # Should point to venv -
Check environment variables:
echo $ANTHROPIC_API_KEY echo $ZAPIER_AUTHORIZATION_TOKEN
-
Check server logs:
- macOS:
~/Library/Application Support/Logi/LogiPluginService/Logs/plugin_logs/MouseTron.log - Windows:
%LOCALAPPDATA%\Logi\LogiPluginService\Logs\plugin_logs\MouseTron.log
- macOS:
-
Check .NET SDK:
dotnet --version # Should be 8.0+ -
Rebuild plugin:
cd MouseTronPlugin dotnet clean dotnet build -
Check plugin link file:
- macOS:
~/Library/Application Support/Logi/LogiPluginService/Plugins/MouseTronPlugin.link - Windows:
%LOCALAPPDATA%\Logi\LogiPluginService\Plugins\MouseTronPlugin.link
- macOS:
-
Check MCP connection:
- Verify Zapier authorization token is correct
- Check Anthropic API key is valid
-
Check tool discovery:
- Look for "Fetched X tools" message in logs
- Verify
dataset/zapier_tools.jsonexists as fallback
-
Check LangSmith (if using):
- Verify API key is correct
- Check project name matches
LANGSMITH_PROJECT
-
Check containers directory:
ls containers/ # Should contain JSON files -
Check recommendations directory:
ls recommendations/ # Should contain JSON files after first execution -
Verify tool names are being extracted:
- Check server logs for "Extracted X tool names"
- Verify agent is completing successfully
# Test agent directly
python agent/main.py
# Test server
python server.py -p 8080
# Test EMA
python EMA.pyVisualize and debug the agent workflow:
langgraph devThen open http://localhost:8123
- Create a new class in
MouseTronPlugin/src/Actions/ - Inherit from
PluginDynamicCommand - Implement
RunCommandmethod - Register in
MouseTronApplication.cs
[Add your license here]
[Add contribution guidelines here]