Repository navigation
Conversation
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.
- 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.
NA-Wen
left a comment
There was a problem hiding this comment.
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 |
|
Any updates on it? |
|
Hi @NA-Wen, been a while but this PR should be ready. Thank you |
…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.
|
Hi @NA-Wen, I've pushed the README update: a link to the node docs under "Relevant reference documentation", plus a new While I was in there I also:
Full suite: 280 passed, 1 skipped. If you meant a different README change, let me know and I'll update it. |

Add Jinja2 template node and template edge processor for flexible message formatting in multi-agent workflows.
New
templatenode type withTemplateNodeExecutor: formats the latest input message with a sandboxed Jinja2 template; context variable{{ input }}New
templateedge processor (TemplateEdgeProcessorConfig) for Jinja2-based payload transformation on edges ({{ input }},{{ extracted }})Custom
fromjson/tojsonfilters; strict undefined-variable checks that list the available context keysConfig, executor, and registration in
builtin_nodes.pyDocs:
docs/user_guide/en/nodes/template.md, node cheatsheet row and edge processor bullet inworkflow_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 sourcesDemo:
yaml_instance/demo_simple_template.yaml