fix(engine): ensure workflow.input available for script/sub-workflow templates in explicit mode#119
Open
PolyphonyRequiem wants to merge 1 commit intomicrosoft:mainfrom
Conversation
…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 Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
In
explicitcontext mode,build_for_agent()starts withworkflow.input: {}and only populates entries declared in the agent'sinput:list. Script agents and sub-workflowinput_mappingtemplates that reference{{ workflow.input.X }}without declaring it in theirinput:list get an empty dict, causingTemplateErrorat runtime.Reproduction
conductor run explicit-script.yaml --input work_item_id=42Expected: Script outputs
42Actual:
TemplateError: 'dict object' has no attribute 'work_item_id'Root Cause
build_for_agent()in explicit mode starts withworkflow.input: {}(line 168 in context.py) and only adds entries via_add_explicit_input()for items in the agent'sinput:list. Script agents typically don't declare workflow inputs in theirinput:list because their templates are rendered locally (no LLM prompt cost concern).Fix
After
build_for_agent(), inject the fullworkflow_inputsinto 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 fullworkflow_inputsafterbuild_for_agent()for script and workflow agent types (2 sites)tests/test_engine/test_workflow.py: Regression test for explicit mode + script agent template renderingTesting