Skip to content

Feature/add template edge processor - #560

Open
LaansDole wants to merge 64 commits into
OpenBMB:mainfrom
LaansDole:feature/add-template-edge-processor
Open

LaansDole wants to merge 64 commits into
OpenBMB:mainfrom
LaansDole:feature/add-template-edge-processor

Conversation

@LaansDole

@LaansDole LaansDole commented Mar 3, 2026 •

Copy link
Copy Markdown
Contributor
  • Add Jinja2 template node and template edge processor for flexible message formatting in multi-agent workflows.

  • New template node type with TemplateNodeExecutor: formats the latest input message with a sandboxed Jinja2 template; context variable {{ input }}

  • New template edge processor (TemplateEdgeProcessorConfig) for Jinja2-based payload transformation on edges ({{ input }}, {{ extracted }})

  • Custom fromjson/tojson filters; strict undefined-variable checks that list the available context keys

  • Config, executor, and registration in builtin_nodes.py

  • Docs: docs/user_guide/en/nodes/template.md, node cheatsheet row and edge processor bullet in workflow_authoring.md, README link under "Relevant reference documentation"

  • Tests: tests/test_template_node.py (node + edge processor rendering, undefined-variable error), run offline with literal sources

  • Demo: yaml_instance/demo_simple_template.yaml

LaansDole and others added 30 commits February 8, 2026 22:02
Implement template edge processor for transforming edge payloads using Jinja2 templates.

Changes:
- Add jinja2>=3.1.0 dependency to pyproject.toml
- Create TemplateEdgeProcessorConfig in entity/configs/edge/edge_processor.py
- Implement TemplateEdgePayloadProcessor with sandboxed Jinja2 environment
- Register 'template' processor type in builtin_types registry
- Add comprehensive test suite (17 tests, 100% pass rate)
- Include template processor example in yaml_template/

Features:
- Variable interpolation: input, environment, extracted
- Custom filters: fromjson, tojson
- Full Jinja2 control structures (if/for/set)
- Safe execution with sandboxed environment
- Strict undefined variable checking
- Descriptive error messages

This enables users to separate data formatting logic from LLM prompts,
improving maintainability and reducing hallucination in complex workflows
like the hospital simulation report generation.

Fixes 14 existing template processor edges in simulation_hospital.yaml
that were previously failing silently.
Add template node type that formats input messages using Jinja2 templates
and emits rendered output directly to logs (without LLM interaction).

Implementation:
- entity/configs/node/template.py: Configuration schema with template field
- runtime/node/executor/template_executor.py: Executor with sandboxed Jinja2
- runtime/node/builtin_nodes.py: Register template node type
- yaml_instance/template_demo.yaml: Enhanced demo showing both edge processors and template nodes

Features:
- Sandboxed Jinja2 environment with StrictUndefined mode
- Custom filters: fromjson, tojson (plus all standard Jinja2 filters)
- Template context: input (latest message), environment (execution vars)
- Error handling with detailed logging
- Supports conditionals, loops, string operations

Use case:
- Format structured data (JSON) into human-readable reports
- Create discharge summaries, dashboards, formatted logs
- Deterministic formatting without AI reasoning
Fix template node error where text_content was accessed as a property
instead of being called as a method, causing JSON decode error.

Error was: 'the JSON object must be str, bytes or bytearray, not method'

Changed: latest_input.text_content → latest_input.text_content()
Replace StatusReport agent node with a template node to prevent
LLM from adding unwanted commentary to the status message.

Issue: StatusReport agent was responding with COVID-19 advice instead
of simply acknowledging the formatted status from the edge processor.

Solution: Convert to template node that wraps the input in a clean
acknowledgment format without AI interpretation.

This demonstrates another template node use case: formatting
acknowledgments/wrappers around already-formatted data.
Add template node type that formats input messages using Jinja2 templates
and emits rendered output directly to logs (without LLM interaction).

Implementation:
- entity/configs/node/template.py: Configuration schema with template field
- runtime/node/executor/template_executor.py: Executor with sandboxed Jinja2
- runtime/node/builtin_nodes.py: Register template node type
- yaml_instance/template_demo.yaml: Enhanced demo showing both edge processors and template nodes

Features:
- Sandboxed Jinja2 environment with StrictUndefined mode
- Custom filters: fromjson, tojson (plus all standard Jinja2 filters)
- Template context: input (latest message), environment (execution vars)
- Error handling with detailed logging
- Supports conditionals, loops, string operations

Use case:
- Format structured data (JSON) into human-readable reports
- Create discharge summaries, dashboards, formatted logs
- Deterministic formatting without AI reasoning
Fix template node error where text_content was accessed as a property
instead of being called as a method, causing JSON decode error.

Error was: 'the JSON object must be str, bytes or bytearray, not method'

Changed: latest_input.text_content → latest_input.text_content()
Replace StatusReport agent node with a template node to prevent
LLM from adding unwanted commentary to the status message.

Issue: StatusReport agent was responding with COVID-19 advice instead
of simply acknowledging the formatted status from the edge processor.

Solution: Convert to template node that wraps the input in a clean
acknowledgment format without AI interpretation.

This demonstrates another template node use case: formatting
acknowledgments/wrappers around already-formatted data.
LaansDole and others added 12 commits February 12, 2026 22:35
- Remove invalid 'version' field
- Restructure to match DevAll YAML schema (graph at top level)
- Move start/end nodes to end of graph block
- Validation now passes: 'Workflow OK. Design is valid.'
Key fixes:
- Add proper trigger edges: Critic -> Timer Gate with trigger=true
- Add feedback loop: Timer Gate -> Writer with trigger=true
- Remove incorrect Writer -> Critic -> Timer Gate -> Writer pattern
- Follow ChatDev_v1 loop pattern: input -> gate (trigger) -> gate -> output (trigger)
- Start both branches simultaneously in start nodes

This ensures the timer gates are properly triggered and loops execute correctly.
@LaansDole

Copy link
Copy Markdown
Contributor Author

It will look something like

chatdev-template

@NA-Wen NA-Wen left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution! 🙏
Everything looks great. I have a small suggestion regarding the README update—once that’s included, this PR will be ready to merge.

@LaansDole

Copy link
Copy Markdown
Contributor Author

Thanks for the contribution! 🙏 Everything looks great. I have a small suggestion regarding the README update—once that’s included, this PR will be ready to merge.

Hi @NA-Wen, please let me know your suggestion for README, and I will update it rightaway

@LaansDole
LaansDole requested a review from NA-Wen March 11, 2026 15:41
@LaansDole

Copy link
Copy Markdown
Contributor Author

Any updates on it?

@LaansDole

Copy link
Copy Markdown
Contributor Author

Hi @NA-Wen, been a while but this PR should be ready. Thank you

LaansDole and others added 3 commits July 25, 2026 11:45
…ntext; add docs and tests

- builtin_nodes: the template node reused loop_timer's summary text.
- Remove the {{ environment }} context key: ExecutionContext has no such
  attribute, so it was always {} (and exposing os.environ would leak API keys).
- docs: nodes/template.md, cheatsheet row, template edge processor bullet,
  README node reference link (review request).
- tests: node + edge processor rendering, undefined-variable error.
@LaansDole

Copy link
Copy Markdown
Contributor Author

Hi @NA-Wen, I've pushed the README update: a link to the node docs under "Relevant reference documentation", plus a new docs/user_guide/en/nodes/template.md and a row in the node cheatsheet.

While I was in there I also:

  • fixed the template node's registration summary (it reused the loop_timer text)
  • removed the {{ environment }} context variable, which was always empty
  • added offline tests in tests/test_template_node.py
  • merged the latest main

Full suite: 280 passed, 1 skipped. If you meant a different README change, let me know and I'll update it.

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