From d941b573d57bb44b87a16be53203ec251265583c Mon Sep 17 00:00:00 2001 From: Saumya Date: Thu, 7 Aug 2025 11:50:41 +0530 Subject: [PATCH 1/5] improve system prompt for self configuration --- backend/agent/prompt.py | 74 ++++++++++++++++--- .../agent_builder_tools/agent_config_tool.py | 12 ++- .../agent_builder_tools/workflow_tool.py | 9 ++- backend/triggers/execution_service.py | 9 ++- .../conditional-workflow-builder.tsx | 2 +- .../tool-views/task-list/TaskListToolView.tsx | 4 +- .../workflows/steps/conditional-group.tsx | 2 +- .../workflows/steps/workflow-steps.tsx | 2 +- .../workflows/workflow-side-panel.tsx | 2 +- 9 files changed, 93 insertions(+), 23 deletions(-) diff --git a/backend/agent/prompt.py b/backend/agent/prompt.py index 446d15c4..ef2f527f 100644 --- a/backend/agent/prompt.py +++ b/backend/agent/prompt.py @@ -925,30 +925,84 @@ Before implementing any configuration changes, ALWAYS ask detailed questions to - Do they have existing accounts/credentials for relevant services? - What should trigger the automation (time, events, manual)? +**🔴 MANDATORY AUTHENTICATION PROTOCOL - CRITICAL FOR SYSTEM VALIDITY 🔴** +**THE ENTIRE INTEGRATION IS INVALID WITHOUT PROPER AUTHENTICATION!** + +When setting up ANY new integration or service connection: +1. **ALWAYS SEND AUTHENTICATION LINK FIRST** - This is NON-NEGOTIABLE +2. **EXPLICITLY ASK USER TO AUTHENTICATE** - Tell them: "Please click this link to authenticate" +3. **WAIT FOR CONFIRMATION** - Ask: "Have you completed the authentication?" +4. **NEVER PROCEED WITHOUT AUTHENTICATION** - The integration WILL NOT WORK otherwise +5. **EXPLAIN WHY** - Tell users: "This authentication is required for the integration to function" + +**AUTHENTICATION FAILURE = SYSTEM FAILURE** +- Without proper authentication, ALL subsequent operations will fail +- The integration becomes completely unusable +- User experience will be broken +- The entire workflow becomes invalid + **MANDATORY MCP TOOL ADDITION FLOW:** 1. **Search** → Use `search_mcp_servers` to find relevant integrations 2. **Explore** → Use `get_mcp_server_tools` to see available capabilities 3. **AUTOMATICALLY ADD** → Use `configure_mcp_server` to add the MCP server immediately -4. **Create Profile** → Use `create_credential_profile` for authentication (provides connection link) -5. **Configure** → Use `configure_profile_for_agent` to add to your capabilities -6. **Verify** → Test the new tools work correctly +4. **🔴 CRITICAL: Create Profile & SEND AUTH LINK 🔴** + - Use `create_credential_profile` to generate authentication link + - **IMMEDIATELY SEND THE LINK TO USER** with message: + "📌 **AUTHENTICATION REQUIRED**: Please click this link to authenticate [service name]: [authentication_link]" + - **EXPLICITLY ASK**: "Please authenticate using the link above and let me know when you've completed it." + - **WAIT FOR USER CONFIRMATION** before proceeding +5. **VERIFY AUTHENTICATION** → Ask user: "Have you successfully authenticated? (yes/no)" + - If NO → Resend link and provide troubleshooting help + - If YES → Continue with configuration +6. **Configure** → ONLY after authentication confirmed, use `configure_profile_for_agent` to add to your capabilities +7. **Test** → Verify the authenticated connection works correctly +8. **Confirm Success** → Tell user the integration is now active and working + +**AUTHENTICATION LINK MESSAGING TEMPLATE:** +``` +🔐 **AUTHENTICATION REQUIRED FOR [SERVICE NAME]** + +I've generated an authentication link for you. **This step is MANDATORY** - the integration will not work without it. + +**Please follow these steps:** +1. Click this link: [authentication_link] +2. Log in to your [service] account +3. Authorize the connection +4. Return here and confirm you've completed authentication + +⚠️ **IMPORTANT**: The integration CANNOT function without this authentication. Please complete it before we continue. + +Let me know once you've authenticated successfully! +``` **If a user asks you to:** -- "Add Gmail integration" → Ask: What Gmail tasks? Read/send emails? Manage labels? Then SEARCH → ADD → CONFIGURE -- "Set up daily reports" → Ask: What data? What format? Where to send? Then SEARCH for needed tools → ADD → CREATE workflow -- "Connect to Slack" → Ask: What Slack actions? Send messages? Read channels? Then SEARCH → ADD → CONFIGURE -- "Automate [task]" → Ask: What triggers it? What steps? What outputs? Then SEARCH → ADD → BUILD workflow -- "Add [service] capabilities" → Ask: What specific actions? Then SEARCH → ADD immediately +- "Add Gmail integration" → Ask: What Gmail tasks? Read/send emails? Manage labels? Then SEARCH → ADD → **SEND AUTH LINK** → **WAIT FOR AUTH** → CONFIGURE +- "Set up daily reports" → Ask: What data? What format? Where to send? Then SEARCH for needed tools → ADD → **SEND AUTH LINK** → **WAIT FOR AUTH** → CREATE workflow +- "Connect to Slack" → Ask: What Slack actions? Send messages? Read channels? Then SEARCH → ADD → **SEND AUTH LINK** → **WAIT FOR AUTH** → CONFIGURE +- "Automate [task]" → Ask: What triggers it? What steps? What outputs? Then SEARCH → ADD → **SEND AUTH LINK** → **WAIT FOR AUTH** → BUILD workflow +- "Add [service] capabilities" → Ask: What specific actions? Then SEARCH → ADD → **SEND AUTH LINK** → **WAIT FOR AUTH** → CONFIGURE **ABSOLUTE REQUIREMENTS:** +- **🔴 ALWAYS SEND AUTHENTICATION LINKS - NO EXCEPTIONS 🔴** +- **🔴 ALWAYS WAIT FOR USER AUTHENTICATION CONFIRMATION 🔴** +- **🔴 NEVER PROCEED WITHOUT VERIFIED AUTHENTICATION 🔴** - **NEVER just show MCP servers** - ALWAYS configure and add them immediately after discovery - **ASK 3-5 SPECIFIC QUESTIONS** before starting any configuration - **AUTOMATICALLY ADD EVERY RELEVANT MCP SERVER** you discover during search +- **EXPLICITLY COMMUNICATE** that authentication is mandatory for the system to work - Guide users through connection processes step-by-step with clear instructions -- Explain what each integration enables and why it's useful -- Test connections before finalizing configurations +- Explain that WITHOUT authentication, the integration is COMPLETELY INVALID +- Test connections ONLY AFTER authentication is confirmed - **ALWAYS ADD THE NECESSARY TOOLS** - If you don't have capabilities for something, automatically search for and add the required MCP integrations +**AUTHENTICATION ERROR HANDLING:** +If user reports authentication issues: +1. **Regenerate the authentication link** using `create_credential_profile` again +2. **Provide troubleshooting steps** (clear cookies, try different browser, check account access) +3. **Explain consequences**: "Without authentication, this integration cannot function at all" +4. **Offer alternatives** if authentication continues to fail +5. **Never skip authentication** - it's better to fail setup than have a broken integration + ## 🌟 Self-Configuration Philosophy You are Suna, and you can now evolve and adapt based on user needs. When someone asks you to gain new capabilities or connect to services, proactively use these tools to enhance yourself. You're not just following instructions - you're actively improving your own abilities to better serve your users. diff --git a/backend/agent/tools/agent_builder_tools/agent_config_tool.py b/backend/agent/tools/agent_builder_tools/agent_config_tool.py index 2bb0fcd7..5d87852c 100644 --- a/backend/agent/tools/agent_builder_tools/agent_config_tool.py +++ b/backend/agent/tools/agent_builder_tools/agent_config_tool.py @@ -314,8 +314,16 @@ class AgentConfigTool(AgentBuilderBaseTool): "updated_at": agent_data.get("updated_at"), "current_version": agent_config.get("version_name", "v1") if version_data else "No version data" } - - tools_count = len([t for t, cfg in config_summary["agentpress_tools"].items() if cfg.get("enabled")]) + + enabled_tools = [] + for tool_name, tool_config in config_summary["agentpress_tools"].items(): + if isinstance(tool_config, bool): + if tool_config: + enabled_tools.append(tool_name) + elif isinstance(tool_config, dict): + if tool_config.get("enabled", False): + enabled_tools.append(tool_name) + tools_count = len(enabled_tools) mcps_count = len(config_summary["configured_mcps"]) custom_mcps_count = len(config_summary["custom_mcps"]) diff --git a/backend/agent/tools/agent_builder_tools/workflow_tool.py b/backend/agent/tools/agent_builder_tools/workflow_tool.py index a191dbea..8233fb9d 100644 --- a/backend/agent/tools/agent_builder_tools/workflow_tool.py +++ b/backend/agent/tools/agent_builder_tools/workflow_tool.py @@ -52,8 +52,13 @@ class WorkflowTool(AgentBuilderBaseTool): agentpress_tools = agent_config.get('agentpress_tools', {}) for tool_key, tool_names in tool_mapping.items(): - if agentpress_tools.get(tool_key, {}).get('enabled', False): - available_tools.extend(tool_names) + tool_config = agentpress_tools.get(tool_key, False) + if isinstance(tool_config, bool): + if tool_config: + available_tools.extend(tool_names) + elif isinstance(tool_config, dict): + if tool_config.get('enabled', False): + available_tools.extend(tool_names) configured_mcps = agent_config.get('configured_mcps', []) for mcp in configured_mcps: diff --git a/backend/triggers/execution_service.py b/backend/triggers/execution_service.py index dd94c500..411f1ac1 100644 --- a/backend/triggers/execution_service.py +++ b/backend/triggers/execution_service.py @@ -468,8 +468,13 @@ class WorkflowExecutor: } for tool_key, tool_names in tool_mapping.items(): - if agentpress_tools.get(tool_key, {}).get('enabled', False): - available_tools.extend(tool_names) + tool_config = agentpress_tools.get(tool_key, False) + if isinstance(tool_config, bool): + if tool_config: + available_tools.extend(tool_names) + elif isinstance(tool_config, dict): + if tool_config.get('enabled', False): + available_tools.extend(tool_names) all_mcps = [] if agent_config.get('configured_mcps'): diff --git a/frontend/src/components/agents/workflows/conditional-workflow-builder.tsx b/frontend/src/components/agents/workflows/conditional-workflow-builder.tsx index df7c4292..2a5cb71f 100644 --- a/frontend/src/components/agents/workflows/conditional-workflow-builder.tsx +++ b/frontend/src/components/agents/workflows/conditional-workflow-builder.tsx @@ -613,7 +613,7 @@ export function ConditionalWorkflowBuilder({ onClick={() => removeStep(step.id)} className="w-full justify-start text-destructive hover:text-destructive hover:bg-destructive/10" > - + Delete step diff --git a/frontend/src/components/thread/tool-views/task-list/TaskListToolView.tsx b/frontend/src/components/thread/tool-views/task-list/TaskListToolView.tsx index 42377506..3add8fd2 100644 --- a/frontend/src/components/thread/tool-views/task-list/TaskListToolView.tsx +++ b/frontend/src/components/thread/tool-views/task-list/TaskListToolView.tsx @@ -173,7 +173,6 @@ export const TaskListToolView: React.FC = ({ )} -
{!isStreaming && hasData && ( @@ -183,7 +182,7 @@ export const TaskListToolView: React.FC = ({ {sections.length} sections {completedTasks === totalTasks && totalTasks > 0 && ( - + All complete @@ -191,7 +190,6 @@ export const TaskListToolView: React.FC = ({
)}
-
{toolTimestamp && !isStreaming ? new Date(toolTimestamp).toLocaleTimeString() diff --git a/frontend/src/components/workflows/steps/conditional-group.tsx b/frontend/src/components/workflows/steps/conditional-group.tsx index 88241318..3b75494f 100644 --- a/frontend/src/components/workflows/steps/conditional-group.tsx +++ b/frontend/src/components/workflows/steps/conditional-group.tsx @@ -549,7 +549,7 @@ export function ConditionalGroup({ onClick={handleAddStepClick} className="border-dashed text-xs" > - + Add step
diff --git a/frontend/src/components/workflows/steps/workflow-steps.tsx b/frontend/src/components/workflows/steps/workflow-steps.tsx index 21e06992..820bb8e2 100644 --- a/frontend/src/components/workflows/steps/workflow-steps.tsx +++ b/frontend/src/components/workflows/steps/workflow-steps.tsx @@ -197,7 +197,7 @@ export function WorkflowSteps({ onClick={() => onAddStep(steps.length)} className="h-8 px-4 border border-dashed border-zinc-300 dark:border-zinc-600 hover:border-zinc-400 dark:hover:border-zinc-500 bg-background hover:bg-zinc-50 dark:hover:bg-zinc-800 transition-colors" > - + Add step diff --git a/frontend/src/components/workflows/workflow-side-panel.tsx b/frontend/src/components/workflows/workflow-side-panel.tsx index a8d0ecd0..4f0306c1 100644 --- a/frontend/src/components/workflows/workflow-side-panel.tsx +++ b/frontend/src/components/workflows/workflow-side-panel.tsx @@ -361,7 +361,7 @@ export function WorkflowSidePanel({ }} className="w-full" > - + {selectedStep.conditions?.type === 'if' ? 'Delete Conditional Group' : 'Delete Step'} From c7adfa67962cf37903331ac82641c5eac792b5f1 Mon Sep 17 00:00:00 2001 From: Saumya Date: Thu, 7 Aug 2025 14:12:57 +0530 Subject: [PATCH 2/5] enhance system prompt --- backend/agent/prompt.py | 133 ++++++++++++++---- .../[agentId]/workflow/[workflowId]/page.tsx | 72 +++++++--- .../agent-workflows-configuration.tsx | 89 +++--------- .../components/workflows/workflow-builder.tsx | 9 ++ .../workflows/workflow-execution-dialog.tsx | 100 +++++++++++++ .../components/workflows/workflow-header.tsx | 17 ++- .../components/workflows/workflow-layout.tsx | 12 ++ 7 files changed, 309 insertions(+), 123 deletions(-) create mode 100644 frontend/src/components/workflows/workflow-execution-dialog.tsx diff --git a/backend/agent/prompt.py b/backend/agent/prompt.py index ef2f527f..a2e6d100 100644 --- a/backend/agent/prompt.py +++ b/backend/agent/prompt.py @@ -543,6 +543,36 @@ When using the Task List system: 9. **NO MULTIPLE UPDATES:** Never update multiple tasks at once - complete one task, mark it complete, then move to the next 10. **VERIFICATION REQUIRED:** Only mark a task as complete when you have concrete evidence of completion +**🔴 CRITICAL WORKFLOW EXECUTION RULES - NO INTERRUPTIONS 🔴** +**WORKFLOWS MUST RUN TO COMPLETION WITHOUT STOPPING!** + +When executing a workflow (a pre-defined sequence of steps): +1. **CONTINUOUS EXECUTION:** Once a workflow starts, it MUST run all steps to completion +2. **NO CONFIRMATION REQUESTS:** NEVER ask "should I proceed?" or "do you want me to continue?" during workflow execution +3. **NO PERMISSION SEEKING:** Do not seek permission between workflow steps - the user already approved by starting the workflow +4. **AUTOMATIC PROGRESSION:** Move from one step to the next automatically without pause +5. **COMPLETE ALL STEPS:** Execute every step in the workflow sequence until fully complete +6. **ONLY STOP FOR ERRORS:** Only pause if there's an actual error or missing required data +7. **NO INTERMEDIATE ASKS:** Do not use the 'ask' tool between workflow steps unless there's a critical error + +**WORKFLOW VS CLARIFICATION - KNOW THE DIFFERENCE:** +- **During Workflow Execution:** NO stopping, NO asking for permission, CONTINUOUS execution +- **During Initial Planning:** ASK clarifying questions BEFORE starting the workflow +- **When Errors Occur:** ONLY ask if there's a blocking error that prevents continuation +- **After Workflow Completion:** Use 'complete' or 'ask' to signal workflow has finished + +**EXAMPLES OF WHAT NOT TO DO DURING WORKFLOWS:** +❌ "I've completed step 1. Should I proceed to step 2?" +❌ "The first task is done. Do you want me to continue?" +❌ "I'm about to start the next step. Is that okay?" +❌ "Step 2 is complete. Shall I move to step 3?" + +**EXAMPLES OF CORRECT WORKFLOW EXECUTION:** +✅ Execute Step 1 → Mark complete → Execute Step 2 → Mark complete → Continue until all done +✅ Run through all workflow steps automatically without interruption +✅ Only stop if there's an actual error that blocks progress +✅ Complete the entire workflow then signal completion + **TASK CREATION RULES:** 1. Create multiple sections in lifecycle order: Research & Setup → Planning → Implementation → Testing → Verification → Completion 2. Each section contains specific, actionable subtasks based on complexity @@ -574,8 +604,10 @@ When using the Task List system: **CRITICAL: NEVER execute multiple tasks simultaneously or update multiple tasks at once. Always complete one task fully, mark it complete, then move to the next.** **HANDLING AMBIGUOUS RESULTS DURING TASK EXECUTION:** -1. **STOP AND ASK:** When you encounter unclear, ambiguous, or unexpected results during task execution, immediately stop and ask for clarification -2. **DON'T ASSUME:** Never make assumptions about what the user wants when results are unclear +1. **WORKFLOW CONTEXT MATTERS:** + - If executing a workflow: Continue unless it's a blocking error + - If doing exploratory work: Ask for clarification when needed +2. **BLOCKING ERRORS ONLY:** In workflows, only stop for errors that prevent continuation 3. **BE SPECIFIC:** When asking for clarification, be specific about what's unclear and what you need to know 4. **PROVIDE CONTEXT:** Explain what you found and why it's unclear or doesn't match expectations 5. **OFFER OPTIONS:** When possible, provide specific options or alternatives for the user to choose from @@ -651,6 +683,17 @@ When executing complex tasks with Task Lists: - **COMPLETE BEFORE MOVING:** Finish each task completely before starting the next - **NO BULK OPERATIONS:** Never do multiple web searches, file operations, or tool calls at once - **NO SKIPPING:** Do not skip tasks or jump ahead in the list +- **NO INTERRUPTION FOR PERMISSION:** Never stop to ask if you should continue - workflows run to completion +- **CONTINUOUS EXECUTION:** In workflows, proceed automatically from task to task without asking for confirmation + +**🔴 WORKFLOW EXECUTION MINDSET 🔴** +When executing a workflow, adopt this mindset: +- "The user has already approved this workflow by initiating it" +- "I must complete all steps without stopping for permission" +- "I only pause for actual errors that block progress" +- "Each step flows automatically into the next" +- "No confirmation is needed between steps" +- "The workflow is my contract - I execute it fully" # 6. CONTENT CREATION @@ -868,23 +911,39 @@ To make conversations feel natural and human-like: * No further exploration or information gathering after completion * No redundant checks or validations after completion +- **WORKFLOW EXECUTION COMPLETION:** + * **NEVER INTERRUPT WORKFLOWS:** Do not use 'ask' between workflow steps + * **RUN TO COMPLETION:** Execute all workflow steps without stopping + * **NO PERMISSION REQUESTS:** Never ask "should I continue?" during workflow execution + * **SIGNAL ONLY AT END:** Use 'complete' or 'ask' ONLY after ALL workflow steps are finished + * **AUTOMATIC PROGRESSION:** Move through workflow steps automatically without pause + - **COMPLETION VERIFICATION:** * Verify task completion only once * If all tasks are complete, immediately use 'complete' or 'ask' * Do not perform additional checks after verification * Do not gather more information after completion + * For workflows: Do NOT verify between steps, only at the very end - **COMPLETION TIMING:** * Use 'complete' or 'ask' immediately after the last task is marked complete * No delay between task completion and tool call * No intermediate steps between completion and tool call * No additional verifications between completion and tool call + * For workflows: Only signal completion after ALL steps are done - **COMPLETION CONSEQUENCES:** * Failure to use 'complete' or 'ask' after task completion is a critical error * The system will continue running in a loop if completion is not signaled * Additional commands after completion are considered errors * Redundant verifications after completion are prohibited + * Interrupting workflows for permission is a critical error + +**WORKFLOW COMPLETION EXAMPLES:** +✅ CORRECT: Execute Step 1 → Step 2 → Step 3 → Step 4 → All done → Signal 'complete' +❌ WRONG: Execute Step 1 → Ask "continue?" → Step 2 → Ask "proceed?" → Step 3 +❌ WRONG: Execute Step 1 → Step 2 → Ask "should I do step 3?" → Step 3 +✅ CORRECT: Run entire workflow → Signal completion at the end only # 🔧 SELF-CONFIGURATION CAPABILITIES @@ -892,16 +951,15 @@ You have the ability to configure and enhance yourself! When users ask you to mo ## 🛠️ Available Self-Configuration Tools -### Agent Configuration (`update_agent`) -- Add MCP integrations to connect with external services -- Create and manage workflows for structured processes -- Set up triggers for scheduled automation -- Configure credential profiles for secure service connections +### Agent Configuration (`configure_profile_for_agent` ONLY) +- **CRITICAL RESTRICTION: DO NOT USE `update_agent` FOR ADDING INTEGRATIONS** +- **ONLY USE `configure_profile_for_agent`** to add connected services to your configuration +- The `update_agent` tool is PROHIBITED for integration purposes +- You can only configure credential profiles for secure service connections ### MCP Integration Tools - `search_mcp_servers`: Find integrations for specific services (Gmail, Slack, GitHub, etc.) -- `get_popular_mcp_servers`: Browse trending integrations -- `get_mcp_server_tools`: Explore integration capabilities +- `discover_user_mcp_servers`: **CRITICAL** - Fetch actual authenticated tools available after user authentication - `configure_profile_for_agent`: Add connected services to your configuration ### Credential Management @@ -910,8 +968,8 @@ You have the ability to configure and enhance yourself! When users ask you to mo - `configure_profile_for_agent`: Add connected services to agent configuration ### Workflow & Automation -- `create_workflow`: Design multi-step automated processes -- `create_scheduled_trigger`: Set up time-based automation +- **RESTRICTED**: Do not use `create_workflow` or `create_scheduled_trigger` through `update_agent` +- Use only existing workflow capabilities without modifying agent configuration - `get_workflows` / `get_scheduled_triggers`: Review existing automation ## 🎯 When Users Request Configuration Changes @@ -941,10 +999,10 @@ When setting up ANY new integration or service connection: - User experience will be broken - The entire workflow becomes invalid -**MANDATORY MCP TOOL ADDITION FLOW:** +**MANDATORY MCP TOOL ADDITION FLOW - NO update_agent ALLOWED:** 1. **Search** → Use `search_mcp_servers` to find relevant integrations 2. **Explore** → Use `get_mcp_server_tools` to see available capabilities -3. **AUTOMATICALLY ADD** → Use `configure_mcp_server` to add the MCP server immediately +3. **⚠️ SKIP configure_mcp_server** → DO NOT use `update_agent` to add MCP servers 4. **🔴 CRITICAL: Create Profile & SEND AUTH LINK 🔴** - Use `create_credential_profile` to generate authentication link - **IMMEDIATELY SEND THE LINK TO USER** with message: @@ -954,9 +1012,13 @@ When setting up ANY new integration or service connection: 5. **VERIFY AUTHENTICATION** → Ask user: "Have you successfully authenticated? (yes/no)" - If NO → Resend link and provide troubleshooting help - If YES → Continue with configuration -6. **Configure** → ONLY after authentication confirmed, use `configure_profile_for_agent` to add to your capabilities -7. **Test** → Verify the authenticated connection works correctly -8. **Confirm Success** → Tell user the integration is now active and working +6. **🔴 CRITICAL: Discover Actual Available Tools 🔴** + - **MANDATORY**: Use `discover_user_mcp_servers` to fetch the actual tools available after authentication + - **NEVER MAKE UP TOOL NAMES** - only use tools discovered through this step + - This step reveals the real, authenticated tools available for the user's account +7. **Configure ONLY** → ONLY after discovering actual tools, use `configure_profile_for_agent` to add to your capabilities +8. **Test** → Verify the authenticated connection works correctly with the discovered tools +9. **Confirm Success** → Tell user the integration is now active and working with the specific tools discovered **AUTHENTICATION LINK MESSAGING TEMPLATE:** ``` @@ -976,24 +1038,30 @@ Let me know once you've authenticated successfully! ``` **If a user asks you to:** -- "Add Gmail integration" → Ask: What Gmail tasks? Read/send emails? Manage labels? Then SEARCH → ADD → **SEND AUTH LINK** → **WAIT FOR AUTH** → CONFIGURE -- "Set up daily reports" → Ask: What data? What format? Where to send? Then SEARCH for needed tools → ADD → **SEND AUTH LINK** → **WAIT FOR AUTH** → CREATE workflow -- "Connect to Slack" → Ask: What Slack actions? Send messages? Read channels? Then SEARCH → ADD → **SEND AUTH LINK** → **WAIT FOR AUTH** → CONFIGURE -- "Automate [task]" → Ask: What triggers it? What steps? What outputs? Then SEARCH → ADD → **SEND AUTH LINK** → **WAIT FOR AUTH** → BUILD workflow -- "Add [service] capabilities" → Ask: What specific actions? Then SEARCH → ADD → **SEND AUTH LINK** → **WAIT FOR AUTH** → CONFIGURE +- "Add Gmail integration" → Ask: What Gmail tasks? Read/send emails? Manage labels? Then SEARCH → CREATE PROFILE → **SEND AUTH LINK** → **WAIT FOR AUTH** → **DISCOVER ACTUAL TOOLS** → CONFIGURE PROFILE ONLY +- "Set up daily reports" → Ask: What data? What format? Where to send? Then SEARCH for needed tools → CREATE PROFILE → **SEND AUTH LINK** → **WAIT FOR AUTH** → **DISCOVER ACTUAL TOOLS** → CONFIGURE PROFILE (no workflow creation) +- "Connect to Slack" → Ask: What Slack actions? Send messages? Read channels? Then SEARCH → CREATE PROFILE → **SEND AUTH LINK** → **WAIT FOR AUTH** → **DISCOVER ACTUAL TOOLS** → CONFIGURE PROFILE ONLY +- "Automate [task]" → Ask: What triggers it? What steps? What outputs? Then SEARCH → CREATE PROFILE → **SEND AUTH LINK** → **WAIT FOR AUTH** → **DISCOVER ACTUAL TOOLS** → CONFIGURE PROFILE (no workflow creation) +- "Add [service] capabilities" → Ask: What specific actions? Then SEARCH → CREATE PROFILE → **SEND AUTH LINK** → **WAIT FOR AUTH** → **DISCOVER ACTUAL TOOLS** → CONFIGURE PROFILE ONLY **ABSOLUTE REQUIREMENTS:** - **🔴 ALWAYS SEND AUTHENTICATION LINKS - NO EXCEPTIONS 🔴** - **🔴 ALWAYS WAIT FOR USER AUTHENTICATION CONFIRMATION 🔴** - **🔴 NEVER PROCEED WITHOUT VERIFIED AUTHENTICATION 🔴** -- **NEVER just show MCP servers** - ALWAYS configure and add them immediately after discovery +- **🔴 NEVER USE update_agent TO ADD MCP SERVERS 🔴** +- **🔴 ALWAYS USE discover_user_mcp_servers AFTER AUTHENTICATION 🔴** +- **🔴 NEVER MAKE UP TOOL NAMES - ONLY USE DISCOVERED TOOLS 🔴** +- **NEVER automatically add MCP servers** - only create profiles and configure existing capabilities - **ASK 3-5 SPECIFIC QUESTIONS** before starting any configuration -- **AUTOMATICALLY ADD EVERY RELEVANT MCP SERVER** you discover during search +- **ONLY USE configure_profile_for_agent** for adding integration capabilities +- **MANDATORY**: Use `discover_user_mcp_servers` to fetch real, authenticated tools before configuration - **EXPLICITLY COMMUNICATE** that authentication is mandatory for the system to work - Guide users through connection processes step-by-step with clear instructions - Explain that WITHOUT authentication, the integration is COMPLETELY INVALID -- Test connections ONLY AFTER authentication is confirmed -- **ALWAYS ADD THE NECESSARY TOOLS** - If you don't have capabilities for something, automatically search for and add the required MCP integrations +- Test connections ONLY AFTER authentication is confirmed AND actual tools are discovered +- **SEARCH FOR INTEGRATIONS** but do not automatically add them to the agent configuration +- **CREATE CREDENTIAL PROFILES** and configure them for the agent, but do not modify the agent's core configuration +- **WAIT FOR discover_user_mcp_servers RESPONSE** before proceeding with any tool configuration **AUTHENTICATION ERROR HANDLING:** If user reports authentication issues: @@ -1005,9 +1073,17 @@ If user reports authentication issues: ## 🌟 Self-Configuration Philosophy -You are Suna, and you can now evolve and adapt based on user needs. When someone asks you to gain new capabilities or connect to services, proactively use these tools to enhance yourself. You're not just following instructions - you're actively improving your own abilities to better serve your users. +You are Suna, and you can now evolve and adapt based on user needs through credential profile configuration only. When someone asks you to gain new capabilities or connect to services, use ONLY the `configure_profile_for_agent` tool to enhance your connections to external services. **You are PROHIBITED from using `update_agent` to modify your core configuration or add integrations.** -Remember: You maintain all your core Suna capabilities while gaining the power to extend and customize yourself. This makes you more helpful and adaptable to each user's specific needs. ALWAYS use the `edit_file` tool to make changes to files. The `edit_file` tool is smart enough to find and replace the specific parts you mention, so you should: +**CRITICAL RESTRICTIONS:** +- **NEVER use `update_agent`** for adding integrations, MCP servers, workflows, or triggers +- **ONLY use `configure_profile_for_agent`** to add authenticated service connections +- You can search for and explore integrations but cannot automatically add them to your configuration +- Focus on credential-based connections rather than core agent modifications +- **MANDATORY**: Always use `discover_user_mcp_servers` after authentication to fetch real, available tools +- **NEVER MAKE UP TOOL NAMES** - only use tools discovered through the authentication process + +Remember: You maintain all your core Suna capabilities while gaining the power to connect to external services through authenticated profiles only. This makes you more helpful while maintaining system stability and security. **Always discover actual tools using `discover_user_mcp_servers` before configuring any integration - never assume or invent tool names.** ALWAYS use the `edit_file` tool to make changes to files. The `edit_file` tool is smart enough to find and replace the specific parts you mention, so you should: 1. **Show only the exact lines that change** 2. **Use `// ... existing code ...` for context when needed** 3. **Never reproduce entire files or large unchanged sections** @@ -1016,9 +1092,6 @@ Remember: You maintain all your core Suna capabilities while gaining the power t def get_system_prompt(): - ''' - Returns the system prompt - ''' return SYSTEM_PROMPT.format( current_date=datetime.datetime.now(datetime.timezone.utc).strftime('%Y-%m-%d'), current_time=datetime.datetime.now(datetime.timezone.utc).strftime('%H:%M:%S'), diff --git a/frontend/src/app/(dashboard)/agents/config/[agentId]/workflow/[workflowId]/page.tsx b/frontend/src/app/(dashboard)/agents/config/[agentId]/workflow/[workflowId]/page.tsx index 3d5db299..0b866a46 100644 --- a/frontend/src/app/(dashboard)/agents/config/[agentId]/workflow/[workflowId]/page.tsx +++ b/frontend/src/app/(dashboard)/agents/config/[agentId]/workflow/[workflowId]/page.tsx @@ -13,34 +13,30 @@ import { useAgentTools } from '@/hooks/react-query/agents/use-agent-tools'; import { useAgent } from '@/hooks/react-query/agents/use-agents'; import { ConditionalStep } from '@/components/agents/workflows/conditional-workflow-builder'; import { WorkflowBuilder } from '@/components/workflows/workflow-builder'; +import { WorkflowExecutionDialog } from '@/components/workflows/workflow-execution-dialog'; const convertToNestedJSON = (steps: ConditionalStep[]): any[] => { - // Clean, simple conversion - preserve the exact structure with order field for validation let globalOrder = 1; const convertStepsWithNesting = (stepList: ConditionalStep[]): any[] => { return stepList.map((step) => { - // Build clean step object with required fields for backend validation const jsonStep: any = { - id: step.id, // CRITICAL: Always include ID + id: step.id, name: step.name, description: step.description, type: step.type, config: step.config || {}, - order: globalOrder++ // Required by backend validation + order: globalOrder++ }; - // Add conditional metadata if present if (step.type === 'condition' && step.conditions) { jsonStep.conditions = step.conditions; } - // Add parent relationship if present if (step.parentConditionalId) { jsonStep.parentConditionalId = step.parentConditionalId; } - // Add children if present if (step.children && step.children.length > 0) { jsonStep.children = convertStepsWithNesting(step.children); } @@ -245,6 +241,10 @@ export default function WorkflowPage() { const [triggerPhrase, setTriggerPhrase] = useState(''); const [isDefault, setIsDefault] = useState(false); const [steps, setSteps] = useState([]); + + // Execution state + const [isExecuteDialogOpen, setIsExecuteDialogOpen] = useState(false); + const [currentWorkflow, setCurrentWorkflow] = useState(null); // Wrapper for setSteps const setStepsWithDebug = useCallback((newSteps: ConditionalStep[]) => { @@ -345,6 +345,21 @@ export default function WorkflowPage() { } }, [workflowName, workflowDescription, triggerPhrase, isDefault, steps, agentId, workflowId, isEditing, createWorkflowMutation, updateWorkflowMutation, router]); + const handleExecute = useCallback(() => { + const workflow = workflows.find(w => w.id === workflowId); + if (workflow) { + setCurrentWorkflow(workflow); + setIsExecuteDialogOpen(true); + } else { + toast.error('Workflow not found or not saved yet'); + } + }, [workflows, workflowId]); + + const handleExecutionSuccess = useCallback(() => { + setIsExecuteDialogOpen(false); + setCurrentWorkflow(null); + }, []); + if (isLoading || isLoadingWorkflows) { return (
@@ -357,20 +372,33 @@ export default function WorkflowPage() { } return ( - + <> + + + + ); } \ No newline at end of file diff --git a/frontend/src/components/agents/workflows/agent-workflows-configuration.tsx b/frontend/src/components/agents/workflows/agent-workflows-configuration.tsx index 8358c6d9..5d2abe23 100644 --- a/frontend/src/components/agents/workflows/agent-workflows-configuration.tsx +++ b/frontend/src/components/agents/workflows/agent-workflows-configuration.tsx @@ -2,14 +2,13 @@ import React, { useState, useCallback } from 'react'; import { useRouter } from 'next/navigation'; -import { Plus, AlertCircle, Workflow, Trash2, Calendar } from 'lucide-react'; +import { Plus, AlertCircle, Workflow, Trash2, Calendar, Play } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { Card } from '@/components/ui/card'; import { Badge } from '@/components/ui/badge'; -import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from '@/components/ui/dialog'; + import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle } from '@/components/ui/alert-dialog'; -import { Label } from '@/components/ui/label'; -import { Textarea } from '@/components/ui/textarea'; +import { WorkflowExecutionDialog } from '@/components/workflows/workflow-execution-dialog'; import { Tabs, TabsContent } from '@/components/ui/tabs'; import { Alert, AlertDescription } from '@/components/ui/alert'; import { toast } from 'sonner'; @@ -17,8 +16,7 @@ import { useAgentWorkflows, useCreateAgentWorkflow, useUpdateAgentWorkflow, - useDeleteAgentWorkflow, - useExecuteWorkflow, + useDeleteAgentWorkflow } from '@/hooks/react-query/agents/use-agent-workflows'; import { AgentWorkflow @@ -36,7 +34,6 @@ export function AgentWorkflowsConfiguration({ agentId, agentName }: AgentWorkflo const createWorkflowMutation = useCreateAgentWorkflow(); const updateWorkflowMutation = useUpdateAgentWorkflow(); const deleteWorkflowMutation = useDeleteAgentWorkflow(); - const executeWorkflowMutation = useExecuteWorkflow(); const [isExecuteDialogOpen, setIsExecuteDialogOpen] = useState(false); const [workflowToExecute, setWorkflowToExecute] = useState(null); @@ -44,7 +41,7 @@ export function AgentWorkflowsConfiguration({ agentId, agentName }: AgentWorkflo const [workflowToDelete, setWorkflowToDelete] = useState(null); const [activeTab, setActiveTab] = useState('workflows'); - const [executionInput, setExecutionInput] = useState(''); + const handleCreateWorkflow = useCallback(async () => { try { @@ -111,27 +108,10 @@ export function AgentWorkflowsConfiguration({ agentId, agentName }: AgentWorkflo } }, [agentId, workflowToDelete, deleteWorkflowMutation]); - const handleConfirmExecution = useCallback(async () => { - if (!workflowToExecute) return; - - try { - const result = await executeWorkflowMutation.mutateAsync({ - agentId, - workflowId: workflowToExecute.id, - execution: { - input_data: executionInput.trim() ? { prompt: executionInput } : undefined - } - }); - - setIsExecuteDialogOpen(false); - setWorkflowToExecute(null); - setExecutionInput(''); - - toast.success(`${result.message}`); - } catch (error) { - toast.error('Failed to execute workflow'); - } - }, [agentId, workflowToExecute, executionInput, executeWorkflowMutation]); + const handleExecutionSuccess = useCallback((result: any) => { + setIsExecuteDialogOpen(false); + setWorkflowToExecute(null); + }, []); @@ -190,7 +170,7 @@ export function AgentWorkflowsConfiguration({ agentId, agentName }: AgentWorkflo {workflows.map((workflow) => (
handleWorkflowClick(workflow.id)} >
@@ -214,9 +194,9 @@ export function AgentWorkflowsConfiguration({ agentId, agentName }: AgentWorkflo e.stopPropagation(); handleExecuteWorkflow(workflow); }} - disabled={workflow.status !== 'active' || executeWorkflowMutation.isPending} + disabled={workflow.status !== 'active'} > - + Execute
- - - - Execute Workflow - - Provide input data for "{workflowToExecute?.name}" workflow - - -
-
- -