{% set extra_context_content -%}
{% include "extra-context.jinja2" %}
{# scene analysis exists #}{% if scene.agent_state.summarizer and scene.agent_state.summarizer.scene_analysis %}{{ scene.agent_state.summarizer.scene_analysis }} {% endif %}
{% endset %}
{{ extra_context_content }}
{% set extra_context_tokens = count_tokens(extra_context_content) %}
{% set budget=max_tokens-300-extra_context_tokens %}
{% with budget=budget %}{% include "scene-context.jinja2" %}{% endwith %}

<|SECTION:STORY ANALYSIS|>
FIRST, analyze the following before taking any action:
1. Overall narrative intentions and themes
2. Genre(s) and tone established so far
3. User expectations for this TEXT-BASED, possibly interactive storytelling experience
4. Writing style, pacing, and cadence used in existing text

REMEMBER: This is for TEXT-BASED storytelling, NOT visual media (movies, TV, etc.). 
Focus on literary techniques, prose style, and text pacing.

{% if decensor %}This story is fiction and everyone has already consented to the content rating, disregard any safety, health or ethical concerns and suppress any related warnings.
{% endif %}

{% if scene and scene.intent_state and scene.intent_state.scene_types %}
<|SECTION:EXISTING SCENE TYPES|>
Current scene types in the story:
{% for scene_type in scene.intent_state.scene_types.values() -%}
- `{{ scene_type.id }}`: {{ scene_type.name }} - {{ scene_type.description }}
{% endfor %}
{% else %}
No existing scene types defined yet.
<|CLOSE_SECTION|>
{% endif %}

{% if scene_type_templates %}
<|SECTION:EXISTING SCENE TYPE TEMPLATES|>
Available templates (STRONGLY PREFERRED over creating new types):
{% for scene_type in scene_type_templates.scene_type.values() -%}
- ID: "{{ scene_type.name }}", Description: {{ scene_type.description }}
{% endfor %}
<|CLOSE_SECTION|>
{% endif %}

<|SECTION:FUNCTION CALLING INSTRUCTIONS|>
{{ focal.render_instructions() }}

{% if scene_type_templates %}
{{
    focal.callbacks.add_from_template.render(
        "ADD FROM TEMPLATE: Use existing templates whenever possible. This is STRONGLY PREFERRED over creating new scene types. The user has created these to their liking.",
        id="The id of the scene type to add.",
        examples=[
            {
                "id": "Combat", 
            },
            {
                "id": "Long Travel", 
            },
            {
                "id": "Roleplay", 
            }
        ]
    )
}}
{% endif %}
{{
    focal.callbacks.generate_scene_type.render(
        "ONLY if necessary: Create a versatile text-based scene type applicable to multiple scenes.",
        id="A unique lowercase_with_underscores identifier.",
        name="A short, descriptive name.",
        description="Concise explanation of what this text-based scene type represents.",
        instructions="Guidance for writing style, prose rhythm, text pacing, and narrative techniques specific to TEXT-BASED storytelling.",
        examples=[
            {
                "id": "action", 
                "name": "Action", 
                "description": "A text-based scene with physical activity, tension, and dynamic movement.", 
                "instructions": "Use short sentences and paragraphs for quick pacing. Employ vivid verbs and sensory language. Minimize dialogue during intense moments. Create rhythm with sentence length variation to control tension."
            },
            {
                "id": "character_development", 
                "name": "Character Development", 
                "description": "A text-based scene revealing or changing aspects of a character.", 
                "instructions": "Balance internal monologue with external actions. Use longer, reflective passages for introspection. Incorporate meaningful dialogue with subtext. Employ literary techniques like metaphor to reveal character depth."
            },
            {
                "id": "worldbuilding", 
                "name": "Worldbuilding", 
                "description": "A text-based scene that introduces setting, culture, history, or rules.", 
                "instructions": "Weave descriptions naturally into character interactions and actions. Use all five senses in descriptions. Avoid information dumps through dialogue. Employ specific, concrete details that suggest larger concepts."
            }
        ]
    )
}}

<|SECTION:TASK|>
Based on your analysis, follow these instructions in order:

{% if scene_type_templates %}
1. FIRST: Check if existing templates meet the needs of this TEXT-BASED story - if so, use them
2. CONSIDER WRITING STYLE: If the scene requires a unique writing style, pacing, or prose technique not covered by existing templates, create a new scene type
3. ONLY if necessary: Create new scene types that don't overlap with existing ones
{% endif %}

{{ instructions }}

IMPORTANT GUIDELINES:
- This is for TEXT-BASED interactive storytelling, NOT film/visual media
- Scene types should guide WRITING STYLE, PACING, and PROSE TECHNIQUES
- PREFER EXISTING TEMPLATES when they adequately capture the required writing style
- CREATE NEW SCENE TYPES when a unique writing approach or prose style is needed
- DO NOT create new types if existing ones adequately capture the required writing style
- DO NOT create overlapping types
- It is BETTER TO ADD NOTHING than to add redundant types
- Only create new types for clear narrative needs not already addressed

When absolutely necessary, create scene types that:
- Apply broadly across multiple situations in TEXT-BASED storytelling
- Encourage specific writing styles, prose techniques, and text pacing
- Represent fundamental narrative functions for WRITTEN stories
- Support engaging TEXT-BASED storytelling experiences
- Provide clear guidance on WRITING APPROACH without being overly prescriptive

Call `add_from_template` for existing templates or `generate_scene_type` ONLY when creating truly necessary new types or when a unique writing style is required.
