-
Notifications
You must be signed in to change notification settings - Fork 90
Support model-family and model-variant system prompts #1348
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
cc9264d
implement model-family specific system prompts
ryanhoangt 9a50f66
update claude specific prompts
ryanhoangt d1c7b72
update claude prompt
ryanhoangt d0601b7
add gemini custom prompt
ryanhoangt 3b4a5f7
add ability to define model variant-specific prompt
ryanhoangt e5d9335
add gpt-5 custom prompts
ryanhoangt e29f7b6
remove detection indicator in j2 templates
ryanhoangt c1e3ae0
Merge branch 'main' into ht/custom-prompts-per-models
ryanhoangt c074acc
use pydantic
ryanhoangt 6998fd6
add behavior test for oververification
ryanhoangt 4c6e59e
remove all custom prompt files
ryanhoangt ebe6301
add behavior-test label
ryanhoangt 4eb49b4
allow running only behavior tests via workflow dispatch
ryanhoangt 9d66b7c
add behavior test for useless backward compat
ryanhoangt 18dbd0c
Merge branch 'main' into ht/custom-prompts-per-models
enyst c6d4fde
add enviroment notes
ryanhoangt 6e3b4e9
refactor tests
ryanhoangt 555ebc4
revert default system prompt & prioritize canonical name
ryanhoangt 018b27a
Merge branch 'main' into ht/custom-prompts-per-models
enyst e7a865c
remove convo summary truncation for llm judge
ryanhoangt 78ca66c
remove follow up requirement in b03
ryanhoangt 44e5b5a
do not truncate when serializing content in judge llm
ryanhoangt 392b237
add custom prompts for claude and gemini
ryanhoangt 15dba97
add test b04 for gpt-5 and gemini
ryanhoangt 1ba590b
add test b05
ryanhoangt 3d5a622
truncate obs to max 5000 chars
ryanhoangt f07d811
reduce max iter of intg tests to 100
ryanhoangt cb3af19
use 1m context window for judge
ryanhoangt c521e9d
adjust criteria for b02
ryanhoangt 71a6c8f
use haiku for judge
ryanhoangt dff8805
add custom prompts for gpt-5 and gpt-5-codex
ryanhoangt 6b482e3
fix comments
ryanhoangt e8f7424
move <MODEL_SPECIFIC> tag to base prompt
ryanhoangt 4c1e8d5
enable reasoning_summary in intg tests
ryanhoangt 73752c5
Merge branch 'main' into ht/custom-prompts-per-models
ryanhoangt 4c5aaa4
add note for cutoff due to max iter for llm judge
ryanhoangt 1494055
Apply suggestion from @xingyaoww
xingyaoww 708d6bc
Apply suggestion from @xingyaoww
xingyaoww 402eae0
trim newlines from important
xingyaoww File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
openhands-sdk/openhands/sdk/agent/prompts/model_specific/anthropic_claude.j2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| * Try to follow the instructions exactly as given - don't make extra or fewer actions if not asked. | ||
| * Avoid unnecessary defensive programming; do not add redundant fallbacks or default values — fail fast instead of masking misconfigurations. | ||
| * When backward compatibility expectations are unclear, confirm with the user before making changes that could break existing behavior. |
1 change: 1 addition & 0 deletions
1
openhands-sdk/openhands/sdk/agent/prompts/model_specific/google_gemini.j2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| * Avoid being too proactive. Fulfill the user's request thoroughly: if they ask questions/investigations, answer them; if they ask for implementations, provide them. But do not take extra steps beyond what is requested. |
3 changes: 3 additions & 0 deletions
3
openhands-sdk/openhands/sdk/agent/prompts/model_specific/openai_gpt/gpt-5-codex.j2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| * Stream your thinking and responses while staying concise; surface key assumptions and environment prerequisites explicitly. | ||
| * ALWAYS send a brief preamble to the user explaining what you're about to do before each tool call, using 8 - 12 words, with a friendly and curious tone. | ||
| * You have access to external resources and should actively use available tools to try accessing them first, rather than claiming you can’t access something without making an attempt. |
3 changes: 3 additions & 0 deletions
3
openhands-sdk/openhands/sdk/agent/prompts/model_specific/openai_gpt/gpt-5.j2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| * Stream your thinking and responses while staying concise; surface key assumptions and environment prerequisites explicitly. | ||
| * ALWAYS send a brief preamble to the user explaining what you're about to do before each tool call, using 8 - 12 words, with a friendly and curious tone. | ||
| * You have access to external resources and should actively use available tools to try accessing them first, rather than claiming you can’t access something without making an attempt. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
openhands-sdk/openhands/sdk/llm/utils/model_prompt_spec.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| """Utilities for detecting model families and variants. | ||
| These helpers allow prompts and other systems to tailor behavior for specific | ||
| LLM providers while keeping naming heuristics centralized. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from pydantic import BaseModel, ConfigDict | ||
|
|
||
|
|
||
| class ModelPromptSpec(BaseModel): | ||
| """Detected prompt metadata for a given model configuration.""" | ||
|
|
||
| model_config = ConfigDict(frozen=True) | ||
|
|
||
| family: str | None = None | ||
| variant: str | None = None | ||
|
|
||
|
|
||
| _MODEL_FAMILY_PATTERNS: dict[str, tuple[str, ...]] = { | ||
| "openai_gpt": ( | ||
| "gpt-", | ||
| "o1", | ||
| "o3", | ||
| "o4", | ||
| ), | ||
| "anthropic_claude": ("claude",), | ||
| "google_gemini": ("gemini",), | ||
| "meta_llama": ("llama",), | ||
| "mistral": ("mistral",), | ||
| "deepseek": ("deepseek",), | ||
| "alibaba_qwen": ("qwen",), | ||
| } | ||
|
|
||
| # Ordered heuristics to pick the most specific variant available for a family. | ||
| _MODEL_VARIANT_PATTERNS: dict[str, tuple[tuple[str, tuple[str, ...]], ...]] = { | ||
| "openai_gpt": ( | ||
| ("gpt-5-codex", ("gpt-5-codex", "gpt-5.1-codex")), | ||
| ("gpt-5", ("gpt-5", "gpt-5.1")), | ||
| ), | ||
| } | ||
|
|
||
|
|
||
| def _normalize(name: str | None) -> str: | ||
| return (name or "").strip().lower() | ||
|
|
||
|
|
||
| def _match_family(model_name: str) -> str | None: | ||
| normalized = _normalize(model_name) | ||
| if not normalized: | ||
| return None | ||
|
|
||
| for family, patterns in _MODEL_FAMILY_PATTERNS.items(): | ||
| if any(pattern in normalized for pattern in patterns): | ||
| return family | ||
| return None | ||
|
|
||
|
|
||
| def _match_variant( | ||
| family: str, | ||
| model_name: str, | ||
| canonical_name: str | None = None, | ||
| ) -> str | None: | ||
| patterns = _MODEL_VARIANT_PATTERNS.get(family) | ||
| if not patterns: | ||
| return None | ||
|
|
||
| # Choose canonical_name if available, otherwise fall back to model_name | ||
| candidate = _normalize(canonical_name) or _normalize(model_name) | ||
| if not candidate: | ||
| return None | ||
|
|
||
| for variant, substrings in patterns: | ||
| if any(sub in candidate for sub in substrings): | ||
| return variant | ||
|
|
||
| return None | ||
|
|
||
|
|
||
| def get_model_prompt_spec( | ||
| model_name: str, | ||
| canonical_name: str | None = None, | ||
| ) -> ModelPromptSpec: | ||
| """Return family and variant prompt metadata for the given identifiers.""" | ||
|
|
||
| family = _match_family(model_name) | ||
| if family is None and canonical_name: | ||
| family = _match_family(canonical_name) | ||
|
|
||
| variant = None | ||
| if family is not None: | ||
| variant = _match_variant(family, model_name, canonical_name) | ||
|
|
||
| return ModelPromptSpec(family=family, variant=variant) | ||
|
|
||
|
|
||
| __all__ = ["ModelPromptSpec", "get_model_prompt_spec"] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.