Skip to content

Feature/add template edge processor#560

Open
LaansDole wants to merge 53 commits intoOpenBMB:mainfrom
LaansDole:feature/add-template-edge-processor
Open

Feature/add template edge processor#560
LaansDole wants to merge 53 commits intoOpenBMB:mainfrom
LaansDole:feature/add-template-edge-processor

Conversation

@LaansDole
Copy link
Contributor

@LaansDole LaansDole commented Mar 3, 2026

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

  • New template node type with TemplateNodeExecutor — formats input messages using Jinja2 templates in a sandboxed environment with {{ input }} and {{ environment }} context variables

  • New TemplateEdgeProcessorConfig for Jinja2-based payload transformation on edges

  • Custom fromjson/tojson filters; strict undefined-variable checks

  • Config, executor, and registration in builtin_nodes.py

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 23 commits February 12, 2026 22:31
- Add LoopTimerConfig with duration units support (seconds/minutes/hours)
- Implement LoopTimerNodeExecutor with standard and passthrough modes
- Register loop_timer node type in builtin_nodes.py
- Update documentation (execution_logic.md, YAML_FORMAT_QUICK_GUIDE.md)
- Add demo workflows for both modes

Closes: add-loop-timer change proposal
- Merge demo_loop_timer.yaml and demo_loop_timer_passthrough.yaml into single comprehensive demo
- Create dual-branch workflow demonstrating both standard and passthrough modes side-by-side
- Increase duration from 5 seconds to 2 minutes for better demonstration
- Update YAML_FORMAT_QUICK_GUIDE.md with detailed mode explanations and demo reference
- Update tasks.md in add-loop-timer proposal to reflect demo improvements
- Remove duplicate demo_loop_timer_passthrough.yaml file
- 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
Contributor Author

It will look something like

chatdev-template

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.

1 participant