Repository navigation
PC-5280: forward agent max_tokens to tool simulation, detect truncation - #1969
Draft
al3xanndru wants to merge 2 commits into
Draft
al3xanndru wants to merge 2 commits into
al3xanndru wants to merge 2 commits into
Conversation
…ation Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ModelSettings has no populate_by_name, so the max_tokens keyword was silently ignored. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
This branch has not been deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.


Problem
https://uipath.atlassian.net/browse/PC-5280
Debug and playground runs that simulate tools through the legacy
toolsToSimulatepath can fault with:The agent's own LLM calls succeed. Only the tool simulation fails, and only when the simulated output is large, for example when the tool's output schema has an open-ended list or
anyOf: [{}, null]field.Root cause
Two gaps in
uipath.eval.mocks:max_tokens.build_mocking_contextfalls back to the agent's model asModelSettings(model=agent_model), which carries the model name only. The eval runtime does the same withModelSettings(model=get_agent_model(...)). So the simulation call goes out at theUiPathLlmChatService.chat_completionsdefault ofmax_tokens=4096, even when the agent is configured for more (16384 in the reported case). In the reported failure, the logged request body showsmax_tokens: 4096, and both simulation calls used exactly 4096 completion tokens.response_formatreply is cut off and failsjson.loads. The forcedsubmit_tool_responsefallback is cut off the same way, and the gateway returns its arguments as{}.extract_responsenever looks atfinish_reason, so it reports a missing key instead of a length cut-off.Change
eval/helpers.py: newget_agent_max_tokens(schema), the counterpart ofget_agent_model. It readsschema.metadata["settings"]["max_tokens"](the low-code runtime dumpsAgentSettingsby field name) ormaxTokens. Anything that isn't a positive int is ignored.eval/mocks/_mock_runtime.py:build_mocking_context,build_mocking_context_from_dictandload_simulation_configtake an optionalagent_max_tokens. When the simulation falls back to the agent's model, it usesModelSettings(model=agent_model, max_tokens=agent_max_tokens). The new parameter is keyword-compatible, so existing callers are unaffected._cli/cli_debug.py,_cli/cli_run.py,eval/runtime/runtime.py: pass the agent's max tokens wherever the agent's model is already passed.eval/mocks/_structured_output.py:responsekey andfinish_reason == "length",extract_responseraises a clear error: "LLM response was truncated at the max_tokens limit (finish_reason='length') ... increase the model's max tokens".response_formatpath logs a warning when its output was truncated, before it falls back to tools.pyproject.toml,uv.lock).Deliberately left out:
temperature(and its other settings) are still not forwarded. Forwarding temperature to models that reject it is what caused PC-4769.SimulationConfig.modeldoes not inherit the agent'smax_tokens. That model may have a lower output cap than the agent's model, and sending the agent's cap to it could turn today's successful runs into 400s.Tests
tests/cli/eval/mocks/test_mock_runtime_model_settings.py(new):max_tokens, and it reachessimulation_completion_kwargs;max_tokensis omitted when the agent has none;tests/cli/eval/mocks/test_structured_output.py:{}arguments raises the truncation error;finish_reason == "length"are still returned;response_formatreply followed by a truncated tool call raises the truncation error, and both calls carrymax_tokens.tests/cli/eval/test_eval_runtime_metadata.py:get_agent_max_tokenshandles snake_case, camelCase, a missing value, and unusable values.Results: see the summary below the fold. (TEST_RESULTS)
Risks / open questions
max_tokens, which costs more tokens and time on runs whose mock output really is large. That is the agent author's configured budget.model, and coded agents (no model in their schema), still go out at the 4096 default. If those need a larger cap, the next step would be a mocker defaultmax_tokens.UiPathMockResponseGenerationError, which the agents runtime maps to Unknown. Classifying it correctly is a separate change in uipath-agents-python's exception mapper.Drafted by the wabbit-dri draft-fixes loop for PC-5280 (draft #1), for a human to review: not ready to merge as is.
🤖 Generated with Claude Code