Skip to content

fix(tools): fixed workflow tool for agent to respect user provided params, inject at runtime like all other tools - #2750

Merged
waleedlatif1 merged 4 commits into
stagingfrom
fix/workflow-as-a-tool
Jan 10, 2026
Merged

fix(tools): fixed workflow tool for agent to respect user provided params, inject at runtime like all other tools#2750
waleedlatif1 merged 4 commits into
stagingfrom
fix/workflow-as-a-tool

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

Summary

  • fixed workflow tool for agent to respect user provided params, inject at runtime like all other tools
  • this caused the LLM to not detect when the user had provided fields, and inject them at runtime. basically, this treats all workflow inputs as 'user-or-llm' but has to be handled separately since the inputMapping is destructured into params for the agent, but its flat for all other tools
  • added workflowId, userAgent, workspaceId to the help tickets email

Type of Change

  • Bug fix

Testing

Tested manually.

  • Tested without ever touching the workflow tool inputs -> llm provides
  • Tested with touching it and clearing the field -> llm provides
  • Tested with providing my own value -> uses mine
  • Tested with telling it something random but providing a value -> uses mine

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel

vercelBot commented Jan 9, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
ProjectDeploymentReviewUpdated (UTC)
docsSkippedSkippedJan 10, 2026 1:12am

@greptile-appsgreptile-appsBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Greptile Overview

Greptile Summary

Changes Overview

This PR addresses two main issues:

  1. Help Ticket Enhancement: Adds contextual information (workflowId, workspaceId, userAgent) to help ticket emails to improve support debugging
  2. Workflow Tool Parameter Fix: Fixes the workflow_executor tool to properly respect user-provided parameters by implementing deep merge logic for inputMapping

Key Implementation Details

Help Ticket Context (3 files changed)

  • Modified help-modal.tsx to accept and pass workflowId and workspaceId props
  • Updated sidebar.tsx to provide these context values from URL params
  • Enhanced route.ts API to extract and include these fields in support emails

Workflow Tool Parameter Handling (4 files changed)

  • Created deepMergeInputMapping() function in tools/params.ts for intelligent parameter merging
  • Updated prepareToolExecution() in providers/utils.ts to use deep merge for inputMapping
  • Added createLLMToolSchema() special handling to always include inputMapping for workflow_executor
  • Extensive test coverage added for all new functionality

Problem Solved

Previously, the workflow_executor tool treated inputMapping as a regular parameter, so if a user provided an empty object {} or partial values in the UI, the LLM wouldn't be able to fill in dynamic values at runtime. The fix implements a deep merge strategy where:

  • User-provided non-empty values take precedence
  • LLM fills in missing or empty fields
  • This allows hybrid user/LLM parameter configuration

Issues Found

  1. Critical: workspaceId in email template doesn't handle null case (missing ?? 'N/A')
  2. Logic Bug: deepMergeInputMapping() incorrectly treats 0 and false as empty values, which would prevent users from explicitly setting these valid values

Confidence Score: 3/5

  • This PR is generally safe to merge but has two logic bugs that need fixing
  • Score of 3 reflects two important issues: (1) workspaceId can display "null" in emails due to missing null handling, and (2) deepMergeInputMapping incorrectly treats 0/false as empty, preventing users from setting these valid values. The core functionality is well-tested and sound, but these edge cases need addressing before merge.
  • apps/sim/app/api/help/route.ts needs null handling for workspaceId; apps/sim/tools/params.ts needs to properly handle 0 and false values in deepMergeInputMapping

Important Files Changed

File Analysis

FilenameScoreOverview
apps/sim/app/api/help/route.ts3/5Adds workflowId, workspaceId, and userAgent to help ticket emails; workspaceId missing null handling
apps/sim/providers/utils.ts4/5Implements special deep merge handling for inputMapping in prepareToolExecution
apps/sim/tools/params.ts3/5Adds deepMergeInputMapping function and updates mergeToolParameters; edge case with 0/false values

Sequence Diagram

sequenceDiagram
participant User
participant HelpModal
participant HelpAPI
participant Email
participant Agent
participant WorkflowTool
participant PrepareToolExec
participant DeepMerge
Note over User,Email: Help Ticket Flow (New)
User->>HelpModal: Opens help modal
HelpModal->>HelpModal: Captures workflowId, workspaceId from context
User->>HelpModal: Fills form and submits
HelpModal->>HelpAPI: POST /api/help with formData
Note right of HelpModal: Includes: subject, message, type<br/>workflowId, workspaceId, userAgent
HelpAPI->>HelpAPI: Extract and validate fields
HelpAPI->>Email: Send email with context info
Note right of Email: Email now includes:<br/>workflowId, workspaceId, userId, userAgent
Email-->>User: Confirmation email sent
Note over Agent,DeepMerge: Workflow Tool Parameter Flow (Fixed)
Agent->>WorkflowTool: Uses workflow_executor tool
Agent->>WorkflowTool: Provides llmArgs (inputMapping)
Note right of Agent: User may have provided partial<br/>or empty inputMapping in UI
WorkflowTool->>PrepareToolExec: prepareToolExecution(tool, llmArgs, request)
PrepareToolExec->>PrepareToolExec: Filter empty user params
PrepareToolExec->>PrepareToolExec: Check if param is inputMapping
PrepareToolExec->>DeepMerge: deepMergeInputMapping(llm, user)
DeepMerge->>DeepMerge: Parse user JSON string if needed
DeepMerge->>DeepMerge: Merge: LLM values as base
DeepMerge->>DeepMerge: Override with non-empty user values
DeepMerge-->>PrepareToolExec: Merged inputMapping
PrepareToolExec-->>WorkflowTool: toolParams with merged inputMapping
WorkflowTool->>WorkflowTool: Execute workflow with merged params
Loading

Comment threadapps/sim/app/api/help/route.ts Outdated
Comment threadapps/sim/tools/params.ts
@waleedlatif1

Copy link
Copy Markdown
CollaboratorAuthor

@greptile

@greptile-apps

greptile-appsBot commented Jan 10, 2026

Copy link
Copy Markdown
Contributor

Greptile Overview

Greptile Summary

Fixes workflow_executor tool to properly respect user-provided parameters by always including inputMapping in the LLM schema and implementing deep merge logic. Previously, any user interaction with inputMapping fields would prevent the LLM from filling empty values, but now the LLM can dynamically populate fields the user left blank while preserving explicitly set values. Additionally enhances help ticket emails by including workflowId, workspaceId, and userAgent for better support context.

Confidence Score: 4/5

  • Safe to merge after addressing the identified test coverage consideration
  • The core logic is well-implemented with comprehensive test coverage for the inputMapping deep merge behavior. The special handling for workflow_executor is properly isolated and documented. However, there's no integration test verifying the end-to-end flow from LLM schema generation through parameter merging to execution, which would provide additional confidence in the complete workflow.
  • apps/sim/tools/params.ts and apps/sim/providers/utils.ts require attention due to duplicated logic

Important Files Changed

File Analysis

FilenameScoreOverview
apps/sim/tools/params.ts4/5Adds workflow inputMapping special handling with deep merge logic and comprehensive test coverage
apps/sim/providers/utils.ts4/5Mirrors inputMapping deep merge logic in prepareToolExecution with comprehensive test coverage

Sequence Diagram

sequenceDiagram
participant UI as Workflow UI
participant Schema as createLLMToolSchema
participant LLM as Language Model
participant Merge as mergeToolParameters
participant Exec as prepareToolExecution
participant Tool as Workflow Executor
Note over UI,Tool: User configures workflow with empty inputMapping fields
UI->>Schema: Generate schema for LLM<br/>userParams: {workflowId, inputMapping: {query: ""}}
Note over Schema: Special handling for workflow_executor
Schema-->>Schema: Always include inputMapping in schema<br/>(even if user touched it)
Schema->>LLM: Schema with inputMapping included
LLM->>Merge: Returns params<br/>{workflowId, inputMapping: {query: "llm-value", limit: 10}}
Note over Merge: Deep merge inputMapping
Merge-->>Merge: User empty values + LLM values<br/>→ {query: "llm-value", limit: 10}
Merge->>Exec: Merged params
Note over Exec: Apply same deep merge logic
Exec-->>Exec: Filter empty user params<br/>Deep merge inputMapping again
Exec->>Tool: Final params with complete inputMapping
Loading

@greptile-appsgreptile-appsBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5 files reviewed, 5 comments

Edit Code Review Agent Settings | Greptile

Comment threadapps/sim/tools/params.ts
Comment threadapps/sim/tools/params.ts Outdated
Comment threadapps/sim/tools/params.ts Outdated
Comment threadapps/sim/tools/params.ts
Comment threadapps/sim/tools/params.ts
@waleedlatif1

Copy link
Copy Markdown
CollaboratorAuthor

@greptile

@greptile-appsgreptile-appsBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

4 files reviewed, 4 comments

Edit Code Review Agent Settings | Greptile

Comment threadapps/sim/tools/params.ts
Comment threadapps/sim/tools/params.ts
Comment threadapps/sim/tools/params.ts
Comment threadapps/sim/providers/utils.ts
@waleedlatif1
waleedlatif1 merged commit 1f5e8a4 into stagingJan 10, 2026
6 checks passed
@waleedlatif1
waleedlatif1 deleted the fix/workflow-as-a-tool branch January 10, 2026 01:13
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@waleedlatif1