-
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
Open
tudormatei1
wants to merge
8
commits into
main
Choose a base branch
from
feat/model-specific-settings
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
fc47974
feat(agent): forward model settings and skip forced tool_choice under…
tudormatei1 81dedc5
handle anthropic thinking edge case
tudormatei1 6a0ab10
router and llm node now support one llm call stall, meaning thinking …
tudormatei1 ae06dad
refactor
tudormatei1 33b7c59
refactor
tudormatei1 191ee03
ensured PII doesnt get logged in telemetry
tudormatei1 a0f190a
addressed copilot comments
tudormatei1 9b88d18
fix import after licensing merged into llm module
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.
Uh oh!
There was an error while loading. Please reload this page.