Skip to content

fix(custom-blocks): render and execute custom blocks as agent tools#5811

Merged
TheodoreSpeaks merged 3 commits into
stagingfrom
fix/custom-block-agent-tool
Jul 21, 2026
Merged

fix(custom-blocks): render and execute custom blocks as agent tools#5811
TheodoreSpeaks merged 3 commits into
stagingfrom
fix/custom-block-agent-tool

Conversation

@TheodoreSpeaks

Copy link
Copy Markdown
Collaborator

Summary

  • Custom blocks added as Agent tools rendered generic "Workflow ID"/"Input Mapping" instead of their own inputs — they now render the block's real fields
  • They also couldn't execute: added an in-process custom_block_executor that reuses WorkflowBlockHandler, so authority (org-scoped owner identity, latest deployment, curated outputs, cost roll-up) matches the canvas path
  • Fixed getToolIdForOperation reading a stale block cache, which made "add tool" a silent no-op for async-hydrated custom blocks
  • Registered workflow_executor + custom_block_executor in the minimal dev registry so tool config resolves under SIM_DEV_MINIMAL_REGISTRY=1
  • Kept the executor/db graph out of the client bundle by moving execution into a server-only runner that executeTool dynamic-imports

Type of Change

  • Bug fix

Testing

bun run lint and bun run check:api-validation:strict pass, tsc --noEmit clean, and 139 tests pass across the touched suites (render branch, tool transform, execution runner). Not yet exercised in a running browser.

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

vercel Bot commented Jul 21, 2026

Copy link
Copy Markdown

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

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Jul 21, 2026 8:18pm

Request Review

@cursor

cursor Bot commented Jul 21, 2026

Copy link
Copy Markdown

PR Summary

Medium Risk
Touches agent tool transformation and in-process child workflow execution (authority, billing, recursion via call chain); changes are guarded by tests and server-only dynamic imports, but incorrect binding or merge behavior could affect tool availability or billing attribution.

Overview
Custom blocks (deploy-as-block) now work end-to-end as Agent tools instead of showing generic workflow-executor fields and failing at run time.

The tool panel surfaces each block’s real input sub-blocks (not workflowId / inputMapping), passes overlay-aware block config into getToolIdForOperation / getToolParametersConfig / getSubBlocksForToolInput so async-hydrated custom blocks can be added, and allows multiple custom blocks despite sharing workflow_executor as the underlying tool id.

Runtime routes custom blocks through a new deployed_block_executor tool (per-block wire ids like deployed_block_executor_custom_block_*, normalized for execution). transformBlockTool resolves org-scoped bindings via resolveCustomBlockToolBinding, builds id-keyed inputMapping schemas (shared assembleCustomBlockInputMapping), and skips tools that need required file inputs the model cannot fill. executeTool dynamic-imports runCustomBlockTool, which runs WorkflowBlockHandler in-process with server _context, inherited callChain, and partial child cost on failure—matching canvas authority without pulling executor/DB into the client bundle. Agent and Pi paths inject the binding resolver and use mergeToolParameters for preseeded vs LLM args.

Also registers workflow_executor and deployed_block_executor in the minimal dev tool registry.

Reviewed by Cursor Bugbot for commit 2db4e6c. Bugbot is set up for automated code reviews on this repo. Configure here.

Comment thread apps/sim/tools/index.ts
Comment thread apps/sim/executor/handlers/pi/sim-tools.ts
@greptile-apps

greptile-apps Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR makes custom blocks render and run as agent tools. The main changes are:

  • Renders each custom block’s deployed input fields in the tool editor.
  • Resolves custom-block bindings with workspace-scoped authority.
  • Executes custom blocks through a server-only workflow runner.
  • Preserves child workflow costs when execution fails.
  • Registers the workflow executors in the full and minimal registries.

Confidence Score: 5/5

This looks safe to merge.

  • Required file inputs are either supplied from preset values or the unusable tool is omitted.
  • Failed child runs retain their incurred cost in the tool response.
  • No blocking issues remain in the updated code.

Important Files Changed

Filename Overview
apps/sim/providers/utils.ts Builds field-based custom-block tool schemas and omits tools with unfilled required file inputs.
apps/sim/executor/handlers/workflow/custom-block-tool-runner.ts Runs custom blocks through the workflow handler and returns incurred child cost on failure.
apps/sim/executor/handlers/workflow/workflow-handler.ts Exports the existing child-cost aggregation helper for the custom-block runner.
apps/sim/executor/handlers/pi/sim-tools.ts Merges preset block values with model arguments while preserving the trusted execution context.
apps/sim/tools/index.ts Routes deployed-block executor calls to the dynamically imported server runner.
apps/sim/tools/params.ts Uses current custom-block definitions to render their real fields and resolve tool IDs.
apps/sim/lib/workflows/custom-blocks/operations.ts Resolves the authoritative custom-block workflow and its latest deployed input fields.

Sequence Diagram

%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
    participant Editor as Tool Editor
    participant Provider as Tool Transformer
    participant Resolver as Block Resolver
    participant Agent as Agent Runtime
    participant Runner as Block Runner
    participant Workflow as Workflow Handler

    Editor->>Provider: Custom block configuration
    Provider->>Resolver: Resolve workspace-scoped binding
    Resolver-->>Provider: Latest fields and required inputs
    Provider-->>Agent: Field schema and preset mapping
    Agent->>Runner: Tool call with merged inputs
    Runner->>Workflow: Execute custom block
    Workflow-->>Runner: Curated output and cost
    Runner-->>Agent: Tool response
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
    participant Editor as Tool Editor
    participant Provider as Tool Transformer
    participant Resolver as Block Resolver
    participant Agent as Agent Runtime
    participant Runner as Block Runner
    participant Workflow as Workflow Handler

    Editor->>Provider: Custom block configuration
    Provider->>Resolver: Resolve workspace-scoped binding
    Resolver-->>Provider: Latest fields and required inputs
    Provider-->>Agent: Field schema and preset mapping
    Agent->>Runner: Tool call with merged inputs
    Runner->>Workflow: Execute custom block
    Workflow-->>Runner: Curated output and cost
    Runner-->>Agent: Tool response
Loading

Reviews (3): Last reviewed commit: "fix(custom-blocks): move executor tool i..." | Re-trigger Greptile

Comment thread apps/sim/providers/utils.ts
Comment thread apps/sim/executor/handlers/workflow/custom-block-tool-runner.ts Outdated
Comment thread apps/sim/lib/workflows/custom-blocks/operations.ts
@TheodoreSpeaks

Copy link
Copy Markdown
Collaborator Author

@greptile

@TheodoreSpeaks

Copy link
Copy Markdown
Collaborator Author

@cursor review

Comment thread apps/sim/tools/index.ts
@TheodoreSpeaks

Copy link
Copy Markdown
Collaborator Author

@greptile

@TheodoreSpeaks

Copy link
Copy Markdown
Collaborator Author

@cursor review

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 2db4e6c. Configure here.

@TheodoreSpeaks
TheodoreSpeaks merged commit 407c729 into staging Jul 21, 2026
20 checks passed
@TheodoreSpeaks
TheodoreSpeaks deleted the fix/custom-block-agent-tool branch July 21, 2026 21:37
Sign up for free to 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