-
Notifications
You must be signed in to change notification settings - Fork 152
feat: Support reasoning content in Agent SDK #139
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
34 commits
Select commit
Hold shift + click to select a range
11f1593
feat: Support reasoning content in Agent SDK
enyst abbf611
Address PR review comments
openhands-agent 4ca0ef2
Remove Anthropic-specific thinking_blocks field, keep only reasoning_…
openhands-agent 2403165
Merge branch 'main' into openhands/support-reasoning-content
xingyaoww 9d244a4
fix missing comma
xingyaoww 1bf97c2
add reasoning content to all relavant fields
xingyaoww 1aef2e6
directly assign reasoning content since it is also str | None
xingyaoww 6155a25
update repo md
xingyaoww 59c7569
track reasoning tokens
xingyaoww e23d198
add convertible to other fields too
xingyaoww a645fc2
support showing reasoning token in metrics
xingyaoww 399a968
examples: add reasoning debug example to visualize Message.reasoning_…
enyst 412c38f
add reasoning file
enyst d01a8ab
add missing deepseek-reasoner
enyst 083807c
examples: add multi-model reasoning probe and clean up; sdk.llm: remo…
enyst 1a82e87
fix name
enyst 7679f4e
Reasoning: surface reasoning_content end-to-end; add debug example; D…
enyst a61214b
examples: focus defaults on DeepSeek R1 (deepseek-r1-0528) for debugg…
enyst bb0642d
examples(reasoning_debug): restore defaults to deepseek-reasoner + ge…
enyst 73605e9
merge: resolve conflicts with upstream/main\n\n- llm_convertible.Acti…
enyst f1fa4e6
Update openhands/sdk/llm/llm.py
enyst a195ce9
fix: tolerate reasoning_content on MessageEvent input; make Metrics.a…
enyst 9b2f9b9
tests: remove deepseek-r1-0528 from model_features tests; align expec…
enyst 8cbd0f1
set explicit default for Gemini
enyst f057010
Update openhands/sdk/llm/llm.py
enyst 20a766e
chore: ruff-format fixes after removing thinking_blocks passthrough\n…
enyst db5192e
fix: remove thought/reasoning_content from AgentErrorEvent and its us…
enyst 1b06c01
fix(llm): only forward tools when native function-calling is active t…
enyst e858943
chore(examples): remove debugging-only reasoning probe from PR; keep …
enyst 539b450
also save cache read
xingyaoww c79029c
simplify duplicated logic
xingyaoww 51494f3
remove unused test and revert changes
xingyaoww 1f87277
Merge commit '46b1fa541af21be5849bcc5775efd2747ef36b41' into openhand…
xingyaoww 048202c
rename example
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -370,7 +370,10 @@ def completion( | |
|
|
||
| # 3) normalize provider params | ||
| kwargs["tools"] = tools # we might remove this field in _normalize_call_kwargs | ||
| call_kwargs = self._normalize_call_kwargs(kwargs, has_tools=bool(tools)) | ||
| has_tools_flag = ( | ||
| bool(tools) and use_native_fc | ||
| ) # only keep tools when native FC is active | ||
| call_kwargs = self._normalize_call_kwargs(kwargs, has_tools=has_tools_flag) | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note from the agent
... which is confirmed 🫠 |
||
|
|
||
| # 4) optional request logging context (kept small) | ||
| assert self._telemetry is not None | ||
|
|
@@ -495,11 +498,11 @@ def _normalize_call_kwargs(self, opts: dict, *, has_tools: bool) -> dict: | |
| # Anthropic/OpenAI reasoning models ignore temp/top_p | ||
| out.pop("temperature", None) | ||
| out.pop("top_p", None) | ||
| # Gemini 2.5 budget mapping | ||
| # Gemini 2.5-pro default to low if not set | ||
| # otherwise litellm doesn't send reasoning, even though it happens | ||
| if "gemini-2.5-pro" in self.model: | ||
| if self.reasoning_effort in {None, "low", "none"}: | ||
| out["thinking"] = {"budget_tokens": 128} | ||
| out["allowed_openai_params"] = ["thinking"] | ||
| if self.reasoning_effort in {None, "none"}: | ||
| out["reasoning_effort"] = "low" | ||
|
|
||
| # Anthropic Opus 4.1: prefer temperature when | ||
| # both provided; disable extended thinking | ||
|
|
@@ -563,14 +566,21 @@ def _all_choices( | |
| "Expected non-streaming Choices when post-processing mocked tools" | ||
| ) | ||
|
|
||
| non_fn_message: dict = resp.choices[0].message.model_dump() | ||
| fn_msgs = convert_non_fncall_messages_to_fncall_messages( | ||
| # Preserve provider-specific reasoning fields before conversion | ||
| orig_msg = resp.choices[0].message | ||
| non_fn_message: dict = orig_msg.model_dump() | ||
| fn_msgs: list[dict] = convert_non_fncall_messages_to_fncall_messages( | ||
| nonfncall_msgs + [non_fn_message], tools | ||
| ) | ||
| last = fn_msgs[-1] | ||
| if not isinstance(last, LiteLLMMessage): | ||
| last = LiteLLMMessage(**last) | ||
| resp.choices[0].message = last | ||
| last: dict = fn_msgs[-1] | ||
|
|
||
| for name in ("reasoning_content", "provider_specific_fields"): | ||
| val = getattr(orig_msg, name, None) | ||
| if not val: | ||
| continue | ||
| last[name] = val | ||
|
|
||
| resp.choices[0].message = LiteLLMMessage.model_validate(last) | ||
| return resp | ||
|
|
||
| # ========================================================================= | ||
|
|
||
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
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.