Repository navigation
Conversation
wuyak
force-pushed
the
codex/s18-output-truncation-v2
branch
from
October 9, 2026 06:50
ea5bc8a to
4939d50
Compare
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.
AgentScope Version
2.0.10devDescription
Closes #3194.
Model providers report why generation stopped, but AgentScope currently drops that information and leaves
ChatResponse.finished_reasonasCOMPLETED. If generation reaches an output-length limit while producing tool arguments, the existing JSON repair can make the partial arguments syntactically valid and allow the tool to run.For example, assume the agent exposes this tool:
The model may intend to generate:
{ "path": "/tmp/result.txt", "content": "unfinished task, please continue..." }If the provider stops generation at its output limit, AgentScope may receive:
{"path": "/tmp/result.txt", "content": "unfinishedThe existing repair path can turn it into:
{"path": "/tmp/result.txt", "content": "unfinished"}and execute the equivalent of:
JSON repair can restore syntax, but it cannot recover content the model never generated.
Changes
Added
FinishedReason.LENGTH.Preserved the provider's original value in
ChatResponse.metadata["raw_finish_reason"].Preserved explicit finish reasons and metadata through streaming accumulation.
Read finish reasons inside the existing parsing paths of the supported adapters:
lengthmax_tokensandmodel_context_window_exceededMAX_TOKENSREASON_MAX_LENandREASON_MAX_CONTEXTlengthAdded an opt-in ReAct guard:
The option defaults to
False. When enabled, AgentScope rejects only the final tool call when the response is explicitly markedFinishedReason.LENGTHand strictjson.loadscannot parse its arguments. The rejected call is closed with the existingERRORToolResult; the existing ReAct loop decides what happens next.Behavior boundaries
qwen3.7-flashprobe, the provider reported normal completion/tool use for a token-limited malformed tool call, so the guard correctly did not activate.Added tests
This PR adds 14 test methods to AgentScope's existing Agent and model-adapter test files, covering:
ToolResultis produced.Result:
git diff --checkalso passes.Real-model validation
I also ran a temporary, side-effect-free probe against
deepseek-v4.1-flashthrough Alibaba Cloud Model Studio's OpenAI-compatible Chat API (DeepSeek API, model documentation). The probe used this branch,max_tokens=64, the guard enabled, a two-iteration ReAct limit, and an in-memory tool.Observed behavior:
lengthwith incomplete JSON tool arguments.ERRORToolResultand did not execute the tool.TRUNCATION_ERROR_OBSERVED.The tool execution count remained zero. This confirms the provider signal reaches the guard and that the existing loop can continue after the error result; the controlled prompt does not claim a general model recovery strategy.
Checklist