adk-model 2.3.0

LLM model integrations for Rust Agent Development Kit (ADK-Rust) (Gemini, OpenAI, Claude, DeepSeek, etc.)
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
//! Type conversion utilities for DeepSeek API.

use crate::attachment;
use adk_core::{Content, FinishReason, LlmResponse, Part, UsageMetadata};
use serde::{Deserialize, Serialize};
use serde_json::Value;

/// DeepSeek chat message.
#[derive(Debug, Clone, Deserialize)]
pub struct Message {
    pub role: String,
    pub content: Option<String>,
    #[serde(skip)]
    pub content_parts: Option<Vec<Value>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub name: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub tool_calls: Option<Vec<ToolCall>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub tool_call_id: Option<String>,
    /// Reasoning content from thinking mode (only in responses).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub reasoning_content: Option<String>,
}

impl Serialize for Message {
    fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
        use serde::ser::SerializeMap;
        let mut map = serializer.serialize_map(None)?;
        map.serialize_entry("role", &self.role)?;
        if let Some(parts) = &self.content_parts {
            map.serialize_entry("content", parts)?;
        } else {
            map.serialize_entry("content", &self.content)?;
        }
        if let Some(name) = &self.name {
            map.serialize_entry("name", name)?;
        }
        if let Some(calls) = &self.tool_calls {
            map.serialize_entry("tool_calls", calls)?;
        }
        if let Some(id) = &self.tool_call_id {
            map.serialize_entry("tool_call_id", id)?;
        }
        if let Some(reasoning) = &self.reasoning_content {
            map.serialize_entry("reasoning_content", reasoning)?;
        }
        map.end()
    }
}

/// Tool call in a message.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ToolCall {
    pub id: String,
    #[serde(rename = "type")]
    pub call_type: String,
    pub function: FunctionCall,
}

/// Function call details.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FunctionCall {
    pub name: String,
    pub arguments: String,
}

/// Tool definition for DeepSeek.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Tool {
    #[serde(rename = "type")]
    pub tool_type: String,
    pub function: FunctionDef,
}

/// Function definition.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FunctionDef {
    pub name: String,
    pub description: String,
    pub parameters: Value,
    /// When `true` (beta), the model strictly follows the JSON schema.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub strict: Option<bool>,
}

/// DeepSeek chat completion request.
#[derive(Debug, Clone, Serialize)]
pub struct ChatCompletionRequest {
    pub model: String,
    pub messages: Vec<Message>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub temperature: Option<f32>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub top_p: Option<f32>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub max_tokens: Option<u32>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub stream: Option<bool>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub tools: Option<Vec<Tool>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub response_format: Option<ResponseFormat>,
    /// Thinking mode configuration (`{"type": "enabled"}` or `{"type": "disabled"}`).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub thinking: Option<ThinkingConfig>,
    /// Reasoning effort level (`"high"` or `"max"`).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub reasoning_effort: Option<String>,
    /// Stop sequences.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub stop: Option<Vec<String>>,
}

/// Response format configuration.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ResponseFormat {
    #[serde(rename = "type")]
    pub format_type: String,
}

/// Thinking mode configuration.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ThinkingConfig {
    #[serde(rename = "type")]
    pub thinking_type: String,
}

impl ThinkingConfig {
    /// Create a thinking config that enables chain-of-thought reasoning.
    pub fn enabled() -> Self {
        Self { thinking_type: "enabled".to_string() }
    }

    /// Create a thinking config that explicitly disables thinking.
    pub fn disabled() -> Self {
        Self { thinking_type: "disabled".to_string() }
    }
}

/// DeepSeek chat completion response.
#[derive(Debug, Clone, Deserialize)]
pub struct ChatCompletionResponse {
    /// Response ID (used for API tracking).
    #[serde(rename = "id")]
    pub _id: String,
    /// Object type (always "chat.completion").
    #[serde(rename = "object")]
    pub _object: String,
    /// Unix timestamp of creation.
    #[serde(rename = "created")]
    pub _created: u64,
    /// Model used for completion.
    #[serde(rename = "model")]
    pub _model: String,
    pub choices: Vec<Choice>,
    #[serde(default)]
    pub usage: Option<Usage>,
}

/// Response choice.
#[derive(Debug, Clone, Deserialize)]
pub struct Choice {
    /// Choice index in multi-choice responses.
    #[serde(rename = "index")]
    pub _index: u32,
    pub message: Option<Message>,
    pub delta: Option<DeltaMessage>,
    pub finish_reason: Option<String>,
}

/// Streaming delta message.
#[derive(Debug, Clone, Deserialize, Default)]
pub struct DeltaMessage {
    /// Role in the message (assistant, etc.).
    #[serde(default, rename = "role")]
    pub _role: Option<String>,
    #[serde(default)]
    pub content: Option<String>,
    #[serde(default)]
    pub reasoning_content: Option<String>,
    #[serde(default)]
    pub tool_calls: Option<Vec<DeltaToolCall>>,
}

/// Streaming delta tool call.
#[derive(Debug, Clone, Deserialize)]
pub struct DeltaToolCall {
    pub index: u32,
    #[serde(default)]
    pub id: Option<String>,
    /// Tool call type (always "function").
    #[serde(rename = "type", default)]
    pub _call_type: Option<String>,
    #[serde(default)]
    pub function: Option<DeltaFunction>,
}

/// Streaming delta function.
#[derive(Debug, Clone, Deserialize, Default)]
pub struct DeltaFunction {
    #[serde(default)]
    pub name: Option<String>,
    #[serde(default)]
    pub arguments: Option<String>,
}

/// Token usage information.
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct Usage {
    pub prompt_tokens: u32,
    pub completion_tokens: u32,
    pub total_tokens: u32,
    /// Tokens used for reasoning (thinking mode).
    #[serde(default)]
    pub reasoning_tokens: Option<u32>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub completion_tokens_details: Option<Value>,
    /// Cache hit tokens for prefix caching.
    #[serde(default)]
    pub prompt_cache_hit_tokens: Option<u32>,
    /// Non-cached input tokens.
    #[serde(default)]
    pub prompt_cache_miss_tokens: Option<u32>,
}

pub fn usage(u: &Usage) -> UsageMetadata {
    UsageMetadata {
        prompt_token_count: u.prompt_tokens as i32,
        candidates_token_count: u.completion_tokens as i32,
        total_token_count: u.total_tokens as i32,
        thinking_token_count: u
            .reasoning_tokens
            .or_else(|| {
                u.completion_tokens_details
                    .as_ref()?
                    .get("reasoning_tokens")?
                    .as_u64()?
                    .try_into()
                    .ok()
            })
            .map(|tokens| tokens as i32),
        cache_read_input_token_count: u.prompt_cache_hit_tokens.map(|tokens| tokens as i32),
        // Cache misses are ordinary input, not separately billed cache writes.
        provider_usage: serde_json::to_value(u).ok(),
        ..Default::default()
    }
}

/// Convert ADK Content to DeepSeek Message.
/// Builds a system message carrying `text`.
pub fn system_message(text: impl Into<String>) -> Message {
    Message {
        role: "system".to_string(),
        content: Some(text.into()),
        content_parts: None,
        name: None,
        tool_calls: None,
        tool_call_id: None,
        reasoning_content: None,
    }
}

pub fn content_to_message(content: &Content) -> Message {
    let role = match content.role.as_str() {
        "model" | "assistant" => "assistant",
        "user" => "user",
        "system" => "system",
        "tool" | "function" => "tool", // DeepSeek uses "tool" for function responses
        other => other,
    };

    let mut text_parts = Vec::new();
    let mut reasoning_parts = Vec::new();
    let mut tool_calls = Vec::new();
    let mut tool_call_id = None;
    let mut content_parts = Vec::new();
    let mut has_image = false;

    for part in &content.parts {
        let previous = text_parts.len();
        match part {
            Part::Text { text } => text_parts.push(text.clone()),
            Part::FunctionCall { name, args, id, .. } => {
                tool_calls.push(ToolCall {
                    id: id.clone().unwrap_or_else(|| format!("call_{}", tool_calls.len())),
                    call_type: "function".to_string(),
                    function: FunctionCall {
                        name: name.clone(),
                        arguments: serde_json::to_string(args).unwrap_or_default(),
                    },
                });
            }
            Part::FunctionResponse { function_response, id, .. } => {
                // Tool response - set tool_call_id and content
                tool_call_id = id.clone();
                text_parts
                    .push(crate::tool_result::serialize_tool_result(&function_response.response));
            }
            Part::InlineData { mime_type, data, .. }
                if role == "user"
                    && matches!(
                        mime_type.as_str(),
                        "image/png" | "image/jpeg" | "image/gif" | "image/webp"
                    ) =>
            {
                has_image = true;
                content_parts.push(serde_json::json!({
                    "type": "image_url",
                    "image_url": {"url": format!("data:{mime_type};base64,{}", attachment::encode_base64(data))}
                }));
            }
            Part::InlineData { mime_type, data, .. } => {
                text_parts.push(attachment::inline_attachment_to_text(mime_type, data));
            }
            Part::FileData { mime_type, file_uri, .. } => {
                text_parts.push(attachment::file_attachment_to_text(mime_type, file_uri));
            }
            Part::Thinking { thinking, .. } => {
                reasoning_parts.push(thinking.clone());
            }
            // Server-side tool parts are Gemini-specific; skip for DeepSeek
            Part::ServerToolCall { .. } | Part::ServerToolResponse { .. } => {}
            // Embedded resources: text → text; blob → inline-bytes text representation.
            Part::EmbeddedResource { resource } => match resource {
                adk_core::EmbeddedResource::Text(text) => text_parts.push(text.text.clone()),
                adk_core::EmbeddedResource::Blob(blob) => {
                    let mime_type = blob.mime_type.as_deref().unwrap_or("application/octet-stream");
                    text_parts.push(attachment::inline_attachment_to_text(mime_type, &blob.data));
                }
            },
        }
        content_parts.extend(
            text_parts[previous..]
                .iter()
                .map(|text| serde_json::json!({"type":"text", "text":text})),
        );
    }

    // Interrupted calls and cross-provider histories may retain only thinking.
    // DeepSeek rejects an assistant with neither content nor tool_calls; an
    // explicit empty string preserves the reasoning without inventing an answer.
    let content_str = if text_parts.is_empty() {
        (role == "assistant" && tool_calls.is_empty()).then(String::new)
    } else {
        Some(text_parts.join("\n"))
    };
    let reasoning_content =
        if reasoning_parts.is_empty() { None } else { Some(reasoning_parts.join("\n")) };

    Message {
        role: role.to_string(),
        content: content_str,
        content_parts: has_image.then_some(content_parts),
        name: None,
        tool_calls: if tool_calls.is_empty() { None } else { Some(tool_calls) },
        tool_call_id,
        reasoning_content,
    }
}

/// Reasoning that the terminal chunk still owes the consumer.
///
/// With thinking enabled, each `reasoning_content` delta is yielded as a
/// partial `Part::Thinking` while it arrives, so the terminal chunk must not
/// replay `buffer`. With thinking disabled the deltas are buffered and never
/// yielded, so the terminal chunk is the only place they can surface.
///
/// # Example
///
/// ```rust,ignore
/// // thinking enabled: already streamed, nothing left to emit
/// assert!(pending_reasoning(&mut buffer, true).is_none());
/// ```
pub fn pending_reasoning(buffer: &mut String, thinking_enabled: bool) -> Option<String> {
    if thinking_enabled || buffer.is_empty() {
        return None;
    }
    Some(std::mem::take(buffer))
}

/// Parts the terminal chunk of a stream contributes, on top of everything its
/// earlier chunks already yielded.
///
/// ADK accumulates the parts of *every* chunk it receives, partial ones
/// included, so each piece of a response must be emitted exactly once across
/// the stream. The terminal chunk therefore carries only its own `delta` —
/// plus any reasoning that was buffered but never streamed.
///
/// # Example
///
/// ```rust,ignore
/// // The usual DeepSeek finish chunk has an empty delta and contributes nothing.
/// assert!(final_chunk_parts(None, &mut String::new(), false).is_empty());
/// ```
pub fn final_chunk_parts(
    delta: Option<&DeltaMessage>,
    reasoning_buffer: &mut String,
    thinking_enabled: bool,
) -> Vec<Part> {
    let mut parts = Vec::new();
    if let Some(thinking) = pending_reasoning(reasoning_buffer, thinking_enabled) {
        parts.push(Part::Thinking { thinking, signature: None });
    }
    if let Some(text) = delta.and_then(|d| d.content.as_deref())
        && !text.is_empty()
    {
        parts.push(Part::Text { text: text.to_string() });
    }
    parts
}

/// Convert ADK tools to DeepSeek tools.
///
/// When `strict` is `true`, each tool definition includes `"strict": true`
/// for the beta strict tool mode.
pub fn convert_tools(tools: &std::collections::HashMap<String, Value>, strict: bool) -> Vec<Tool> {
    tools
        .values()
        .filter_map(|tool| {
            let name = tool.get("name")?.as_str()?;
            let description = tool.get("description").and_then(|d| d.as_str()).unwrap_or("");
            let parameters = tool.get("parameters").cloned().unwrap_or(serde_json::json!({
                "type": "object",
                "properties": {}
            }));

            Some(Tool {
                tool_type: "function".to_string(),
                function: FunctionDef {
                    name: name.to_string(),
                    description: description.to_string(),
                    parameters,
                    strict: if strict { Some(true) } else { None },
                },
            })
        })
        .collect()
}

/// Convert DeepSeek response to ADK LlmResponse.
pub fn from_response(response: &ChatCompletionResponse) -> LlmResponse {
    let choice = response.choices.first();

    let (content, finish_reason) = if let Some(choice) = choice {
        let finish = choice.finish_reason.as_ref().map(|fr| match fr.as_str() {
            "stop" => FinishReason::Stop,
            "length" => FinishReason::MaxTokens,
            "tool_calls" => FinishReason::Stop,
            "content_filter" => FinishReason::Safety,
            _ => FinishReason::Stop,
        });

        if let Some(msg) = &choice.message {
            let mut parts = Vec::new();

            // Add reasoning content if present (thinking mode)
            if let Some(reasoning) = &msg.reasoning_content
                && !reasoning.is_empty()
            {
                parts.push(Part::Thinking { thinking: reasoning.clone(), signature: None });
            }

            // Add main content
            if let Some(text) = &msg.content
                && !text.is_empty()
            {
                parts.push(Part::Text { text: text.clone() });
            }

            // Add tool calls
            if let Some(tool_calls) = &msg.tool_calls {
                for tc in tool_calls {
                    let args: Value = serde_json::from_str(&tc.function.arguments)
                        .unwrap_or(serde_json::json!({}));
                    parts.push(Part::FunctionCall {
                        name: tc.function.name.clone(),
                        args,
                        id: Some(tc.id.clone()),
                        thought_signature: None,
                    });
                }
            }

            (
                if parts.is_empty() {
                    None
                } else {
                    Some(Content { role: "model".to_string(), parts })
                },
                finish,
            )
        } else {
            (None, finish)
        }
    } else {
        (None, None)
    };

    let usage = response.usage.as_ref().map(usage);

    // A turn that emits tool calls is not complete — tool results must still be
    // processed and sent back to the model (issue #401).
    let turn_complete = content.as_ref().is_none_or(|c| !c.has_function_calls());

    LlmResponse {
        content,
        usage_metadata: usage,
        finish_reason,
        citation_metadata: None,
        partial: false,
        turn_complete,
        interrupted: false,
        error_code: None,
        error_message: None,
        provider_metadata: None,
        interaction_id: None,
    }
}

/// Create a tool call response for accumulated tool calls.
pub fn create_tool_call_response(
    tool_calls: Vec<(String, String, Value)>, // (id, name, args)
    finish_reason: Option<FinishReason>,
    reasoning: Option<String>,
) -> LlmResponse {
    let mut parts: Vec<Part> = Vec::new();

    if let Some(ref text) = reasoning
        && !text.is_empty()
    {
        parts.push(Part::Thinking { thinking: text.clone(), signature: None });
    }

    parts.extend(tool_calls.into_iter().map(|(id, name, args)| Part::FunctionCall {
        name,
        args,
        id: Some(id),
        thought_signature: None,
    }));

    LlmResponse {
        content: Some(Content { role: "model".to_string(), parts }),
        usage_metadata: None,
        finish_reason,
        citation_metadata: None,
        partial: false,
        // This response carries tool calls, so the turn continues (issue #401).
        turn_complete: false,
        interrupted: false,
        error_code: None,
        error_message: None,
        provider_metadata: None,
        interaction_id: None,
    }
}

#[cfg(test)]
mod tests {
    #[test]
    fn pending_reasoning_is_owed_only_when_it_was_never_streamed() {
        // Thinking enabled: the deltas were yielded as they arrived.
        let mut buffer = String::from("because");
        assert_eq!(pending_reasoning(&mut buffer, true), None);
        assert_eq!(buffer, "because", "buffer must not be consumed");

        // Thinking disabled: the terminal chunk is the only place it can surface.
        assert_eq!(pending_reasoning(&mut buffer, false), Some("because".to_string()));
        assert!(buffer.is_empty(), "buffer is drained once emitted");
        assert_eq!(pending_reasoning(&mut buffer, false), None);
    }

    #[test]
    fn final_chunk_carries_only_its_own_delta() {
        // Regression: the terminal chunk used to replay the accumulated text
        // buffer on top of the deltas it had already yielded, so consumers that
        // accumulate every chunk saw the whole response twice.
        let delta = DeltaMessage { content: Some("tail".into()), ..Default::default() };
        let parts = final_chunk_parts(Some(&delta), &mut String::new(), false);
        assert_eq!(parts.len(), 1);
        assert!(matches!(&parts[0], Part::Text { text } if text == "tail"));

        // The usual DeepSeek finish chunk has an empty delta.
        assert!(final_chunk_parts(None, &mut String::new(), false).is_empty());
        let empty = DeltaMessage { content: Some(String::new()), ..Default::default() };
        assert!(final_chunk_parts(Some(&empty), &mut String::new(), false).is_empty());
    }

    #[test]
    fn final_chunk_orders_unstreamed_reasoning_before_text() {
        let delta = DeltaMessage { content: Some("answer".into()), ..Default::default() };
        let mut buffer = String::from("because");
        let parts = final_chunk_parts(Some(&delta), &mut buffer, false);
        assert!(matches!(&parts[0], Part::Thinking { thinking, .. } if thinking == "because"));
        assert!(matches!(&parts[1], Part::Text { text } if text == "answer"));
    }

    use super::*;

    #[test]
    fn tool_call_response_is_not_turn_complete() {
        // Issue #401: a response carrying tool calls must not mark the turn complete.
        let resp = create_tool_call_response(
            vec![("call_1".to_string(), "get_weather".to_string(), serde_json::json!({}))],
            Some(FinishReason::Stop),
            None,
        );
        assert!(!resp.turn_complete);
        assert!(resp.content.as_ref().unwrap().has_function_calls());
    }

    #[test]
    fn content_to_message_keeps_inline_attachment_payload() {
        let content = Content {
            role: "user".to_string(),
            parts: vec![Part::inline_data("application/pdf", b"%PDF".to_vec())],
        };
        let message = content_to_message(&content);
        let payload = message.content.unwrap_or_default();
        assert!(payload.contains("application/pdf"));
        assert!(payload.contains("encoding=\"base64\""));
    }

    #[test]
    fn content_to_message_keeps_file_attachment_payload() {
        let content = Content {
            role: "user".to_string(),
            parts: vec![Part::file_data("text/csv", "https://example.com/data.csv")],
        };
        let message = content_to_message(&content);
        let payload = message.content.unwrap_or_default();
        assert!(payload.contains("text/csv"));
        assert!(payload.contains("https://example.com/data.csv"));
    }

    #[test]
    fn thinking_only_history_has_explicit_content() {
        let content = Content {
            role: "model".into(),
            parts: vec![Part::Thinking {
                thinking: "Retained reasoning from an interrupted turn".into(),
                signature: None,
            }],
        };
        let message = content_to_message(&content);
        let json = serde_json::to_value(&message).unwrap();
        assert_eq!(json["content"], "");
        assert_eq!(json["reasoning_content"], "Retained reasoning from an interrupted turn");
        assert!(json.get("tool_calls").is_none());
    }

    #[test]
    fn content_to_message_maps_thinking_to_reasoning_content() {
        let content = Content {
            role: "model".to_string(),
            parts: vec![
                Part::Thinking {
                    thinking: "reason through the tool plan".to_string(),
                    signature: None,
                },
                Part::Text { text: "let me check the prices".to_string() },
            ],
        };

        let message = content_to_message(&content);

        assert_eq!(message.role, "assistant");
        assert_eq!(message.reasoning_content.as_deref(), Some("reason through the tool plan"));
        assert_eq!(message.content.as_deref(), Some("let me check the prices"));
    }
}