Replace Pattern Matching with AI-Driven Tool Selection for @enteract Commands
Issue Summary
Currently, @enteract commands use basic pattern matching to select MCP tools, which severely limits their capability for complex requests. Meanwhile, regular AI chat has a sophisticated AI-driven tool calling system that's much more capable but not exposed to users. We need to unify these systems to provide better tool selection and execution.
❗Proper MCP should exist but "@enteract" is a shortcut for regex - users don't have access to real MCP. Should unify if possible. The regex is reliable but limited.
First validate
Current Architecture Problems
Pattern Matching System (@enteract)
Location: src/composables/mcpService.ts - parseActionFromMessage()
Current Implementation:
// Very basic string matching
if (lowerMessage.includes('screenshot')) {
actions.push({ toolName: 'take_screenshot', parameters: {} })
}
if (lowerMessage.includes('click') && coordMatch) {
actions.push({ toolName: 'click_at', parameters: { x: 100, y: 200 } })
}
Limitations:
- ❌ Hardcoded string matching (
includes('screenshot'))
- ❌ Cannot handle complex multi-step requests
- ❌ Parameter extraction is primitive (basic regex only)
- ❌ No context understanding
- ❌ Cannot combine multiple tools intelligently
- ❌ Fails on requests like: "take a screenshot then click on the red button in the top right"
AI Tool Calling System (Regular Chat)
Location: src-tauri/src/ollama.rs - process_tool_calls() and build_mcp_system_prompt()
Current Implementation:
// AI model generates structured tool calls
let system_prompt = "You can use tools like: TOOL_CALL: take_screenshot {}"
// Model generates: "I'll help you. TOOL_CALL: take_screenshot {}"
let tool_call_pattern = regex::Regex::new(r"TOOL_CALL:\s*(\w+)\s*(\{[^}]*\})").ok()?;
Capabilities:
- ✅ Handles complex multi-step requests
- ✅ Understands context and intent
- ✅ Generates appropriate parameters automatically
- ✅ Can combine multiple tools intelligently
- ✅ Provides explanations and reasoning
Proposed Solution
Replace the pattern matching system with AI-driven tool selection for @enteract commands.
Option 1: Enhance @enteract with AI Planning (Recommended)
New Flow:
- User sends
@enteract take a screenshot and click login
- Frontend sends request to AI model for tool planning
- AI generates structured tool execution plan with
TOOL_CALL: format
- Backend parses and executes AI-generated plan sequentially
- Results displayed to user with progress updates
Option 2: Expose Existing AI Tool System
Make the existing generate_mcp_enabled_response available through user commands (e.g., @ai instead of @enteract).
Implementation Plan
Phase 1: Backend Changes
Files to modify: src-tauri/src/ollama.rs
-
Create new command: generate_mcp_tool_plan
#[tauri::command]
pub async fn generate_mcp_tool_plan(
user_request: String,
mcp_session_id: String,
planning_session_id: String,
// ... other params
) -> Result<(), String>
-
Enhanced system prompt for tool planning:
const TOOL_PLANNING_PROMPT: &str = r#"
You are a tool execution planner. Analyze the user request and create a step-by-step plan using available tools.
Available tools: {tool_list}
For each tool you want to use, format as:
TOOL_CALL: tool_name {"param1": "value1", "param2": "value2"}
Provide clear explanations for each step.
"#;
-
Event emission for tool plans:
app_handle.emit(&format!("mcp-tool-plan-{}", planning_session_id), tool_plan)
Phase 2: Frontend Changes
Files to modify: src/composables/mcpService.ts
-
Replace pattern matching in parseActionFromMessage():
// OLD: Pattern matching
private static parseActionFromMessage(message: string, availableTools: any[])
// NEW: AI-driven planning
private static async generateToolPlan(message: string, sessionId: string)
-
Add event listeners for AI-generated plans:
static listenForToolPlan(aiSessionId: string, thinkingMessageId: number, mcpSessionId: string)
-
Sequential execution of AI-generated tool plans:
static async executeToolPlan(toolPlan: any, sessionId: string, messageId: number)
Phase 3: UI/UX Improvements
- Progress indicators during multi-step execution
- Plan preview before execution (for complex requests)
- Better error handling and recovery
- Approval system for high-risk tool combinations
Files to Modify
Backend (Rust)
Frontend (TypeScript)
Example Improvements
Before (Pattern Matching)
User: "@enteract take a screenshot and click on the login button"
Result: ❌ Only takes screenshot (can't parse "click on login button")
After (AI-Driven)
User: "@enteract take a screenshot and click on the login button"
AI Plan:
1. TOOL_CALL: take_screenshot {}
2. TOOL_CALL: find_text {"text": "login"}
3. TOOL_CALL: click_on_text {"text": "login"}
Result: ✅ Takes screenshot, finds login button, clicks it
Testing Requirements
Unit Tests
Integration Tests
User Testing
Success Criteria
-
Functionality: @enteract can handle complex multi-step requests like "take a screenshot, find the search box, type 'hello world', and press enter"
-
Performance: AI planning completes within 2-3 seconds for typical requests
-
User Experience: Clear progress indicators and error messages for tool execution
-
Reliability: 95%+ success rate for well-formed tool requests
-
Backward Compatibility: Existing simple @enteract commands continue to work
Priority
High Priority - This directly impacts the core user experience of the MCP system and unlocks significantly more powerful automation capabilities.
Estimated Effort
2-3 days for core implementation + testing
- Day 1: Backend AI planning system
- Day 2: Frontend integration and event handling
- Day 3: Testing, refinement, and UX improvements
Replace Pattern Matching with AI-Driven Tool Selection for @enteract Commands
Issue Summary
Currently,
@enteractcommands use basic pattern matching to select MCP tools, which severely limits their capability for complex requests. Meanwhile, regular AI chat has a sophisticated AI-driven tool calling system that's much more capable but not exposed to users. We need to unify these systems to provide better tool selection and execution.❗Proper MCP should exist but "@enteract" is a shortcut for regex - users don't have access to real MCP. Should unify if possible. The regex is reliable but limited.
First validate
Current Architecture Problems
Pattern Matching System (@enteract)
Location:
src/composables/mcpService.ts-parseActionFromMessage()Current Implementation:
Limitations:
includes('screenshot'))AI Tool Calling System (Regular Chat)
Location:
src-tauri/src/ollama.rs-process_tool_calls()andbuild_mcp_system_prompt()Current Implementation:
Capabilities:
Proposed Solution
Replace the pattern matching system with AI-driven tool selection for @enteract commands.
Option 1: Enhance @enteract with AI Planning (Recommended)
New Flow:
@enteract take a screenshot and click loginTOOL_CALL:formatOption 2: Expose Existing AI Tool System
Make the existing
generate_mcp_enabled_responseavailable through user commands (e.g.,@aiinstead of@enteract).Implementation Plan
Phase 1: Backend Changes
Files to modify:
src-tauri/src/ollama.rsCreate new command:
generate_mcp_tool_planEnhanced system prompt for tool planning:
Event emission for tool plans:
Phase 2: Frontend Changes
Files to modify:
src/composables/mcpService.tsReplace pattern matching in
parseActionFromMessage():Add event listeners for AI-generated plans:
Sequential execution of AI-generated tool plans:
Phase 3: UI/UX Improvements
Files to Modify
Backend (Rust)
src-tauri/src/ollama.rs- Addgenerate_mcp_tool_plancommandsrc-tauri/src/system_prompts.rs- Add tool planning promptsrc-tauri/src/lib.rs- Register new commandFrontend (TypeScript)
src/composables/mcpService.ts- Replace pattern matching with AI planningsrc/composables/agentService.ts- Update @enteract routing if neededExample Improvements
Before (Pattern Matching)
After (AI-Driven)
Testing Requirements
Unit Tests
Integration Tests
User Testing
Success Criteria
Functionality: @enteract can handle complex multi-step requests like "take a screenshot, find the search box, type 'hello world', and press enter"
Performance: AI planning completes within 2-3 seconds for typical requests
User Experience: Clear progress indicators and error messages for tool execution
Reliability: 95%+ success rate for well-formed tool requests
Backward Compatibility: Existing simple @enteract commands continue to work
Priority
High Priority - This directly impacts the core user experience of the MCP system and unlocks significantly more powerful automation capabilities.
Estimated Effort
2-3 days for core implementation + testing