Skip to content

fix(engine): ensure workflow.input available for script/sub-workflow templates in explicit mode#119

Open
PolyphonyRequiem wants to merge 1 commit intomicrosoft:mainfrom
PolyphonyRequiem:fix/explicit-mode-script-inputs
Open

fix(engine): ensure workflow.input available for script/sub-workflow templates in explicit mode#119
PolyphonyRequiem wants to merge 1 commit intomicrosoft:mainfrom
PolyphonyRequiem:fix/explicit-mode-script-inputs

Conversation

@PolyphonyRequiem
Copy link
Copy Markdown
Member

Problem

In explicit context mode, build_for_agent() starts with workflow.input: {} and only populates entries declared in the agent's input: list. Script agents and sub-workflow input_mapping templates that reference {{ workflow.input.X }} without declaring it in their input: list get an empty dict, causing TemplateError at runtime.

Reproduction

workflow:
  name: explicit-script
  entry_point: detector
  context:
    mode: explicit
  input:
    work_item_id:
      type: number
      required: true
agents:
  - name: detector
    type: script
    command: pwsh
    args:
      - "-Command"
      - "Write-Output '{{ workflow.input.work_item_id }}'; exit 0"
    routes:
      - to: $end

conductor run explicit-script.yaml --input work_item_id=42

Expected: Script outputs 42
Actual: TemplateError: 'dict object' has no attribute 'work_item_id'

Root Cause

build_for_agent() in explicit mode starts with workflow.input: {} (line 168 in context.py) and only adds entries via _add_explicit_input() for items in the agent's input: list. Script agents typically don't declare workflow inputs in their input: list because their templates are rendered locally (no LLM prompt cost concern).

Fix

After build_for_agent(), inject the full workflow_inputs into the template context for script and workflow (sub-workflow) agent types. These are local template renders with no LLM cost, so workflow inputs should always be available regardless of context mode.

This preserves the explicit mode contract for LLM agents (no unnecessary token cost from undeclared inputs in prompts).

Changes

  • src/conductor/engine/workflow.py: Inject full workflow_inputs after build_for_agent() for script and workflow agent types (2 sites)
  • tests/test_engine/test_workflow.py: Regression test for explicit mode + script agent template rendering

Testing

  • 75 workflow engine tests pass (including new regression test)
  • Existing explicit mode tests unchanged (LLM agents still filter correctly)

…rkflow template rendering in explicit mode

In explicit context mode, build_for_agent() starts with workflow.input: {}
and only populates entries declared in the agent's input: list. Script agents
and sub-workflow input_mapping templates that reference workflow.input.X
without declaring it in their input: list get an empty dict, causing
TemplateError at runtime.

Script args and input_mapping are rendered locally (no LLM cost), so
workflow inputs must always be available for template resolution regardless
of context mode. This fix injects the full workflow_inputs into the template
context after build_for_agent() for script and workflow agent types.

Fixes: script agents in explicit mode failing with
  TemplateError: 'dict object' has no attribute '<field>'

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@codecov-commenter
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (main@dbcf20f). Learn more about missing BASE report.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #119   +/-   ##
=======================================
  Coverage        ?   84.86%           
=======================================
  Files           ?       53           
  Lines           ?     7167           
  Branches        ?        0           
=======================================
  Hits            ?     6082           
  Misses          ?     1085           
  Partials        ?        0           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

2 participants