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

   Closes #1472
   
   ### Purpose of change
   
   DashScope Chat and Embedding connections now reuse an SDK client across 
calls. Media uses the SDK’s job resources for status and cancellation. This 
brings the providers onto the same SDK generation while retaining the Flink 
Agents result types and recoverable job handles.
   
   #### Runtime flow
   
   A Chat or Embedding connection creates its native client on first use. Each 
call separates request options from model parameters, selects the text or 
multimodal resource, and maps the typed response to a framework result. The 
connection releases the pool on `close()`. Media submits a task once and 
records its ID. Fetch, cancel and recovery use that ID.
   
   #### Key decisions
   
   Synchronous speech recognition and image generation/editing use one 
multimodal Chat request. Asynchronous Qwen image submission needs a separate 
route: the SDK image job helper for Qwen selects the image-synthesis service, 
while Qwen accepts the image-generation endpoint. The provider uses the 
high-level submit API for six model families with matching routing and 
explicitly selects the endpoint for Qwen and deployment aliases.
   
   ### Behavioral Semantics
   
   #### Interaction decisions
   
   | Input or condition | Observable behavior |
   | --- | --- |
   | Registered or directly constructed Chat/Embedding connection | The runtime 
closes a registered connection. Direct callers close it after the last request. 
A subsequent call creates a new pool. |
   | A connection sets a region and a base URL | The base URL selects the 
endpoint. Otherwise the SDK resolves a workspace or shared regional gateway. 
Local SDK config files are skipped. |
   | One call overrides credentials, workspace, headers or timeout | The 
override applies to that request. SDK-level automatic retries are disabled. |
   | Text Chat, synchronous ASR, or synchronous image generation | Chat 
preserves message order and tool call IDs. ASR accepts an explicit empty 
transcript. Image generation preserves image order and permits empty captions. |
   | Single input, batch, or empty Embedding batch | A single input returns a 
vector. A batch returns one vector per input in input order. An empty batch 
makes no request. |
   
   #### Behavioral contracts
   
   Tool arguments must decode to a JSON object. Token usage comes from the 
typed SDK response and remains optional. Media polling distinguishes a failed 
task from failure to query a task, and retains the cancellation reason when 
available. Video generation sends ordered input roles literally and preserves 
SDK resolution of OSS URLs.
   
   #### Failure behavior
   
   Invalid timeouts and unsupported SDK call options fail locally. Chat and 
Embedding propagate SDK connection and timeout errors; service failures raise 
`RuntimeError` with the SDK cause. A missing transcript, an ambiguous captioned 
image result, or an incomplete embedding batch fails the call. Recovery resumes 
polling the stored job ID.
   
   ### Tests
   
   | Contract | Regression coverage |
   | --- | --- |
   | Connection ownership, credentials and request timeout | 
`test_dashscope_connection_lifetime`, 
`test_dashscope_credentials_and_positional_timeout`, 
`test_request_timeout_reaches_sdk_transport` |
   | One request on network failure, service error cause | 
`test_dashscope_native_http_failure_is_not_retried`, 
`test_dashscope_unknown_service_error_preserves_message_and_cause` |
   | Conversation order and tool arguments | 
`test_text_chat_sends_the_full_conversation_in_order`, 
`test_tool_call_ids_round_trip`, 
`test_tool_arguments_require_an_explicit_json_object` |
   | ASR silence and ordered image output | 
`test_asr_preserves_silence_and_rejects_a_missing_transcript`, 
`test_image_generation_requires_and_preserves_ordered_images` |
   | Embedding order, cardinality and optional usage | 
`test_text_embedding_restores_input_order`, 
`test_empty_embedding_batch_needs_no_request`, 
`test_batch_text_embedding_usage` |
   | Media submit routes, role ordering and job recovery | Image and video 
submission tests assert the HTTP payload and headers. 
`test_fetch_keeps_task_error_when_gateway_error_fields_are_empty` checks the 
failure detail. `test_interrupted_wait_replays_the_submitted_job` checks that 
recovery submits only once. |
   
   DashScope provider and durable recovery tests passed on SDK 2.1.0 and 2.1.2 
(340 per version). Ruff lint and formatting passed. The full Python 
non-integration suite on SDK 2.1.0 passed (3,995 passed, 18 skipped, 91 
deselected).
   
   Earlier live Beijing gateway checks covered Chat, Embedding, transcription, 
speech synthesis, image generation and video. The final rebased revision was 
verified offline. Cross-language Flink E2E and live calls for every supported 
image family were outside that run.
   
   ### API
   
   The Python dependency becomes `dashscope>=2.1.0,<3`. Existing framework 
resource names and result types are retained. Multi-turn callers pass 
`messages` in order. Legacy `history=`, WebSocket and SDK-only request options 
are rejected. Use the framework’s `request_timeout` for a positive, finite 
timeout in seconds.
   
   ### Documentation
   
   - [x] `doc-included` — Updated the Chat and Embedding provider guides.
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   - [x] Yes
   - [ ] No
   
   Generated-by: Codex CLI 0.171.0-alpha.13.2 (GPT-6.2 Astra)
   


-- 
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