Skip to content

Add automatic expression wrapping for template conditionals in agentic workflows#1245

Merged
pelikhan merged 7 commits intomainfrom
copilot/fix-template-expression-handling
Oct 6, 2025
Merged

Add automatic expression wrapping for template conditionals in agentic workflows#1245
pelikhan merged 7 commits intomainfrom
copilot/fix-template-expression-handling

Conversation

Copy link
Contributor

Copilot AI commented Oct 5, 2025

  • Understand the repository structure and current template rendering implementation
  • Identify the issue: template conditionals with GitHub expressions need wrapping
  • Create a function to detect and wrap expressions in template conditionals
  • Add comprehensive tests for the expression wrapping functionality
  • Integrate the wrapping function into the compilation process
  • Test the changes with real-world examples
  • Create integration test for end-to-end workflow compilation
  • Run make agent-finish for complete validation
  • Verify all tests pass and linting is clean
  • Simplify implementation: always wrap expressions not starting with ${{
  • Update documentation and instructions (complete)

Summary

Successfully implemented and documented automatic expression wrapping for template conditionals in agentic workflows.

Complete Documentation Updates

Both user-facing documentation and internal instructions now fully document the feature:

  1. Template Rendering Docs (docs/src/content/docs/reference/template-rendering.md):

    • ✅ "Automatic Expression Wrapping" section
    • ✅ Updated all examples to natural syntax
    • ✅ Section on manual wrapping for complex expressions
    • ✅ Updated "How It Works" process flow
  2. Instructions File (.github/instructions/github-agentic-workflows.instructions.md):

    • ✅ Comprehensive "Template Rendering" section
    • ✅ Event-based conditional examples
    • ✅ Workflow input conditional examples
    • ✅ Complex expression documentation
    • ✅ Truthy/falsy evaluation rules
    • ✅ Link to full documentation

Implementation Summary

Simplified approach: Always wrap expressions in {{#if}} that don't start with ${{

Examples:

{{#if github.event.issue.number}}  → {{#if ${{ github.event.issue.number }} }}
{{#if true}}                        → {{#if ${{ true }} }}
{{#if ${{ github.actor }} }}        → {{#if ${{ github.actor }} }} (no change)

All tests passing. Documentation comprehensive and ready for users.

Original prompt

The compiler should detect template regions in prompts that use expressions and wrap the expressions in ${{ }}

So if this is found

{{#if github....}}

Rewrite to

{{#if ${{ github... }} }}

So that the expression gets evaluated by the github actions workflow.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI and others added 2 commits October 5, 2025 20:47
- Create wrapExpressionsInTemplateConditionals function to detect and wrap GitHub expressions in {{#if}} blocks
- Add shouldWrapExpression helper to identify expressions that need wrapping
- Integrate wrapping into compilation process before prompt generation
- Add comprehensive tests for expression wrapping functionality
- Update existing template rendering test to verify wrapped expressions

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
- Add end-to-end integration test for real-world workflow compilation
- Add test for already-wrapped expressions to prevent double-wrapping
- Add test for mixed expressions and literals
- Verify correct wrapping behavior in compiled output
- All tests passing

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix template expression handling in prompts Add automatic expression wrapping for template conditionals in agentic workflows Oct 5, 2025
Copilot AI requested a review from pelikhan October 5, 2025 20:56
@pelikhan
Copy link
Contributor

pelikhan commented Oct 5, 2025

@copilot make it simpler: always wrap expressions that don't start with ${{ in {{#if

…th ${{

- Remove shouldWrapExpression function and complex prefix checking
- Always wrap any expression in {{#if ...}} that doesn't start with ${{
- Simpler logic: just check if expression starts with "${{" to avoid double-wrapping
- Update all tests to reflect new behavior where literals are also wrapped
- Remove constants import that is no longer needed

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Oct 5, 2025

@copilot make it simpler: always wrap expressions that don't start with ${{ in {{#if

Done! Simplified to always wrap expressions that don't start with ${{ in commit 71b5eeb.

The new logic is much cleaner:

  • No more complex prefix checking (github., needs., steps., env.)
  • No more shouldWrapExpression function
  • Just one simple check: if it doesn't start with ${{, wrap it
  • All tests updated and passing

…c workflows

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
@pelikhan
Copy link
Contributor

pelikhan commented Oct 6, 2025

@copilot update docs and instructions

- Add "Automatic Expression Wrapping" section to template-rendering.md
- Update all examples to show natural syntax without manual ${{ }} wrapping
- Add "Template Rendering" section to github-agentic-workflows.instructions.md
- Include examples of event-based conditionals and workflow inputs
- Document when to use manual wrapping for complex expressions
- Update compilation process docs to mention expression wrapping

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Oct 6, 2025

@copilot update docs and instructions

Done! Updated documentation and instructions in commit d9ab8e7.

Documentation updates:

  • Added "Automatic Expression Wrapping" section to template-rendering.md
  • Updated all examples to show natural syntax (no manual ${{ }} needed)
  • Added comprehensive "Template Rendering" section to instructions file
  • Documented when to use manual wrapping for complex expressions
  • Included examples for event-based conditionals and workflow inputs

- Add comprehensive "Template Rendering" section with automatic wrapping details
- Include event-based conditional examples
- Document workflow input conditionals
- Explain complex expression handling
- Add truthy/falsy evaluation rules
- Update compilation process to mention template expression wrapping

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
@pelikhan pelikhan marked this pull request as ready for review October 6, 2025 00:30
@pelikhan pelikhan merged commit 87a19cc into main Oct 6, 2025
13 checks passed
@pelikhan pelikhan deleted the copilot/fix-template-expression-handling branch October 6, 2025 00:32
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