You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by "emecii (via GitHub)" <gi...@apache.org> on 2026/09/07 07:01:20 UTC
[PR] [bug][integrations][anthropic][java][python] Preserve Anthropic finish reason [flink-agents]
emecii opened a new pull request, #1107:
URL: https://github.com/apache/flink-agents/pull/1107
Linked issue: #936
### Purpose of change
Anthropic responses that stop at the configured output-token limit now reach the shared chat action
as `extra_args["finish_reason"] == "length"`. The action already rejects that canonical value before
it dispatches incomplete content, so callers receive its clear truncation error instead of parsing
or consuming a partial response.
Both Anthropic connections read the SDK response stop reason after converting the content. They map
Anthropic's `max_tokens` value to the existing cross-provider `length` value and retain every other
reported value unchanged.
### Behavioral Semantics
#### Key decisions
Only `max_tokens` is normalized because it is Anthropic's name for the shared action's established
token-limit condition. Other reasons remain provider values so that an unknown future reason is
observable without changing control flow.
#### Interaction decisions
| Anthropic stop reason | Stored `finish_reason` | Shared action behavior |
| --- | --- | --- |
| absent | absent | Existing behavior |
| `max_tokens` | `length` | Rejects incomplete response before dispatch |
| any other supplied value | same value | Existing accepted-reason behavior |
#### Behavioral contracts
- A Java or Python Anthropic response stopped by `max_tokens` exposes the canonical `length`
metadata that the shared action recognizes.
- A supplied non-token-limit stop reason remains available without being reclassified.
- A response without a stop reason gains no metadata entry.
#### Failure behavior
This converter change does not catch, retry, or transform provider failures. When the model returns
`max_tokens`, the existing shared action raises its established truncation error; direct connection
callers can inspect the response metadata before invoking that action.
### Tests
| Contract | Tests |
| --- | --- |
| `max_tokens` becomes `length`; ordinary reasons remain observable | Java `AnthropicChatModelConnectionTest` (94 passed); Python `test_anthropic_response_parsing.py` |
| Shared action rejects `length` before dispatch | Java `ChatModelActionTest` and `ChatModelActionRetryTest` (36 passed); Python `test_chat_model_action.py` |
Focused Python run: 107 passed across the Anthropic response parser and shared-action tests.
Spotless, Ruff format/check, and Apache RAT license checks pass.
Not verified: live Anthropic API calls. Tests use SDK response objects and local action fixtures, so
they require no credentials or network access.
<details>
<summary>Implementation evidence</summary>
The Python converter stores the key independently of token-usage metrics. The Java converter reads
the optional SDK stop reason after constructing the response and does the same. This keeps the
mapping available for responses with or without recorded usage and for both plain-text and tool-call
conversion paths.
</details>
### API
No public API signature changes. Existing consumers of `extra_args` gain `finish_reason` on
Anthropic responses; the shared action now classifies Anthropic token-limit responses consistently
with OpenAI-family responses.
### Documentation
- [ ] `doc-needed`
- [x] `doc-not-needed`
- [ ] `doc-included`
### Was this patch authored or co-authored using generative AI tooling?
- [x] Yes
- [ ] No
Generated-by: Codex CLI 0.153.4 (GPT-6)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [integrations][anthropic][java][python] Preserve Anthropic finish reason [flink-agents]
Posted by "wenjin272 (via GitHub)" <gi...@apache.org>.
wenjin272 merged PR #1107:
URL: https://github.com/apache/flink-agents/pull/1107
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org