Skip to content

feat(engine): add workflow.dir, workflow.file, workflow.name template variables#121

Open
PolyphonyRequiem wants to merge 1 commit intomicrosoft:mainfrom
PolyphonyRequiem:feat/workflow-dir-template
Open

feat(engine): add workflow.dir, workflow.file, workflow.name template variables#121
PolyphonyRequiem wants to merge 1 commit intomicrosoft:mainfrom
PolyphonyRequiem:feat/workflow-dir-template

Conversation

@PolyphonyRequiem
Copy link
Copy Markdown
Member

Summary

Adds three new template variables available in all agent contexts:

  • {{ workflow.dir }} — absolute path to the workflow YAML's parent directory
  • {{ workflow.file }} — absolute path to the workflow YAML file itself
  • {{ workflow.name }} — workflow name from the YAML config

Motivation

Script agents specify script paths in args, but these resolve relative to CWD (where conductor run is invoked). When workflows live in a registry (e.g., ~/.conductor/registries/twig/), co-located scripts can't be found because CWD is the user's project directory, not the registry.

{{ workflow.dir }} solves this by letting scripts build paths relative to the workflow file:

agents:
  - name: detector
    type: script
    command: pwsh
    args:
      - "-File"
      - "{{ workflow.dir }}/scripts/detect-state.ps1"

This matches how !file tags already resolve prompt file paths relative to the workflow file.

Changes

  • src/conductor/engine/context.py: Add workflow_dir, workflow_file, workflow_name fields to WorkflowContext. Include them in build_for_agent() output under the workflow dict (all context modes).
  • src/conductor/engine/workflow.py: Set the new fields from workflow_path during WorkflowEngine.__init__().
  • tests/test_engine/test_context.py: Tests for metadata in accumulate/explicit modes, and empty-string omission.

Design decisions

  • Available in all context modes — workflow metadata is lightweight (3 strings) and fundamental. Unlike agent outputs, these shouldn't be filtered by explicit mode.
  • Empty strings omitted — when workflow_path is None (e.g., tests), the fields are empty strings and excluded from the context dict to avoid polluting templates.
  • No breaking changes — existing workflow.input behavior is unchanged. New fields are additive.

Testing

  • 139 context + workflow engine tests pass
  • New tests cover accumulate mode, explicit mode, and empty-metadata omission

… variables

Adds three new template variables available in all agent contexts:
- {{ workflow.dir }}  - absolute path to the workflow YAML's directory
- {{ workflow.file }} - absolute path to the workflow YAML file
- {{ workflow.name }} - workflow name from the YAML config

These enable script agents to resolve co-located scripts relative to
the workflow file rather than CWD, which is critical for registry-based
workflows where scripts live alongside the YAML in the registry directory.

Example:
  args:
    - -File
    - {{ workflow.dir }}/scripts/detect-state.ps1

Available in all context modes (accumulate, last_only, explicit).
Empty strings are omitted from context to avoid polluting templates.

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     #121   +/-   ##
=======================================
  Coverage        ?   84.88%           
=======================================
  Files           ?       53           
  Lines           ?     7178           
  Branches        ?        0           
=======================================
  Hits            ?     6093           
  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