horus 0.6.2

A small, modular Rust framework for building coding agents
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
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
//! Native Anthropic Messages API provider.

use reqwest::Client;
use serde_json::Value;
use std::collections::BTreeMap;
use std::collections::BTreeSet;
use std::sync::Arc;

use super::Model;
use super::ModelEventSink;
use super::ModelInfo;
use super::ModelOutput;
use super::ModelRequest;
use super::REPLAY_REASONING_FIELD;
use super::TOOL_ERROR_FIELD;
use super::ToolDefinition;
use super::image_input;
use super::provider::HostedWebSearch;
use super::provider::ModelPreset;
use super::provider::ProviderAuth;
use super::provider::ProviderBuildConfig;
use super::provider::ProviderDefinition;
use super::provider::ReasoningPreset;
use super::transport::MAX_SSE_FRAME_BYTES;
use super::transport::frame_data;
use super::transport::push_sse_chunk;
use super::transport::status_error;
use super::transport::streaming_client;
use super::transport::take_sse_frame;
use super::usage_i64;
use crate::BoxFuture;
use crate::Error;
use crate::Result;
use crate::protocol::FrontendSymbol;
use crate::protocol::ModelEvent;
use crate::protocol::TokenUsage;
use crate::protocol::WebSearchAction;

const API_URL: &str = "https://api.anthropic.com/v1/messages";
const API_VERSION: &str = "2023-06-01";
const MAX_OUTPUT_TOKENS: u64 = 64_000;
const MAX_CONTENT_BLOCKS: usize = 1_024;
const RAW_CONTENT: &str = "_anthropic_content";

const REASONING: &[ReasoningPreset] = &[
    ReasoningPreset {
        id: "low",
        label: "Low",
        description: "Prefer speed and lower cost",
    },
    ReasoningPreset {
        id: "medium",
        label: "Medium",
        description: "Balance reasoning and latency",
    },
    ReasoningPreset {
        id: "high",
        label: "High",
        description: "Anthropic's default reasoning effort",
    },
    ReasoningPreset {
        id: "xhigh",
        label: "Extra high",
        description: "Extended effort for long-horizon work",
    },
    ReasoningPreset {
        id: "max",
        label: "Maximum",
        description: "Use maximum available reasoning",
    },
];

const MODELS: &[ModelPreset] = &[
    ModelPreset {
        id: "claude-sonnet-5",
        label: "Claude Sonnet 5",
        description: "Fast frontier model for coding and agents",
        context_window: 1_000_000,
        reasoning: REASONING,
        default_reasoning: Some("high"),
    },
    ModelPreset {
        id: "claude-opus-4-8",
        label: "Claude Opus 4.8",
        description: "Highest-capability Anthropic model",
        context_window: 1_000_000,
        reasoning: REASONING,
        default_reasoning: Some("high"),
    },
    ModelPreset {
        id: "claude-haiku-4-5",
        label: "Claude Haiku 4.5",
        description: "Fast, economical Anthropic model",
        context_window: 200_000,
        reasoning: &[],
        default_reasoning: None,
    },
];

const SEARCH: &[HostedWebSearch] = &[HostedWebSearch::Off, HostedWebSearch::Live];

/// Anthropic's native Messages API provider.
pub struct Anthropic {
    client: Client,
    api_key: String,
    model: String,
    reasoning_effort: Option<String>,
    web_search: bool,
}

impl Anthropic {
    /// Creates a provider for Anthropic's fixed Messages API endpoint.
    pub fn new(api_key: impl Into<String>, model: impl Into<String>) -> Result<Self> {
        Self::with_client(api_key, model, streaming_client()?)
    }

    fn with_client(
        api_key: impl Into<String>,
        model: impl Into<String>,
        client: Client,
    ) -> Result<Self> {
        let api_key = api_key.into();
        if api_key.trim().is_empty() {
            return Err(Error::Config("ANTHROPIC_API_KEY is empty".into()));
        }
        let model = model.into();
        if model.trim().is_empty() {
            return Err(Error::Config("Anthropic model is empty".into()));
        }
        Ok(Self {
            client,
            api_key,
            model,
            reasoning_effort: None,
            web_search: false,
        })
    }

    /// Enables adaptive thinking at one supported Anthropic effort level.
    pub fn with_reasoning_effort(mut self, effort: impl Into<String>) -> Result<Self> {
        let effort = effort.into();
        if !matches!(effort.as_str(), "low" | "medium" | "high" | "xhigh" | "max") {
            return Err(Error::Config(format!(
                "unsupported Anthropic reasoning effort `{effort}`"
            )));
        }
        self.reasoning_effort = Some(effort);
        Ok(self)
    }

    /// Enables Anthropic-hosted web search.
    #[must_use]
    pub fn with_web_search(mut self) -> Self {
        self.web_search = true;
        self
    }

    async fn send_response(
        &self,
        request: ModelRequest<'_>,
        events: ModelEventSink,
    ) -> Result<ModelOutput> {
        let body = self.request_body(
            request.instructions,
            request.input,
            request.tools,
            request.allow_hosted_tools,
        )?;
        let mut response = self.post(&body).await?;
        let mut bytes = Vec::new();
        let mut stream = StreamState::default();
        let mut stream_bytes = 0;
        while let Some(chunk) = response.chunk().await? {
            push_sse_chunk(&mut bytes, &mut stream_bytes, &chunk, "Anthropic")?;
            while let Some(frame) = take_sse_frame(&mut bytes)? {
                let Some(data) = frame_data(&frame) else {
                    continue;
                };
                stream.apply(serde_json::from_str(&data)?, &events)?;
            }
            if bytes.len() > MAX_SSE_FRAME_BYTES {
                return Err(Error::Provider(
                    "Anthropic SSE frame exceeded size limit".into(),
                ));
            }
        }
        if !stream.stopped {
            return Err(Error::Provider(
                "Anthropic stream ended before message_stop".into(),
            ));
        }
        stream.finish()
    }

    fn request_body(
        &self,
        instructions: &str,
        input: &[Value],
        tools: &[ToolDefinition],
        allow_hosted_tools: bool,
    ) -> Result<Value> {
        let mut body = serde_json::json!({
            "model": self.model,
            "max_tokens": MAX_OUTPUT_TOKENS,
            "system": instructions,
            "messages": translate_messages(input)?,
            "tools": wire_tools(tools, self.web_search && allow_hosted_tools),
            "cache_control": {"type": "ephemeral"},
            "stream": true
        });
        self.apply_reasoning(&mut body);
        Ok(body)
    }

    fn apply_reasoning(&self, body: &mut Value) {
        if let Some(effort) = &self.reasoning_effort {
            body["thinking"] = serde_json::json!({"type": "adaptive"});
            body["output_config"] = serde_json::json!({"effort": effort});
        }
    }

    async fn post(&self, body: &Value) -> Result<reqwest::Response> {
        let response = self
            .client
            .post(API_URL)
            .header("x-api-key", &self.api_key)
            .header("anthropic-version", API_VERSION)
            .json(body)
            .send()
            .await?;
        if response.status().is_success() {
            Ok(response)
        } else {
            Err(status_error(response, "Anthropic").await)
        }
    }
}

impl Model for Anthropic {
    fn info(&self) -> ModelInfo {
        ModelInfo {
            model: self.model.clone(),
            reasoning_effort: self.reasoning_effort.clone(),
        }
    }

    fn supports_image_input(&self) -> bool {
        true
    }

    fn respond<'a>(
        &'a self,
        request: ModelRequest<'a>,
        events: ModelEventSink,
    ) -> BoxFuture<'a, Result<ModelOutput>> {
        Box::pin(self.send_response(request, events))
    }
}

#[derive(Default)]
struct StreamState {
    blocks: BTreeMap<usize, Value>,
    partial_json: BTreeMap<usize, String>,
    web_queries: BTreeMap<String, Option<String>>,
    usage: Usage,
    stop_reason: Option<String>,
    stopped: bool,
}

impl StreamState {
    fn apply(&mut self, event: Value, events: &ModelEventSink) -> Result<()> {
        match event.get("type").and_then(Value::as_str) {
            Some("message_start") => self.usage.update(event.pointer("/message/usage"))?,
            Some("content_block_start") => self.start_block(&event, events)?,
            Some("content_block_delta") => self.delta_block(&event, events)?,
            Some("content_block_stop") => self.stop_block(&event)?,
            Some("message_delta") => {
                self.usage.update(event.get("usage"))?;
                self.stop_reason = event
                    .pointer("/delta/stop_reason")
                    .and_then(Value::as_str)
                    .map(ToString::to_string);
            }
            Some("message_stop") => self.stopped = true,
            Some("error") => {
                let message = event
                    .pointer("/error/message")
                    .and_then(Value::as_str)
                    .unwrap_or("Anthropic stream error");
                return Err(Error::Provider(message.to_string().into()));
            }
            Some("ping") | None | Some(_) => {}
        }
        Ok(())
    }

    fn start_block(&mut self, event: &Value, events: &ModelEventSink) -> Result<()> {
        let index = event_index(event)?;
        if self.blocks.contains_key(&index) {
            return Err(Error::Provider(
                format!("Anthropic repeated content block index {index}").into(),
            ));
        }
        if self.blocks.len() >= MAX_CONTENT_BLOCKS {
            return Err(Error::Provider(
                format!("Anthropic returned more than {MAX_CONTENT_BLOCKS} content blocks").into(),
            ));
        }
        let block = event
            .get("content_block")
            .cloned()
            .ok_or_else(|| Error::Provider("Anthropic content block omitted value".into()))?;
        if block.get("type").and_then(Value::as_str) == Some("server_tool_use")
            && block.get("name").and_then(Value::as_str) == Some("web_search")
        {
            let id = required_string(&block, "id")?.to_string();
            let query = block
                .pointer("/input/query")
                .and_then(Value::as_str)
                .map(ToString::to_string);
            self.web_queries.insert(id.clone(), query);
            events(ModelEvent::WebSearchStarted { call_id: id })?;
        }
        if block.get("type").and_then(Value::as_str) == Some("web_search_tool_result") {
            let call_id = required_string(&block, "tool_use_id")?.to_string();
            let query = self.web_queries.get(&call_id).cloned().flatten();
            events(ModelEvent::WebSearchCompleted {
                call_id,
                action: WebSearchAction::Search { query },
            })?;
        }
        self.blocks.insert(index, block);
        Ok(())
    }

    fn delta_block(&mut self, event: &Value, events: &ModelEventSink) -> Result<()> {
        let index = event_index(event)?;
        let delta = event
            .get("delta")
            .ok_or_else(|| Error::Provider("Anthropic content delta omitted value".into()))?;
        let block = self
            .blocks
            .get_mut(&index)
            .ok_or_else(|| Error::Provider("Anthropic delta referenced unknown block".into()))?;
        match delta.get("type").and_then(Value::as_str) {
            Some("text_delta") => {
                let text = required_string(delta, "text")?;
                append_string(block, "text", text);
                events(ModelEvent::TextDelta(text.to_string()))?;
            }
            Some("thinking_delta") => {
                let thinking = required_string(delta, "thinking")?;
                append_string(block, "thinking", thinking);
                events(ModelEvent::ReasoningDelta(thinking.to_string()))?;
            }
            Some("signature_delta") => {
                block["signature"] =
                    Value::String(required_string(delta, "signature")?.to_string());
            }
            Some("input_json_delta") => self
                .partial_json
                .entry(index)
                .or_default()
                .push_str(required_string(delta, "partial_json")?),
            Some("citations_delta") => {
                if let Some(citation) = delta.get("citation") {
                    let citations = block
                        .as_object_mut()
                        .ok_or_else(|| {
                            Error::Provider("Anthropic content block was not an object".into())
                        })?
                        .entry("citations")
                        .or_insert_with(|| Value::Array(Vec::new()));
                    citations
                        .as_array_mut()
                        .ok_or_else(|| {
                            Error::Provider("Anthropic citations were not an array".into())
                        })?
                        .push(citation.clone());
                }
            }
            None | Some(_) => {}
        }
        Ok(())
    }

    fn stop_block(&mut self, event: &Value) -> Result<()> {
        let index = event_index(event)?;
        let Some(partial) = self.partial_json.remove(&index) else {
            return Ok(());
        };
        let input: Value = serde_json::from_str(&partial)?;
        let block = self
            .blocks
            .get_mut(&index)
            .ok_or_else(|| Error::Provider("Anthropic stop referenced unknown block".into()))?;
        block["input"] = input;
        if block.get("type").and_then(Value::as_str) == Some("server_tool_use")
            && block.get("name").and_then(Value::as_str) == Some("web_search")
        {
            let id = required_string(block, "id")?.to_string();
            let query = block
                .pointer("/input/query")
                .and_then(Value::as_str)
                .map(ToString::to_string);
            self.web_queries.insert(id, query);
        }
        Ok(())
    }

    fn finish(self) -> Result<ModelOutput> {
        let content = self.blocks.into_values().collect::<Vec<_>>();
        let calls = content
            .iter()
            .filter(|block| block.get("type").and_then(Value::as_str) == Some("tool_use"))
            .map(|block| {
                let arguments = block
                    .get("input")
                    .cloned()
                    .unwrap_or_else(|| serde_json::json!({}));
                Ok(serde_json::json!({
                    "type": "function_call",
                    "call_id": required_string(block, "id")?,
                    "name": required_string(block, "name")?,
                    "arguments": serde_json::to_string(&arguments)?
                }))
            })
            .collect::<Result<Vec<_>>>()?;
        let visible = content
            .iter()
            .filter(|block| block.get("type").and_then(Value::as_str) == Some("text"))
            .map(|block| {
                serde_json::json!({
                    "type": "output_text",
                    "text": block.get("text").and_then(Value::as_str).unwrap_or_default()
                })
            })
            .collect::<Vec<_>>();
        let mut message = serde_json::json!({
            "type": "message",
            "role": "assistant",
            "content": visible
        });
        let reasoning = content
            .iter()
            .filter(|block| block.get("type").and_then(Value::as_str) == Some("thinking"))
            .filter_map(|block| block.get("thinking").and_then(Value::as_str))
            .collect::<Vec<_>>()
            .join("\n");
        if !reasoning.is_empty() {
            message[REPLAY_REASONING_FIELD] = Value::String(reasoning);
        }
        message[RAW_CONTENT] = Value::Array(content);
        let mut output = vec![message];
        output.extend(calls);
        ModelOutput::from_output(
            output,
            self.stop_reason.as_deref() != Some("pause_turn"),
            self.usage.finish()?,
        )
    }
}

#[derive(Default)]
struct Usage {
    input: i64,
    cache_read: i64,
    cache_write: i64,
    output: i64,
    thinking: i64,
}

impl Usage {
    fn update(&mut self, usage: Option<&Value>) -> Result<()> {
        let Some(usage) = usage else {
            return Ok(());
        };
        update_i64(&mut self.input, usage, "/input_tokens")?;
        update_i64(&mut self.cache_read, usage, "/cache_read_input_tokens")?;
        update_i64(&mut self.cache_write, usage, "/cache_creation_input_tokens")?;
        update_i64(&mut self.output, usage, "/output_tokens")?;
        update_i64(
            &mut self.thinking,
            usage,
            "/output_tokens_details/thinking_tokens",
        )?;
        Ok(())
    }

    fn finish(self) -> Result<TokenUsage> {
        let input_tokens = self
            .input
            .checked_add(self.cache_read)
            .and_then(|tokens| tokens.checked_add(self.cache_write))
            .ok_or_else(|| Error::Provider("Anthropic token usage overflowed".into()))?;
        let total_tokens = input_tokens
            .checked_add(self.output)
            .ok_or_else(|| Error::Provider("Anthropic token usage overflowed".into()))?;
        Ok(TokenUsage {
            input_tokens,
            cached_input_tokens: self.cache_read,
            cache_write_input_tokens: self.cache_write,
            output_tokens: self.output,
            reasoning_output_tokens: self.thinking,
            total_tokens,
        })
    }
}

fn translate_messages(input: &[Value]) -> Result<Vec<Value>> {
    let mut messages = Vec::new();
    let mut preserved_tools = BTreeSet::new();
    for item in input {
        let kind = item
            .get("type")
            .and_then(Value::as_str)
            .or_else(|| item.get("role").is_some().then_some("message"));
        match kind {
            Some("message") => {
                let role = item
                    .get("role")
                    .and_then(Value::as_str)
                    .ok_or_else(|| Error::Provider("history message omitted role".into()))?;
                if let Some(content) = item.get(RAW_CONTENT).and_then(Value::as_array) {
                    preserved_tools.extend(
                        content
                            .iter()
                            .filter(|block| {
                                block.get("type").and_then(Value::as_str) == Some("tool_use")
                            })
                            .filter_map(|block| block.get("id").and_then(Value::as_str))
                            .map(ToString::to_string),
                    );
                    push_message(&mut messages, role, content.clone());
                } else {
                    let mut blocks = Vec::new();
                    for part in item
                        .get("content")
                        .and_then(Value::as_array)
                        .into_iter()
                        .flatten()
                    {
                        match part.get("type").and_then(Value::as_str) {
                            Some("input_text" | "output_text") => {
                                blocks.push(serde_json::json!({
                                    "type": "text",
                                    "text": part.get("text").and_then(Value::as_str).unwrap_or_default()
                                }));
                            }
                            Some("input_image") => {
                                let Some((media_type, data)) = image_input(part, "Anthropic")?
                                else {
                                    continue;
                                };
                                blocks.push(serde_json::json!({
                                    "type": "image",
                                    "source": {
                                        "type": "base64",
                                        "media_type": media_type,
                                        "data": data
                                    }
                                }));
                            }
                            None | Some(_) => {}
                        }
                    }
                    push_message(&mut messages, role, blocks);
                }
            }
            Some("function_call") => {
                let call_id = required_string(item, "call_id")?;
                if !preserved_tools.contains(call_id) {
                    push_message(
                        &mut messages,
                        "assistant",
                        vec![serde_json::json!({
                            "type": "tool_use",
                            "id": call_id,
                            "name": required_string(item, "name")?,
                            "input": serde_json::from_str::<Value>(required_string(item, "arguments")?)?
                        })],
                    );
                }
            }
            Some("function_call_output") => push_message(
                &mut messages,
                "user",
                vec![serde_json::json!({
                    "type": "tool_result",
                    "tool_use_id": required_string(item, "call_id")?,
                    "content": string_field(item, "output")?,
                    "is_error": item.get(TOOL_ERROR_FIELD).and_then(Value::as_bool).unwrap_or(false)
                })],
            ),
            None | Some(_) => {}
        }
    }
    if messages.is_empty() {
        return Err(Error::Provider("Anthropic request has no messages".into()));
    }
    Ok(messages)
}

fn push_message(messages: &mut Vec<Value>, role: &str, blocks: Vec<Value>) {
    if blocks.is_empty() {
        return;
    }
    if let Some(last) = messages.last_mut()
        && last.get("role").and_then(Value::as_str) == Some(role)
        && let Some(content) = last.get_mut("content").and_then(Value::as_array_mut)
    {
        content.extend(blocks);
        return;
    }
    messages.push(serde_json::json!({"role": role, "content": blocks}));
}

fn wire_tools(tools: &[ToolDefinition], web_search: bool) -> Vec<Value> {
    let mut output = tools
        .iter()
        .map(|tool| {
            serde_json::json!({
                "name": tool.name,
                "description": tool.description,
                "input_schema": tool.parameters
            })
        })
        .collect::<Vec<_>>();
    if web_search {
        output.push(serde_json::json!({
            "type": "web_search_20260318",
            "name": "web_search"
        }));
    }
    output
}

fn event_index(event: &Value) -> Result<usize> {
    event
        .get("index")
        .and_then(Value::as_u64)
        .and_then(|index| usize::try_from(index).ok())
        .ok_or_else(|| Error::Provider("Anthropic event omitted block index".into()))
}

fn required_string<'a>(value: &'a Value, field: &str) -> Result<&'a str> {
    let value = string_field(value, field)?;
    if value.is_empty() {
        return Err(Error::Provider(
            format!("Anthropic value omitted {field}").into(),
        ));
    }
    Ok(value)
}

fn string_field<'a>(value: &'a Value, field: &str) -> Result<&'a str> {
    value
        .get(field)
        .and_then(Value::as_str)
        .ok_or_else(|| Error::Provider(format!("Anthropic value omitted {field}").into()))
}

fn append_string(value: &mut Value, field: &str, addition: &str) {
    if let Some(Value::String(current)) = value.get_mut(field) {
        current.push_str(addition);
    } else {
        value[field] = Value::String(addition.to_string());
    }
}

fn update_i64(target: &mut i64, value: &Value, path: &str) -> Result<()> {
    if let Some(value) = usage_i64(Some(value), path, "Anthropic")? {
        *target = value;
    }
    Ok(())
}

pub(super) const fn provider() -> ProviderDefinition {
    ProviderDefinition::new(
        "anthropic",
        "Anthropic",
        FrontendSymbol::Claude,
        "Native Messages API with adaptive thinking",
        ProviderAuth::ApiKey("ANTHROPIC_API_KEY"),
        MODELS,
        SEARCH,
        build_provider,
    )
    .with_image_input()
}

fn build_provider(config: ProviderBuildConfig) -> Result<Arc<dyn Model>> {
    let api_key = config.credential.into_api_key("anthropic")?;
    let provider = Anthropic::with_client(api_key, config.model, config.http)?;
    let provider = match config.reasoning_effort {
        Some(effort) => provider.with_reasoning_effort(effort)?,
        None => provider,
    };
    let provider = if config.web_search == HostedWebSearch::Live {
        provider.with_web_search()
    } else {
        provider
    };
    Ok(Arc::new(provider))
}

#[cfg(test)]
#[path = "anthropic_tests.rs"]
mod tests;