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
//! Provider trait and tool-choice abstraction.
//!
//! Why: Different LLM backends (OpenRouter, AWS Bedrock, …) normalise
//! `tool_choice` and token-usage differently on the wire. The agent loop should
//! not branch on the provider; instead it asks a `Provider` to translate a
//! provider-neutral [`ToolChoice`] into the backend's wire format and to extract
//! a canonical [`TokenUsage`] from the response. This keeps per-backend quirks
//! behind one seam (#1021) and feeds fallback-guidance selection in #1032/#1023.
//! What: Defines [`ToolChoice`] (the neutral policy enum) and the [`Provider`]
//! trait with `name`, `map_tool_choice`, `extract_usage`, and
//! `supports_native_tools`.
//! Test: `provider::tests::*` plus per-impl tests in `openrouter` and `bedrock`.
use Value;
use crateChatResponse;
use crateTokenUsage;
/// Provider-neutral tool-choice policy.
///
/// Why: Callers (the agent loop) want to express intent — "don't call tools",
/// "you may call tools", "you must call a tool", or "call this specific
/// function" — without knowing how each backend spells it on the wire. The
/// `Provider` translates this enum via [`Provider::map_tool_choice`].
/// What: `None` disables tools, `Auto` lets the model decide, `Required` forces
/// some tool call, and `Function(name)` forces a specific named function.
/// Test: `openrouter::tests::map_tool_choice_*` cover every variant.
/// A backend that normalises tool-choice and usage for one family of models.
///
/// Why: The agent loop must stay backend-agnostic. By depending on `dyn
/// Provider` it can drive OpenRouter today and Bedrock later without changing
/// the loop — the factory ([`crate::provider::provider_for`]) picks the impl
/// from the model slug.
/// What: Object-safe (`Send + Sync`) trait with the four normalisation hooks the
/// loop needs. Implementations live in `openrouter` and `bedrock`.
/// Test: `openrouter::tests::*`, `bedrock::tests::*`.