Skip to content

templates

code_context_agent.templates

Jinja2 template loading and rendering for agent prompts.

This module provides a configured Jinja2 environment for rendering prompt templates. Templates are loaded from this directory using FileSystemLoader with StrictUndefined to catch missing variables.

render_prompt

render_prompt(template_name, **context)

Render a prompt template with the given context.

Parameters:

Name Type Description Default
template_name str

Template filename (e.g., "system.md.j2")

required
**context Any

Variables to pass to the template

{}

Returns:

Type Description
str

Rendered prompt string

Source code in src/code_context_agent/templates/__init__.py
def render_prompt(template_name: str, **context: Any) -> str:
    """Render a prompt template with the given context.

    Args:
        template_name: Template filename (e.g., "system.md.j2")
        **context: Variables to pass to the template

    Returns:
        Rendered prompt string
    """
    env = _get_environment()
    template = env.get_template(template_name)
    # fmt: off
    return template.render(**context)  # nosemgrep: python.flask.security.xss.audit.direct-use-of-jinja2.direct-use-of-jinja2  # noqa: E501

render_steering

render_steering(name, **context)

Render a steering template fragment.

Parameters:

Name Type Description Default
name str

Steering template name (e.g., "size_limits")

required
**context Any

Variables to pass to the template

{}

Returns:

Type Description
str

Rendered steering prompt fragment

Source code in src/code_context_agent/templates/__init__.py
def render_steering(name: str, **context: Any) -> str:
    """Render a steering template fragment.

    Args:
        name: Steering template name (e.g., "size_limits")
        **context: Variables to pass to the template

    Returns:
        Rendered steering prompt fragment
    """
    return render_prompt(f"steering/_{name}.md.j2", **context)