Skip to content

Per-model prompt customization: model-family overrides and user-defined prompt pieces #1173

Closed

Description

@enyst

Per-model prompt customization: model-family overrides and user-defined prompt pieces

Context/motivation

  • We want more “forking” logic in prompts to optimize behavior/cost per model (e.g., Sonnet vs GPT vs Gemini), without breaking default setups.
  • Today, prompts are largely shared. We have good Jinja composition, but not a clean, conventional way to vary content per model family.

What exists today (summary)

  • System prompts (Jinja):
    • openhands-sdk/openhands/sdk/agent/prompts/*.j2
    • Primary: system_prompt.j2 includes sections like security_policy.j2 and security_risk_assessment.j2
    • Variants exist (system_prompt_long_horizon.j2, system_prompt_planning.j2, etc.)
  • Other prompt surfaces:
    • Condenser: openhands-sdk/openhands/sdk/context/condenser/prompts/summarizing_prompt.j2
    • AgentContext suffix/skills templates: openhands-sdk/openhands/sdk/context/prompts/templates/*
    • Function-calling shim suffix lives in code (non_native_fc.py) as a string template
  • Rendering:
    • render_template(prompt_dir, template_name, **ctx) supports absolute file paths, so users can completely override templates already
    • AgentBase exposes system_prompt_filename and system_prompt_kwargs; AgentContext can append a system_message_suffix
  • Model awareness:
    • Model-family/capability detection already exists in openhands-sdk/openhands/sdk/llm/utils/model_features.py (e.g., reasoning support, prompt cache), and logic in chat_options.py and responses_options.py

Core problem

  • No conventional, simple mechanism to select prompt variants per model family (e.g., claude | gpt | gemini | deepseek | default) for the system prompt and other prompt surfaces.

Design goals

  • Simple mental model; easy to reason about
  • Backward compatible (no breakage to current users/examples)
  • Works for a small fixed set of families and also supports user-supplied overrides
  • Keep changes shallow and localized; avoid spreading conditionals everywhere

Deep design options (with depth-of-change analysis)

  1. Model-family-aware template resolution (search order + fallback)
  • Idea: When rendering any known template, try a family-specific variant first, then fall back to default.
    • Suggested families: claude, gpt, gemini, deepseek, default
    • Resolution order examples:
      • models/{family}/{template}.j2 → {stem}__{family}.j2 → {template}.j2
      • Apply to: system_prompt.j2, security_policy.j2, security_risk_assessment.j2, summarizing_prompt.j2, etc.
  • Where to implement:
    • openhands-sdk/openhands/sdk/context/prompts/prompt.py
      • In render_template/_get_template: resolve candidate filenames in family-aware order before falling back to the base name
    • Compute model_family from LLM.model (see utils/model_features.py)
      • Provide a small helper (e.g., get_model_family(model: str) -> Literal['claude','gpt','gemini','deepseek','default'])
      • Pass model_family into the template context automatically where we render system prompts and other prompts
    • Packaging: ensure agent-server.spec collects prompts in prompts/models/* (PyInstaller data collection list already includes prompts/.j2; we’d extend it to include prompts/models/ if needed)
  • Depth:
    • ~50–120 LOC across prompt loader, small helper in model_features or a new util, and minor additions where we call render_template
    • Low risk: default templates still load if family-specific files don’t exist
  1. Inject model_family and feature flags into template context (no file layout changes)
  • Idea: Add model_family and features (from get_features(model)) to system_prompt_kwargs (and any other prompt render ctx) automatically.
    • Then templates can do conditional logic: {% if model_family == 'claude' %}…{% endif %}
  • Where to implement:
    • openhands-sdk/openhands/sdk/agent/base.py → system_message property before calling render_template
    • openhands-sdk/openhands/sdk/context/condenser/llm_summarizing_condenser.py → before rendering summarizing_prompt
  • Depth:
    • ~20–40 LOC to pass down model_family/features; pure additive and fully backward compatible
    • No packaging impact
  • Tradeoff:
    • Risk of templates accumulating too many conditionals; keep it minimal and prefer per-section overrides when possible
  1. Section-level override helper (Jinja include-if-exists)
  • Idea: Allow swapping just parts of a prompt per family without copying the full template.
    • Provide include_if_exists(primary, fallback) macro/global so system_prompt.j2 can do:
      • include_if_exists('security_policy__' ~ model_family ~ '.j2', 'security_policy.j2')
  • Where to implement:
    • openhands-sdk/openhands/sdk/context/prompts/prompt.py → extend Jinja Environment with a global function/macro that checks for template existence (env.list_templates or loader.get_source try/except) and renders the first available
    • Update system_prompt.j2 (and other core templates) to optionally use this helper
  • Depth:
    • ~30–60 LOC; purely additive
    • Minimal change to existing templates (only where we want optional overrides)
  1. User-supplied prompt search paths (programmatic overrides without forking)
  • Idea: Allow adding extra directories to the Jinja loader so user-owned folders are searched before defaults.
    • API surfaces:
      • AgentBase or AgentContext gains additional_prompt_paths: list[str]
      • Or env var OPENHANDS_PROMPT_PATHS=/dir1:/dir2
  • Where to implement:
    • openhands-sdk/openhands/sdk/context/prompts/prompt.py → _get_env: use FileSystemLoader with multiple search paths (user-provided first, then default prompt_dir)
    • Add a way to pass paths from Agent/AgentContext to render_template; or store them in AgentContext and thread through
  • Depth:
    • ~40–80 LOC plus light plumbing to propagate paths
    • Backward compatible; improves ergonomics for user-defined per-model pieces
  1. Optional config map (YAML/JSON) of template bindings
  • Idea: Centralize mapping of logical sections → concrete files per family:
    • Example promptmap.yaml:
      system:
      default: system_prompt.j2
      claude: system_prompt__claude.j2
      security_policy:
      default: security_policy.j2
      gemini: security_policy__gemini.j2
  • Where to implement:
    • A small resolver in prompt.py that, if present, rewrites template_name prior to rendering
  • Depth:
    • Medium; adds a new file and parsing logic; might be unnecessary if (1–4) suffice

Backward compatibility considerations

  • All options maintain current behavior if no per-family files are present
  • Absolute-path overrides continue to work
  • No breaking API changes to Agent/LLM unless we add optional parameters (e.g., additional_prompt_paths)

How users would use it (examples)

  • Small fixed set of families (e.g., 5):
    • Drop a claude-specific file: openhands-sdk/openhands/sdk/agent/prompts/models/claude/security_policy.j2
    • Or use suffix form: openhands-sdk/openhands/sdk/agent/prompts/security_policy__claude.j2
    • No code changes required in user code; the loader picks the right file
  • Fully user-defined (Jinja):
    • Full override already works:
      • Agent(llm=llm, system_prompt_filename="/abs/path/custom_system_prompt.j2")
    • With search paths (if 4 is added):
      • AgentContext(additional_prompt_paths=["/my/prompts"]) → place per-family files there, optionally with include_if_exists to swap sections
    • Conditional in a single template (if 2 is added):
      • {% if model_family == 'claude' %}…{% else %}…{% endif %}

Notes on function-calling shim

  • The FC shim’s system_message_suffix_TEMPLATE in non_native_fc.py could be migrated to a Jinja template to unify mechanisms with prompts; or we can keep it as a code string and add minimal per-family branching there if needed. Unifying to Jinja reduces special casing but is not strictly required.

Open questions

  • Canonical family names beyond {claude,gpt,gemini,deepseek,default}?
  • Expose a public helper get_model_family(model: str) for user code?
  • Should we standardize models/{family}/… as the primary pattern and keep {stem}__{family}.j2 as a convenience?

No implementation plan included per request; the above focuses on code design and depth of change needed.

Activity

  1. enyst commented on Dec 4, 2025

    @enyst
    MemberAuthor

    GPT-5 "make it talk" prompt piece: (added to the default system prompt)

    GPT-5 prompt: (and codex)

    Discussion on how to tweak system prompts for models:

    TL;DR: no separate prompts, for the time being, maybe do necessary tweaks per model in the default system prompt.

  2. self-assigned this
    on Dec 8, 2025
  3. removed their assignment
    on Dec 18, 2025
  4. all-hands-bot commented on Jan 28, 2026

    @all-hands-bot
    Collaborator

    This issue is stale because it has been open for 40 days with no activity. Remove the stale label or leave a comment, otherwise it will be closed in 10 days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions