-
Notifications
You must be signed in to change notification settings - Fork 19
docs(sdk): add GPT-5 preset example page linking to code #202
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
3 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| --- | ||
| title: GPT-5 Preset (ApplyPatchTool) | ||
| description: Use the GPT-5 preset to build an agent that swaps the standard FileEditorTool for ApplyPatchTool. | ||
| --- | ||
|
|
||
| import RunExampleCode from "/sdk/shared-snippets/how-to-run-example.mdx"; | ||
|
|
||
| The GPT-5 preset is an opt-in agent preset for patch-based file editing. Calling `get_gpt5_agent(llm)` creates an agent that uses `ApplyPatchTool` instead of the standard `FileEditorTool`, while leaving the default preset unchanged for everything else. | ||
|
|
||
| ## Ready-to-run Example | ||
|
|
||
| <Note> | ||
| This example is available on GitHub: [examples/04_llm_specific_tools/01_gpt5_apply_patch_preset.py](https://github.com/OpenHands/software-agent-sdk/blob/main/examples/04_llm_specific_tools/01_gpt5_apply_patch_preset.py) | ||
| </Note> | ||
|
|
||
| ```python icon="python" expandable examples/04_llm_specific_tools/01_gpt5_apply_patch_preset.py | ||
| """Example: Using GPT-5 preset with ApplyPatchTool for file editing. | ||
|
|
||
| This example demonstrates how to enable the GPT-5 preset, which swaps the | ||
| standard claude-style FileEditorTool for ApplyPatchTool. | ||
|
|
||
| Usage: | ||
| export OPENAI_API_KEY=... # or set LLM_API_KEY | ||
| # Optionally set a model (we recommend a mini variant if available): | ||
| # export LLM_MODEL=( | ||
| # "openai/gpt-5.2-mini" # or fallback: "openai/gpt-5.1-mini" or "openai/gpt-5.1" | ||
| # ) | ||
|
|
||
| uv run python examples/04_llm_specific_tools/01_gpt5_apply_patch_preset.py | ||
| """ | ||
|
|
||
| import os | ||
|
|
||
| from openhands.sdk import LLM, Agent, Conversation | ||
| from openhands.tools.preset.gpt5 import get_gpt5_agent | ||
|
|
||
|
|
||
| # Resolve API key from env | ||
| api_key = os.getenv("LLM_API_KEY") or os.getenv("OPENAI_API_KEY") | ||
| if not api_key: | ||
| raise SystemExit("Please set OPENAI_API_KEY or LLM_API_KEY to run this example.") | ||
|
|
||
| model = os.getenv("LLM_MODEL", "openai/gpt-5.1") | ||
| base_url = os.getenv("LLM_BASE_URL", None) | ||
|
|
||
| llm = LLM(model=model, api_key=api_key, base_url=base_url) | ||
|
|
||
| # Build an agent with the GPT-5 preset (ApplyPatchTool-based editing) | ||
| agent: Agent = get_gpt5_agent(llm) | ||
|
|
||
| # Run in the current working directory | ||
| cwd = os.getcwd() | ||
| conversation = Conversation(agent=agent, workspace=cwd) | ||
|
|
||
| conversation.send_message( | ||
| "Create (or update) a file named GPT5_DEMO.txt at the repo root with " | ||
| "two short lines describing this repository." | ||
| ) | ||
| conversation.run() | ||
|
|
||
| # Report cost | ||
| cost = llm.metrics.accumulated_cost | ||
| print(f"EXAMPLE_COST: {cost}") | ||
| ``` | ||
|
|
||
| <RunExampleCode path_to_script="examples/04_llm_specific_tools/01_gpt5_apply_patch_preset.py"/> | ||
|
|
||
| <Tip> | ||
| You can optionally set `LLM_MODEL` to a GPT-5 variant such as `openai/gpt-5.2-mini`, `openai/gpt-5.1-mini`, or `openai/gpt-5.1`. | ||
| </Tip> | ||
|
|
||
| ## What this preset changes | ||
|
|
||
| - Replaces the standard `FileEditorTool` with `ApplyPatchTool` | ||
| - Keeps the GPT-5-specific configuration explicit via `get_gpt5_agent(llm)` | ||
| - Leaves the default preset unchanged unless you opt into this one | ||
|
|
||
| ## See Also | ||
|
|
||
| - **[LLM Reasoning](/sdk/guides/llm-reasoning)** - Learn more about newer OpenAI model behavior and the Responses API | ||
| - **[LLM Subscriptions](/sdk/guides/llm-subscriptions)** - Use supported OpenAI subscription-backed models without API credits | ||
| - **[Custom Tools](/sdk/guides/custom-tools)** - Understand the standard SDK tool system and presets |
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.