sangkyoonnam opened a new pull request, #1497:
URL: https://github.com/apache/flink-agents/pull/1497

   Linked issue: Part of #1437
   
   ### Purpose of change
   
   This is PR 2 of 3 for the Python side of #1437, following #1487. Python 
routers now execute the escalation they declare, with the semantics of Java's 
#1363: on a tier below the last one, an answer that fails a check is discarded 
before any of its tool calls runs, and the conversation so far goes to the next 
tier, where the request then stays.
   
   The evaluator (`plan/routing/escalation_evaluator.py`) follows 
`EscalationEvaluator`. The structural checks run first: an empty answer, a call 
to a tool the candidate doesn't have, arguments that fail the tool's input 
schema, and the same calls as the previous assistant round of the turn. Then 
the declared signals run in order. The decision-model signal skips a round made 
only of tool calls. A custom signal runs under the durable id 
`escalate:<router>:<candidate>:<index>`, and the decision model under 
`escalate:<router>:<candidate>`, so recovery replays both. A signal that can't 
judge the round fails the request.
   
   `routing/executor.py` owns the hops: it skips a rejected tier during 
fallback, honors the cap, sends a `ModelRoutingEvent` with source `escalation` 
per hop, records `routingEscalationCount` and `routingEscalatedTokens`, and 
adds `escalation_attempted`, `escalations` and `escalated_tokens` to the 
`model_routing` block. A tool round of a tiered request keeps the policy: it 
reads the router and the hops taken from the saved block, and an escalated 
attempt there uses `chat:<router>:<tier>`. On a gated tier the output schema is 
applied after the gate, and an answer that can't be shaped into it is a 
structural rejection rather than a retry. A tiers-only router abstains and 
starts on its default model, the first tier unless declared. The decision 
signal's retries and tokens count against the request, as in Java; to share 
that loop, `process_decision_request` now calls a `decide_with_retries` helper.
   
   This PR doesn't change docs or examples, and adds no e2e test; PR 3 covers 
those.
   
   ### Behavioral Semantics
   
   A router without tiers behaves as before, except that its `model_routing` 
block now carries `escalation_attempted`, `escalations` and `escalated_tokens`, 
as Java's does, and the fallback event's reason names the model that failed 
last (`fallback after model 'x' failed`), the form #1363 introduced. A 
Java-declared candidate skips the two tool checks, since its tools are bound on 
the Java side, the same way Java skips them for a Python candidate.
   
   ### Tests
   
   `test_model_routing_escalation.py` runs requests through the chat action: 
hops on the structural checks and on both signal types, the cap and the last 
tier, a signal that fails, fallback past a rejected tier, a hop inside a tool 
loop and the cap counting hops from earlier rounds, a decision model that fails 
or refuses, native and parsed output schemas on a gated tier, and tiers-only 
routing. `test_escalation_evaluator.py` covers the checks and the verifier 
input. `pytest flink_agents/api flink_agents/plan flink_agents/runtime/tests`: 
2790 passed, 18 skipped (py3.11, all integration extras installed). `ruff 
check` and `ruff format --check` 0.11.13 pass.
   
   ### API
   
   `QualitySignal`, `QualityContext` and `QualityVerdict` join 
`flink_agents.api.chat_models.escalation`, with `Escalation.next_tier(...)` and 
`effective_max_escalations`. `ModelRouterBuilder.escalation(...)` no longer 
leads to a plan error.
   
   ### Documentation
   
   - [x] `doc-needed`
   - [ ] `doc-not-needed`
   - [ ] `doc-included`
   
   PR 3 updates `model_routing.md`, which still says Python doesn't support 
`escalation(...)`.
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   - [x] Yes
   - [ ] No
   
   Generated-by: Claude Code 2.1.333 (Claude Opus 5.5)
   


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to