Skip to content

feat(utils): add Jinja2-based instruction templating with use_jinja2 flag - #6580

Open
guptaishaan wants to merge 1 commit into
google:mainfrom
guptaishaan:fix/issue-2942-4271
Open

feat(utils): add Jinja2-based instruction templating with use_jinja2 flag#6580
guptaishaan wants to merge 1 commit into
google:mainfrom
guptaishaan:fix/issue-2942-4271

Conversation

@guptaishaan

Copy link
Copy Markdown
Contributor

The existing regex-based approach in inject_session_state does not support
control-flow constructs such as conditionals and loops. This change introduces
optional Jinja2 rendering as a first-class alternative.

What changed

  • The original substitution logic is extracted into a private helper
    _render_with_regex — behaviour is identical, no breaking changes.
  • A new private helper _render_with_jinja2 is added. It creates an
    async-capable jinja2.Environment, exposes all session state keys as
    template variables, and injects an async artifact(filename) callable so
    templates can load artifacts inline (e.g. {{ artifact('doc.txt') }}).
  • inject_session_state gains an optional use_jinja2: bool = False keyword
    argument. When True it delegates to _render_with_jinja2; when False
    (the default) it calls _render_with_regex, preserving full backward
    compatibility.
  • Unit tests are added for basic variable substitution, conditional blocks,
    for-loops, artifact loading, and the missing-artifact error path, all via
    use_jinja2=True.

Jinja2 is already a declared dependency of the package so no new requirements
are introduced.

Fixes #2942

…flag

The existing regex-based approach in `inject_session_state` does not support

Signed-off-by: Ishaan <ishaangupta0408@gmail.com>
@adk-bot adk-bot added the core [Component] This issue is related to the core interface and implementation label Aug 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core [Component] This issue is related to the core interface and implementation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feat]: Introduce Jinja2-based Instruction Templating with a Feature Flag

3 participants