Skip to content

Commit 901d142

Browse files
committed
fix(workflows): allow 'tmp' in for_each and expose metadata.depth for templates
Add 'tmp' as an allowed per-iteration key in the workflow schema, move where exec context exposes depth so templates can access it via metadata.depth, and update workflow-creator templates to reference metadata.depth and include a workspace path. These changes fix variable scoping in templates and enable use of temporary loop variables.
1 parent ed66fc3 commit 901d142

4 files changed

Lines changed: 11 additions & 10 deletions

File tree

src/workflows_mcp/engine/schema.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -834,7 +834,7 @@ def validate_string_value(value: str, context: str, allow_each: bool = False) ->
834834
f"{context}: Invalid variable reference '{{{{{var_path}}}}}'. "
835835
f"Unknown namespace '{parts[0]}'. "
836836
f"Valid namespaces: 'inputs', 'blocks', 'metadata', 'secrets', "
837-
f"'each' (for_each blocks only)"
837+
f"'tmp', 'each' (for_each blocks only)"
838838
)
839839

840840
def check_dict_values(obj: Any, path: str, allow_each: bool = False) -> None:

src/workflows_mcp/engine/workflow_runner.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1038,6 +1038,7 @@ def _create_initial_execution_context(
10381038
"started_at": workflow_start_time,
10391039
"execution_id": execution_id,
10401040
"scratch_dir": str(scratch_dir),
1041+
"depth": exec_context.depth,
10411042
}
10421043

10431044
if context:
@@ -1108,7 +1109,6 @@ def _execution_to_dict(self, exec_context: Execution) -> dict[str, Any]:
11081109
"metadata": metadata,
11091110
"blocks": blocks,
11101111
"tmp": str(exec_context.scratch_dir) if exec_context.scratch_dir else "",
1111-
"depth": exec_context.depth,
11121112
}
11131113

11141114
async def _evaluate_condition(self, condition: str, exec_context: Execution) -> bool:

src/workflows_mcp/templates/agents/workflow-creator/layer2/design-approval-loop.yaml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ blocks:
8383
{{inputs.examples}}
8484
</examples>
8585
86-
{% if depth == 1 %}
86+
{% if metadata.depth == 1 %}
8787
# Design New Workflow
8888
8989
Create a Mermaid flowchart diagram for this workflow:
@@ -104,7 +104,7 @@ blocks:
104104
105105
Generate the initial design now.
106106
{% else %}
107-
# Refine Workflow Design (Iteration {{depth}})
107+
# Refine Workflow Design (Iteration {{metadata.depth}})
108108
109109
## Current Design
110110
<previous_diagram>
@@ -175,14 +175,14 @@ blocks:
175175
type: CreateFile
176176
depends_on: [generate_diagram]
177177
inputs:
178-
path: "{{inputs.workspace}}/diagram-{{depth}}.html"
178+
path: "{{inputs.workspace}}/diagram-{{metadata.depth}}.html"
179179
create_parents: true
180180
overwrite: true
181181
content: |
182182
<!DOCTYPE html>
183183
<html>
184184
<head>
185-
<title>Workflow Design - Iteration {{depth}}</title>
185+
<title>Workflow Design - Iteration {{metadata.depth}}</title>
186186
<script type="module">
187187
import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid@11/dist/mermaid.esm.min.mjs';
188188
mermaid.initialize({ startOnLoad: true, theme: 'default' });
@@ -196,7 +196,7 @@ blocks:
196196
</head>
197197
<body>
198198
<h1>Workflow Design</h1>
199-
<p class="subtitle">Iteration {{depth}}</p>
199+
<p class="subtitle">Iteration {{metadata.depth}}</p>
200200
<div class="mermaid">
201201
{{blocks.generate_diagram.outputs.response.mermaid_diagram}}
202202
</div>
@@ -209,10 +209,10 @@ blocks:
209209
depends_on: [create_diagram_viewer]
210210
inputs:
211211
prompt: |
212-
# WORKFLOW DESIGN - ITERATION {{depth}}
213-
{% if depth > 10 %}
212+
# WORKFLOW DESIGN - ITERATION {{metadata.depth}}
213+
{% if metadata.depth > 10 %}
214214
215-
⚠️ You've made {{depth}} refinements. This is getting expensive. Max depth is 50.
215+
⚠️ You've made {{metadata.depth}} refinements. This is getting expensive. Max depth is 50.
216216
{% endif %}
217217
218218
## Diagram

src/workflows_mcp/templates/agents/workflow-creator/workflow-creator.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ blocks:
214214
requirements: "{{inputs.workspace}}/requirements.json"
215215
executor_docs: "{{blocks.bootstrap_context.outputs.executor_docs}}"
216216
examples: "{{blocks.bootstrap_context.outputs.examples}}"
217+
workspace: "{{inputs.workspace}}/design-approval"
217218

218219
- id: check_design_approval
219220
depends_on: [design_approval]

0 commit comments

Comments
 (0)