# =============================================================================
# LLM Provider Configuration
# =============================================================================
{% if primary_provider == "openrouter" %}
# OpenRouter API Key (https://openrouter.ai/keys)
OPENROUTER_API_KEY=sk-or-v1-...
{% elif primary_provider == "anthropic" %}
# Anthropic API Key (https://console.anthropic.com/settings/keys)
ANTHROPIC_API_KEY=sk-ant-api03-...
{% elif primary_provider == "azure" %}
# Azure OpenAI Configuration
AZURE_API_KEY=...
AZURE_API_BASE=https://your-resource.openai.azure.com/
AZURE_API_VERSION=2024-02-15-preview
{% elif primary_provider == "google" or primary_provider == "gemini" %}
# Google Gemini API Key (https://aistudio.google.com/app/apikey)
GEMINI_API_KEY=...
{% elif primary_provider == "bedrock" %}
# AWS Bedrock Configuration
AWS_ACCESS_KEY_ID=...
AWS_SECRET_ACCESS_KEY=...
AWS_REGION_NAME=us-east-1
{% else %}
# OpenAI API Key (https://platform.openai.com/api-keys)
OPENAI_API_KEY=sk-proj-...
{% endif %}

# LLM Model (configured from spec: {{ primary_model }})
LLM_MODEL={{ primary_model }}
# SUMMARIZER_MODEL=
# REFLECTION_MODEL=

# =============================================================================
# Feature Flags
# =============================================================================
MEMORY_ENABLED={{ memory_enabled }}
SUMMARIZER_ENABLED={{ summarizer_enabled }}
REFLECTION_ENABLED={{ reflection_enabled }}

# =============================================================================
# Reflection Settings (if enabled)
# =============================================================================
# REFLECTION_QUALITY_THRESHOLD=0.8
# REFLECTION_MAX_REVISIONS=2

# =============================================================================
# Service URLs
# =============================================================================
MEMORY_BASE_URL={{ memory_base_url|default("http://localhost:8000", true) }}
RAG_SERVER_BASE_URL={{ rag_server_base_url|default("http://localhost:8081", true) }}
WAYFINDER_BASE_URL={{ wayfinder_base_url|default("http://localhost:8082", true) }}

# =============================================================================
# Planner Settings
# =============================================================================
PLANNER_MAX_ITERS={{ planner_max_iters }}
PLANNER_HOP_BUDGET={{ planner_hop_budget }}
PLANNER_ABSOLUTE_MAX_PARALLEL={{ planner_absolute_max_parallel }}
PLANNER_STREAM_FINAL_RESPONSE={{ planner_stream_final_response }}
PLANNER_MULTI_ACTION_SEQUENTIAL={{ planner_multi_action_sequential }}
PLANNER_MULTI_ACTION_READ_ONLY_ONLY={{ planner_multi_action_read_only_only }}
PLANNER_MULTI_ACTION_MAX_TOOLS={{ planner_multi_action_max_tools }}

# =============================================================================
# Artifact Store (binary/large text)
# =============================================================================
ARTIFACT_STORE_ENABLED={{ artifact_store_enabled }}
ARTIFACT_STORE_TTL_SECONDS={{ artifact_store_ttl_seconds }}
ARTIFACT_STORE_MAX_ARTIFACT_BYTES={{ artifact_store_max_artifact_bytes }}
ARTIFACT_STORE_MAX_SESSION_BYTES={{ artifact_store_max_session_bytes }}
ARTIFACT_STORE_MAX_TRACE_BYTES={{ artifact_store_max_trace_bytes }}
ARTIFACT_STORE_MAX_ARTIFACTS_PER_TRACE={{ artifact_store_max_artifacts_per_trace }}
ARTIFACT_STORE_MAX_ARTIFACTS_PER_SESSION={{ artifact_store_max_artifacts_per_session }}
ARTIFACT_STORE_CLEANUP_STRATEGY={{ artifact_store_cleanup_strategy }}

# =============================================================================
# Rich Output (Component Artifacts)
# =============================================================================
RICH_OUTPUT_ENABLED={{ rich_output_enabled }}
# Comma-separated list of component names (e.g., "markdown,json,echarts")
RICH_OUTPUT_ALLOWLIST={{ rich_output_allowlist }}
RICH_OUTPUT_INCLUDE_PROMPT_CATALOG={{ rich_output_include_prompt_catalog }}
RICH_OUTPUT_INCLUDE_PROMPT_EXAMPLES={{ rich_output_include_prompt_examples }}
RICH_OUTPUT_MAX_PAYLOAD_BYTES={{ rich_output_max_payload_bytes }}
RICH_OUTPUT_MAX_TOTAL_BYTES={{ rich_output_max_total_bytes }}

# =============================================================================
# Built-in Short-Term Memory (ReactPlanner)
# =============================================================================
SHORT_TERM_MEMORY_ENABLED={{ short_term_memory_enabled }}
SHORT_TERM_MEMORY_STRATEGY={{ short_term_memory_strategy }}
SHORT_TERM_MEMORY_FULL_ZONE_TURNS={{ short_term_memory_full_zone_turns }}
SHORT_TERM_MEMORY_SUMMARY_MAX_TOKENS={{ short_term_memory_summary_max_tokens }}
SHORT_TERM_MEMORY_TOTAL_MAX_TOKENS={{ short_term_memory_total_max_tokens }}
SHORT_TERM_MEMORY_OVERFLOW_POLICY={{ short_term_memory_overflow_policy }}
# Key paths used to extract identifiers from tool_context (advanced; most apps keep defaults)
# SHORT_TERM_MEMORY_TENANT_KEY={{ short_term_memory_tenant_key|default("tenant_id", true) }}
# SHORT_TERM_MEMORY_USER_KEY={{ short_term_memory_user_key|default("user_id", true) }}
# SHORT_TERM_MEMORY_SESSION_KEY={{ short_term_memory_session_key|default("session_id", true) }}
# SHORT_TERM_MEMORY_REQUIRE_EXPLICIT_KEY={{ short_term_memory_require_explicit_key|default("true", true) }}
SHORT_TERM_MEMORY_INCLUDE_TRAJECTORY_DIGEST={{ short_term_memory_include_trajectory_digest }}
# SHORT_TERM_MEMORY_SUMMARIZER_MODEL=
SHORT_TERM_MEMORY_RECOVERY_BACKLOG_LIMIT={{ short_term_memory_recovery_backlog_limit }}
SHORT_TERM_MEMORY_RETRY_ATTEMPTS={{ short_term_memory_retry_attempts }}
SHORT_TERM_MEMORY_RETRY_BACKOFF_BASE_S={{ short_term_memory_retry_backoff_base_s }}
SHORT_TERM_MEMORY_DEGRADED_RETRY_INTERVAL_S={{ short_term_memory_degraded_retry_interval_s }}

{% if with_background_tasks %}
# =============================================================================
# Background Tasks (Subagents)
# =============================================================================
BACKGROUND_TASKS_ENABLED={{ background_tasks_enabled }}
BACKGROUND_TASKS_ALLOW_TOOL_BACKGROUND={{ background_tasks_allow_tool_background }}
BACKGROUND_TASKS_DEFAULT_MODE={{ background_tasks_default_mode }}
BACKGROUND_TASKS_DEFAULT_MERGE_STRATEGY={{ background_tasks_default_merge_strategy }}
BACKGROUND_TASKS_CONTEXT_DEPTH={{ background_tasks_context_depth }}
BACKGROUND_TASKS_PROPAGATE_ON_CANCEL={{ background_tasks_propagate_on_cancel }}
BACKGROUND_TASKS_SPAWN_REQUIRES_CONFIRMATION={{ background_tasks_spawn_requires_confirmation }}
BACKGROUND_TASKS_INCLUDE_PROMPT_GUIDANCE={{ background_tasks_include_prompt_guidance }}
BACKGROUND_TASKS_MAX_CONCURRENT_TASKS={{ background_tasks_max_concurrent_tasks }}
BACKGROUND_TASKS_MAX_TASKS_PER_SESSION={{ background_tasks_max_tasks_per_session }}
BACKGROUND_TASKS_TASK_TIMEOUT_S={{ background_tasks_task_timeout_s }}
BACKGROUND_TASKS_MAX_PENDING_STEERING={{ background_tasks_max_pending_steering }}

{% endif %}

# =============================================================================
# External Tools
# =============================================================================
{% if external_env_vars %}
# Environment variables required by external tools (MCP/UTCP)
{% for var in external_env_vars %}
{{ var }}=
{% endfor %}
{% else %}
# No external tool environment variables defined in spec
{% endif %}
