Commit 704428b
authored
feat(codec): add missing optional AnnotatedLlmRequest/Response fields (NVIDIA#76)
Summary
This PR expands normalized codec extraction around `AnnotatedLlmRequest` and `AnnotatedLlmResponse` for:
- OpenAI Chat Completions (`/v1/chat/completions`)
- OpenAI Responses (`/v1/responses`)
- Anthropic Messages (`/v1/messages`)
- Hybrid payload variants observed in inference gateways/provider bridges (`vLLM`, `LiteLLM`, `SGLang` patterns)
The goal is to extract more meaningful normalized state while preserving unmodeled provider-specific fields losslessly via `extra`.
Additive Request IR State (`AnnotatedLlmRequest`)
Added normalized optional fields:
- `store: Option<bool>`
- `previous_response_id: Option<String>`
- `truncation: Option<Json>`
- `reasoning: Option<Json>`
- `include: Option<Json>`
- `user: Option<String>`
- `metadata: Option<Json>`
- `service_tier: Option<String>`
- `parallel_tool_calls: Option<bool>`
- `max_output_tokens: Option<u64>`
- `max_tool_calls: Option<u64>`
- `top_logprobs: Option<u64>`
- `stream: Option<bool>`
Multimodal request content expansion:
- `ContentPart::ImageUrl { image_url: OpenAiImageUrl }`
- `OpenAiImageUrl { url, detail }`
Additive Response IR State (`ApiSpecificResponse`)
OpenAI Responses variant expanded with:
- `previous_response_id`
- `store`
- `service_tier`
- `truncation`
- `reasoning`
- `input_tokens_details`
- `output_tokens_details`
Anthropic Messages variant expanded with:
- `service_tier`
- `container`
- `content_blocks`
OpenAI Responses request-side hardening
- Added strict-first decode behavior for heterogeneous `input` arrays
- Removed silent lossy fallback behavior
- Preserves unparsed mixed input items in `extra` (`_openai_responses_unparsed_input_items`) for round-trip safety
- Handles Anthropic-style tool hint combinations when present in mixed gateway payloads
Anthropic request-side updates
- Expanded extraction for metadata, service-tier, and tool parallelism semantics
- Added explicit `tool_choice.type == "none"` parity in decode/encode
- Preserves bridge/runtime extension fields in `extra`
Hybrid payload coverage added
Added fixture/test coverage for mixed/provider patterns:
- vLLM-style Anthropic and OpenAI Responses hybrids
- LiteLLM hybrid patterns for Anthropic and Responses
- SGLang Responses extension payloads
Consumer blast-radius updates
Because request IR added new fields and a new `ContentPart` variant, downstream consumers were updated:
- `crates/adaptive`
- `crates/ffi` tests
- `crates/wasm` tests
- `crates/python`
Scope note
This PR intentionally avoids a larger architectural shift. It keeps the current `AnnotatedLlmRequest` / `AnnotatedLlmResponse` IR approach and expands extraction additively.
Validation performed
- `uv run pre-commit run --all-files`
- `cargo test -p nemo-flow-adaptive`
- `cargo test -p nemo-flow-ffi`
- `cargo test -p nemo-flow-wasm`
- `cargo test -p nemo-flow-python`
- `cargo test -p nemo-flow codec::`
- Live OpenAI Responses smoke test against the real API
- Live OpenAI Responses mixed tool-follow-up `input` round-trip test against the real API
- Live Anthropic Messages smoke test against the real API
Live validation notes
Live provider validation covered:
- OpenAI Responses request/response decode and encode behavior
- OpenAI Responses usage detail preservation for `input_tokens_details.cached_tokens` and `output_tokens_details.reasoning_tokens`
- OpenAI mixed `input` array round-trip behavior using a real tool-calling follow-up request
- Anthropic Messages response preservation for `type` and `stop_reason`
Remaining limitations
- This is still not exhaustive gateway conformance testing for every provider bridge variant
- Hybrid gateway behavior is still primarily fixture-backed rather than live-provider-backed
## Summary by CodeRabbit
## Release Notes
* **New Features**
* Added support for multimodal message content including images alongside text.
* Introduced parallel tool execution control to optimize tool-calling behavior.
* Expanded request and response metadata fields for improved API compatibility (store, user, metadata, service tier, reasoning controls, and token limits).
* **Bug Fixes**
* Improved text extraction from multimodal content to correctly handle image URLs.
* **Tests**
* Updated test fixtures to support expanded request/response schema.
[](https://app.coderabbit.ai/change-stack/NVIDIA/NeMo-Flow/pull/76)
Authors:
- https://github.com/afourniernv
Approvers:
- Will Killian (https://github.com/willkill07)
URL: NVIDIA#761 parent d5798c2 commit 704428b
31 files changed
Lines changed: 2078 additions & 75 deletions
File tree
- crates
- adaptive
- src
- acg
- tests
- integration
- unit
- acg
- core
- src/codec
- tests
- integration
- unit
- codec
- ffi/tests
- integration
- unit
- python
- src/py_types
- tests/coverage
- wasm/tests/coverage
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
147 | 147 | | |
148 | 148 | | |
149 | 149 | | |
150 | | - | |
151 | | - | |
152 | | - | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
153 | 153 | | |
154 | 154 | | |
155 | 155 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
188 | 188 | | |
189 | 189 | | |
190 | 190 | | |
191 | | - | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
192 | 197 | | |
193 | 198 | | |
194 | 199 | | |
| |||
Lines changed: 26 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
143 | 143 | | |
144 | 144 | | |
145 | 145 | | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
146 | 159 | | |
147 | 160 | | |
148 | 161 | | |
| |||
188 | 201 | | |
189 | 202 | | |
190 | 203 | | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
191 | 217 | | |
192 | 218 | | |
193 | 219 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
120 | 120 | | |
121 | 121 | | |
122 | 122 | | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
123 | 136 | | |
124 | 137 | | |
125 | 138 | | |
| |||
Lines changed: 52 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
79 | 79 | | |
80 | 80 | | |
81 | 81 | | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
82 | 95 | | |
83 | 96 | | |
84 | 97 | | |
| |||
100 | 113 | | |
101 | 114 | | |
102 | 115 | | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
103 | 129 | | |
104 | 130 | | |
105 | 131 | | |
| |||
128 | 154 | | |
129 | 155 | | |
130 | 156 | | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
131 | 170 | | |
132 | 171 | | |
133 | 172 | | |
| |||
167 | 206 | | |
168 | 207 | | |
169 | 208 | | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
170 | 222 | | |
171 | 223 | | |
172 | 224 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
74 | 87 | | |
75 | 88 | | |
76 | 89 | | |
| |||
110 | 123 | | |
111 | 124 | | |
112 | 125 | | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
113 | 139 | | |
114 | 140 | | |
115 | 141 | | |
| |||
139 | 165 | | |
140 | 166 | | |
141 | 167 | | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
142 | 181 | | |
143 | 182 | | |
144 | 183 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
97 | 97 | | |
98 | 98 | | |
99 | 99 | | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
100 | 113 | | |
101 | 114 | | |
102 | 115 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
37 | 50 | | |
38 | 51 | | |
39 | 52 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| |||
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
20 | 34 | | |
21 | 35 | | |
22 | 36 | | |
| |||
110 | 124 | | |
111 | 125 | | |
112 | 126 | | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
Lines changed: 13 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
179 | 179 | | |
180 | 180 | | |
181 | 181 | | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
182 | 195 | | |
183 | 196 | | |
184 | 197 | | |
| |||
0 commit comments