-
Notifications
You must be signed in to change notification settings - Fork 35
feat(agent): forward model settings and recover from thinking stalls [PC-4672] #1017
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
11 commits
Select commit
Hold shift + click to select a range
b30c98d
feat(agent): forward model settings and skip forced tool_choice under…
tudormatei1 ba04cd9
feat(agent): retry a stalled thinking turn with a forced extraction call
tudormatei1 a33cc58
feat(agent): tolerate one tool-less turn before failing the run
tudormatei1 0ddd334
refactor(chat): centralize thinking config handling in chat/thinking.py
tudormatei1 bc770c5
refactor(agent): fold licensing error mapping into exceptions/llm
tudormatei1 0b574d8
fix(agent): keep provider error bodies out of run telemetry
tudormatei1 c832e27
refactor(agent): apply review feedback on thinking and extraction
tudormatei1 502f437
fix(agent): update analyze_files_tool import after the licensing merge
tudormatei1 2675455
revert(agent): restore provider http error mapping to main behaviour
tudormatei1 56649a9
chore: bump to 0.16.15 and require uipath-langchain-client>=1.18.3
tudormatei1 6828913
test: type-annotate the forced-extraction and llm-node stubs
tudormatei1 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 was deleted.
Oops, something went wrong.
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 |
|---|---|---|
| @@ -1,4 +1,3 @@ | ||
| DEFAULT_MAX_CONSECUTIVE_THINKING_MESSAGES = 0 | ||
| DEFAULT_MAX_LLM_MESSAGES = 25 | ||
|
|
||
| UIPATH_CONVERSATIONAL_AGENT_RESPONSE_MESSAGES_FIELD = "uipath__agent_response_messages" |
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,49 @@ | ||
| """Force a structured end_execution out of a thinking model that stalled. | ||
|
|
||
| Anthropic won't honor a forced tool_choice while thinking is on, so a thinking model can | ||
| answer in plain text and never call end_execution. build_extraction_call retries that | ||
| turn with thinking off and the tool call forced, which every provider honors. | ||
| """ | ||
|
|
||
| from langchain_core.language_models import BaseChatModel | ||
| from langchain_core.messages import AIMessage, AnyMessage, HumanMessage, ToolMessage | ||
|
|
||
| from uipath_langchain.chat.thinking import is_reasoning_block, strip_thinking | ||
|
|
||
|
|
||
| def _strip_reasoning_blocks(messages: list[AnyMessage]) -> list[AnyMessage]: | ||
| """Drop reasoning blocks from AI messages (keep text + tool calls). | ||
|
|
||
| They can't be replayed on a thinking-off call — an orphaned thinking block 400s. | ||
| """ | ||
| stripped: list[AnyMessage] = [] | ||
| for message in messages: | ||
| if isinstance(message, AIMessage) and isinstance(message.content, list): | ||
| kept = [block for block in message.content if not is_reasoning_block(block)] | ||
| if len(kept) != len(message.content): | ||
| # a turn that was only reasoning is now empty — drop it | ||
| if not kept and not message.tool_calls: | ||
| continue | ||
| message = message.model_copy(update={"content": kept}) | ||
| stripped.append(message) | ||
| return stripped | ||
|
|
||
|
|
||
| def _ensure_trailing_user_turn(messages: list[AnyMessage]) -> list[AnyMessage]: | ||
| if messages and isinstance(messages[-1], (HumanMessage, ToolMessage)): | ||
| return messages | ||
| return list(messages) + [ | ||
| HumanMessage( | ||
| content="Call a tool to continue. Terminal tool calls must contain the final output." | ||
| ) | ||
| ] | ||
|
|
||
|
|
||
| def build_extraction_call( | ||
| model: BaseChatModel, messages: list[AnyMessage] | ||
| ) -> tuple[BaseChatModel, list[AnyMessage]]: | ||
| """The (model, messages) for the extraction call: thinking off, reasoning blocks | ||
| dropped, ending on a user turn — the caller then forces tool_choice.""" | ||
| return strip_thinking(model), _ensure_trailing_user_turn( | ||
| _strip_reasoning_blocks(messages) | ||
| ) |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this mapping is incorrect. I know you just moved the mapping, but this should be fixed.