# =============================================================================
# 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 }}

# =============================================================================
# Tool Search + Deferred Activation
# =============================================================================
TOOL_SEARCH_ENABLED={{ tool_search_enabled }}
TOOL_SEARCH_CACHE_DIR={{ tool_search_cache_dir }}
TOOL_SEARCH_DEFAULT_LOADING_MODE={{ tool_search_default_loading_mode }}
# Comma-separated glob patterns (e.g., "tasks.*,tool_search,finish")
TOOL_SEARCH_ALWAYS_LOADED_PATTERNS={{ tool_search_always_loaded_patterns }}
TOOL_SEARCH_ACTIVATION_SCOPE={{ tool_search_activation_scope }}
TOOL_SEARCH_PREFERRED_NAMESPACES={{ tool_search_preferred_namespaces }}
TOOL_SEARCH_FTS_FALLBACK_TO_REGEX={{ tool_search_fts_fallback_to_regex }}
TOOL_SEARCH_ENABLE_INCREMENTAL_INDEX={{ tool_search_enable_incremental_index }}
TOOL_SEARCH_REBUILD_CACHE_ON_INIT={{ tool_search_rebuild_cache_on_init }}
TOOL_SEARCH_MAX_SEARCH_RESULTS={{ tool_search_max_search_results }}

# Prompt aids (optional)
TOOL_SEARCH_HINTS_ENABLED={{ tool_search_hints_enabled }}
TOOL_SEARCH_HINTS_TOP_K={{ tool_search_hints_top_k }}
TOOL_SEARCH_HINTS_INCLUDE_ALWAYS_LOADED={{ tool_search_hints_include_always_loaded }}
TOOL_SEARCH_HINTS_SEARCH_TYPE={{ tool_search_hints_search_type }}

TOOL_SEARCH_DIRECTORY_ENABLED={{ tool_search_directory_enabled }}
TOOL_SEARCH_DIRECTORY_MAX_GROUPS={{ tool_search_directory_max_groups }}
TOOL_SEARCH_DIRECTORY_MAX_TOOLS_PER_GROUP={{ tool_search_directory_max_tools_per_group }}
TOOL_SEARCH_DIRECTORY_INCLUDE_TOOL_COUNTS={{ tool_search_directory_include_tool_counts }}
TOOL_SEARCH_DIRECTORY_INCLUDE_DEFAULT_GROUPS={{ tool_search_directory_include_default_groups }}

# =============================================================================
# Skills (Local Skill Packs)
# =============================================================================
SKILLS_ENABLED={{ skills_enabled }}
SKILLS_CACHE_DIR={{ skills_cache_dir }}
SKILLS_MAX_TOKENS={{ skills_max_tokens }}
SKILLS_SUMMARIZE={{ skills_summarize }}
SKILLS_REDACT_PII={{ skills_redact_pii }}
SKILLS_SCOPE_MODE={{ skills_scope_mode }}
SKILLS_TOP_K={{ skills_top_k }}
SKILLS_FTS_FALLBACK_TO_REGEX={{ skills_fts_fallback_to_regex }}
SKILLS_DIRECTORY_ENABLED={{ skills_directory_enabled }}
SKILLS_DIRECTORY_MAX_ENTRIES={{ skills_directory_max_entries }}
# Comma-separated (e.g., "name,title,trigger")
SKILLS_DIRECTORY_INCLUDE_FIELDS={{ skills_directory_include_fields }}
SKILLS_DIRECTORY_SELECTION_STRATEGY={{ skills_directory_selection_strategy }}
SKILLS_PROPOSAL_ENABLED={{ skills_proposal_enabled }}

# =============================================================================
# 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 %}
