anthropic 0.68.1__py3-none-any.whl → 0.69.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- anthropic/_version.py +1 -1
- anthropic/lib/streaming/_beta_messages.py +1 -0
- anthropic/lib/tools/__init__.py +7 -0
- anthropic/lib/tools/_beta_builtin_memory_tool.py +245 -0
- anthropic/lib/tools/_beta_functions.py +30 -0
- anthropic/lib/tools/_beta_runner.py +18 -6
- anthropic/resources/beta/files.py +10 -10
- anthropic/resources/beta/messages/batches.py +12 -12
- anthropic/resources/beta/messages/messages.py +59 -15
- anthropic/resources/beta/models.py +4 -4
- anthropic/resources/completions.py +2 -2
- anthropic/resources/models.py +4 -4
- anthropic/types/beta/__init__.py +35 -0
- anthropic/types/beta/beta_clear_tool_uses_20250919_edit_param.py +38 -0
- anthropic/types/beta/beta_clear_tool_uses_20250919_edit_response.py +18 -0
- anthropic/types/beta/beta_context_management_config_param.py +15 -0
- anthropic/types/beta/beta_context_management_response.py +13 -0
- anthropic/types/beta/beta_count_tokens_context_management_response.py +10 -0
- anthropic/types/beta/beta_input_tokens_clear_at_least_param.py +13 -0
- anthropic/types/beta/beta_input_tokens_trigger_param.py +13 -0
- anthropic/types/beta/beta_memory_tool_20250818_command.py +26 -0
- anthropic/types/beta/beta_memory_tool_20250818_create_command.py +18 -0
- anthropic/types/beta/beta_memory_tool_20250818_delete_command.py +15 -0
- anthropic/types/beta/beta_memory_tool_20250818_insert_command.py +21 -0
- anthropic/types/beta/beta_memory_tool_20250818_param.py +23 -0
- anthropic/types/beta/beta_memory_tool_20250818_rename_command.py +18 -0
- anthropic/types/beta/beta_memory_tool_20250818_str_replace_command.py +21 -0
- anthropic/types/beta/beta_memory_tool_20250818_view_command.py +19 -0
- anthropic/types/beta/beta_message.py +4 -0
- anthropic/types/beta/beta_message_tokens_count.py +6 -0
- anthropic/types/beta/beta_raw_message_delta_event.py +4 -0
- anthropic/types/beta/beta_stop_reason.py +3 -1
- anthropic/types/beta/beta_tool_union_param.py +2 -0
- anthropic/types/beta/beta_tool_uses_keep_param.py +13 -0
- anthropic/types/beta/beta_tool_uses_trigger_param.py +13 -0
- anthropic/types/beta/message_count_tokens_params.py +7 -1
- anthropic/types/beta/message_create_params.py +4 -0
- anthropic/types/model.py +2 -0
- anthropic/types/model_param.py +2 -0
- anthropic/types/stop_reason.py +3 -1
- {anthropic-0.68.1.dist-info → anthropic-0.69.0.dist-info}/METADATA +19 -19
- {anthropic-0.68.1.dist-info → anthropic-0.69.0.dist-info}/RECORD +44 -26
- {anthropic-0.68.1.dist-info → anthropic-0.69.0.dist-info}/WHEEL +0 -0
- {anthropic-0.68.1.dist-info → anthropic-0.69.0.dist-info}/licenses/LICENSE +0 -0
anthropic/_version.py
CHANGED
|
@@ -486,6 +486,7 @@ def accumulate_event(
|
|
|
486
486
|
current_snapshot.stop_reason = event.delta.stop_reason
|
|
487
487
|
current_snapshot.stop_sequence = event.delta.stop_sequence
|
|
488
488
|
current_snapshot.usage.output_tokens = event.usage.output_tokens
|
|
489
|
+
current_snapshot.context_management = event.context_management
|
|
489
490
|
|
|
490
491
|
# Update other usage fields if they exist in the event
|
|
491
492
|
if event.usage.input_tokens is not None:
|
anthropic/lib/tools/__init__.py
CHANGED
|
@@ -2,19 +2,26 @@ from ._beta_runner import BetaToolRunner, BetaAsyncToolRunner, BetaStreamingTool
|
|
|
2
2
|
from ._beta_functions import (
|
|
3
3
|
BetaFunctionTool,
|
|
4
4
|
BetaAsyncFunctionTool,
|
|
5
|
+
BetaBuiltinFunctionTool,
|
|
5
6
|
BetaFunctionToolResultType,
|
|
7
|
+
BetaAsyncBuiltinFunctionTool,
|
|
6
8
|
beta_tool,
|
|
7
9
|
beta_async_tool,
|
|
8
10
|
)
|
|
11
|
+
from ._beta_builtin_memory_tool import BetaAbstractMemoryTool, BetaAsyncAbstractMemoryTool
|
|
9
12
|
|
|
10
13
|
__all__ = [
|
|
11
14
|
"beta_tool",
|
|
12
15
|
"beta_async_tool",
|
|
13
16
|
"BetaFunctionTool",
|
|
14
17
|
"BetaAsyncFunctionTool",
|
|
18
|
+
"BetaBuiltinFunctionTool",
|
|
19
|
+
"BetaAsyncBuiltinFunctionTool",
|
|
15
20
|
"BetaToolRunner",
|
|
16
21
|
"BetaAsyncStreamingToolRunner",
|
|
17
22
|
"BetaStreamingToolRunner",
|
|
18
23
|
"BetaAsyncToolRunner",
|
|
19
24
|
"BetaFunctionToolResultType",
|
|
25
|
+
"BetaAbstractMemoryTool",
|
|
26
|
+
"BetaAsyncAbstractMemoryTool",
|
|
20
27
|
]
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from abc import abstractmethod
|
|
4
|
+
from typing import TYPE_CHECKING, Any, cast
|
|
5
|
+
from typing_extensions import override, assert_never
|
|
6
|
+
|
|
7
|
+
from ..._models import construct_type_unchecked
|
|
8
|
+
from ...types.beta import (
|
|
9
|
+
BetaMemoryTool20250818Param,
|
|
10
|
+
BetaMemoryTool20250818Command,
|
|
11
|
+
BetaCacheControlEphemeralParam,
|
|
12
|
+
BetaMemoryTool20250818ViewCommand,
|
|
13
|
+
BetaMemoryTool20250818CreateCommand,
|
|
14
|
+
BetaMemoryTool20250818DeleteCommand,
|
|
15
|
+
BetaMemoryTool20250818InsertCommand,
|
|
16
|
+
BetaMemoryTool20250818RenameCommand,
|
|
17
|
+
BetaMemoryTool20250818StrReplaceCommand,
|
|
18
|
+
)
|
|
19
|
+
from ._beta_functions import BetaBuiltinFunctionTool, BetaFunctionToolResultType, BetaAsyncBuiltinFunctionTool
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class BetaAbstractMemoryTool(BetaBuiltinFunctionTool):
|
|
23
|
+
"""Abstract base class for memory tool implementations.
|
|
24
|
+
|
|
25
|
+
This class provides the interface for implementing a custom memory backend for Claude.
|
|
26
|
+
|
|
27
|
+
Subclass this to create your own memory storage solution (e.g., database, cloud storage, encrypted files, etc.).
|
|
28
|
+
|
|
29
|
+
Example usage:
|
|
30
|
+
|
|
31
|
+
```py
|
|
32
|
+
class MyMemoryTool(BetaAbstractMemoryTool):
|
|
33
|
+
def view(self, command: BetaMemoryTool20250818ViewCommand) -> BetaFunctionToolResultType:
|
|
34
|
+
...
|
|
35
|
+
return "view result"
|
|
36
|
+
|
|
37
|
+
def create(self, command: BetaMemoryTool20250818CreateCommand) -> BetaFunctionToolResultType:
|
|
38
|
+
...
|
|
39
|
+
return "created successfully"
|
|
40
|
+
|
|
41
|
+
# ... implement other abstract methods
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
client = Anthropic()
|
|
45
|
+
memory_tool = MyMemoryTool()
|
|
46
|
+
message = client.beta.messages.run_tools(
|
|
47
|
+
model="claude-sonnet-4-5",
|
|
48
|
+
messages=[{"role": "user", "content": "Remember that I like coffee"}],
|
|
49
|
+
tools=[memory_tool],
|
|
50
|
+
).until_done()
|
|
51
|
+
```
|
|
52
|
+
"""
|
|
53
|
+
|
|
54
|
+
def __init__(self, *, cache_control: BetaCacheControlEphemeralParam | None = None) -> None:
|
|
55
|
+
super().__init__()
|
|
56
|
+
self._cache_control = cache_control
|
|
57
|
+
|
|
58
|
+
@override
|
|
59
|
+
def to_dict(self) -> BetaMemoryTool20250818Param:
|
|
60
|
+
param: BetaMemoryTool20250818Param = {"type": "memory_20250818", "name": "memory"}
|
|
61
|
+
|
|
62
|
+
if self._cache_control is not None:
|
|
63
|
+
param["cache_control"] = self._cache_control
|
|
64
|
+
|
|
65
|
+
return param
|
|
66
|
+
|
|
67
|
+
@override
|
|
68
|
+
def call(self, input: object) -> BetaFunctionToolResultType:
|
|
69
|
+
command = cast(
|
|
70
|
+
BetaMemoryTool20250818Command,
|
|
71
|
+
construct_type_unchecked(value=input, type_=cast(Any, BetaMemoryTool20250818Command)),
|
|
72
|
+
)
|
|
73
|
+
return self.execute(command)
|
|
74
|
+
|
|
75
|
+
def execute(self, command: BetaMemoryTool20250818Command) -> BetaFunctionToolResultType:
|
|
76
|
+
"""Execute a memory command and return the result.
|
|
77
|
+
|
|
78
|
+
This method dispatches to the appropriate handler method based on the
|
|
79
|
+
command type (view, create, str_replace, insert, delete, rename).
|
|
80
|
+
|
|
81
|
+
You typically don't need to override this method.
|
|
82
|
+
"""
|
|
83
|
+
if command.command == "view":
|
|
84
|
+
return self.view(command)
|
|
85
|
+
elif command.command == "create":
|
|
86
|
+
return self.create(command)
|
|
87
|
+
elif command.command == "str_replace":
|
|
88
|
+
return self.str_replace(command)
|
|
89
|
+
elif command.command == "insert":
|
|
90
|
+
return self.insert(command)
|
|
91
|
+
elif command.command == "delete":
|
|
92
|
+
return self.delete(command)
|
|
93
|
+
elif command.command == "rename":
|
|
94
|
+
return self.rename(command)
|
|
95
|
+
elif TYPE_CHECKING: # type: ignore[unreachable]
|
|
96
|
+
assert_never(command)
|
|
97
|
+
else:
|
|
98
|
+
raise NotImplementedError(f"Unknown command: {command.command}")
|
|
99
|
+
|
|
100
|
+
@abstractmethod
|
|
101
|
+
def view(self, command: BetaMemoryTool20250818ViewCommand) -> BetaFunctionToolResultType:
|
|
102
|
+
"""View the contents of a memory path."""
|
|
103
|
+
pass
|
|
104
|
+
|
|
105
|
+
@abstractmethod
|
|
106
|
+
def create(self, command: BetaMemoryTool20250818CreateCommand) -> BetaFunctionToolResultType:
|
|
107
|
+
"""Create a new memory file with the specified content."""
|
|
108
|
+
pass
|
|
109
|
+
|
|
110
|
+
@abstractmethod
|
|
111
|
+
def str_replace(self, command: BetaMemoryTool20250818StrReplaceCommand) -> BetaFunctionToolResultType:
|
|
112
|
+
"""Replace text in a memory file."""
|
|
113
|
+
pass
|
|
114
|
+
|
|
115
|
+
@abstractmethod
|
|
116
|
+
def insert(self, command: BetaMemoryTool20250818InsertCommand) -> BetaFunctionToolResultType:
|
|
117
|
+
"""Insert text at a specific line number in a memory file."""
|
|
118
|
+
pass
|
|
119
|
+
|
|
120
|
+
@abstractmethod
|
|
121
|
+
def delete(self, command: BetaMemoryTool20250818DeleteCommand) -> BetaFunctionToolResultType:
|
|
122
|
+
"""Delete a memory file or directory."""
|
|
123
|
+
pass
|
|
124
|
+
|
|
125
|
+
@abstractmethod
|
|
126
|
+
def rename(self, command: BetaMemoryTool20250818RenameCommand) -> BetaFunctionToolResultType:
|
|
127
|
+
"""Rename or move a memory file or directory."""
|
|
128
|
+
pass
|
|
129
|
+
|
|
130
|
+
def clear_all_memory(self) -> BetaFunctionToolResultType:
|
|
131
|
+
"""Clear all memory data."""
|
|
132
|
+
raise NotImplementedError("clear_all_memory not implemented")
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
class BetaAsyncAbstractMemoryTool(BetaAsyncBuiltinFunctionTool):
|
|
136
|
+
"""Abstract base class for memory tool implementations.
|
|
137
|
+
|
|
138
|
+
This class provides the interface for implementing a custom memory backend for Claude.
|
|
139
|
+
|
|
140
|
+
Subclass this to create your own memory storage solution (e.g., database, cloud storage, encrypted files, etc.).
|
|
141
|
+
|
|
142
|
+
Example usage:
|
|
143
|
+
|
|
144
|
+
```py
|
|
145
|
+
class MyMemoryTool(BetaAbstractMemoryTool):
|
|
146
|
+
def view(self, command: BetaMemoryTool20250818ViewCommand) -> BetaFunctionToolResultType:
|
|
147
|
+
...
|
|
148
|
+
return "view result"
|
|
149
|
+
|
|
150
|
+
def create(self, command: BetaMemoryTool20250818CreateCommand) -> BetaFunctionToolResultType:
|
|
151
|
+
...
|
|
152
|
+
return "created successfully"
|
|
153
|
+
|
|
154
|
+
# ... implement other abstract methods
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
client = Anthropic()
|
|
158
|
+
memory_tool = MyMemoryTool()
|
|
159
|
+
message = client.beta.messages.run_tools(
|
|
160
|
+
model="claude-3-5-sonnet-20241022",
|
|
161
|
+
messages=[{"role": "user", "content": "Remember that I like coffee"}],
|
|
162
|
+
tools=[memory_tool],
|
|
163
|
+
).until_done()
|
|
164
|
+
```
|
|
165
|
+
"""
|
|
166
|
+
|
|
167
|
+
def __init__(self, *, cache_control: BetaCacheControlEphemeralParam | None = None) -> None:
|
|
168
|
+
super().__init__()
|
|
169
|
+
self._cache_control = cache_control
|
|
170
|
+
|
|
171
|
+
@override
|
|
172
|
+
def to_dict(self) -> BetaMemoryTool20250818Param:
|
|
173
|
+
param: BetaMemoryTool20250818Param = {"type": "memory_20250818", "name": "memory"}
|
|
174
|
+
|
|
175
|
+
if self._cache_control is not None:
|
|
176
|
+
param["cache_control"] = self._cache_control
|
|
177
|
+
|
|
178
|
+
return param
|
|
179
|
+
|
|
180
|
+
@override
|
|
181
|
+
async def call(self, input: object) -> BetaFunctionToolResultType:
|
|
182
|
+
command = cast(
|
|
183
|
+
BetaMemoryTool20250818Command,
|
|
184
|
+
construct_type_unchecked(value=input, type_=cast(Any, BetaMemoryTool20250818Command)),
|
|
185
|
+
)
|
|
186
|
+
return await self.execute(command)
|
|
187
|
+
|
|
188
|
+
async def execute(self, command: BetaMemoryTool20250818Command) -> BetaFunctionToolResultType:
|
|
189
|
+
"""Execute a memory command and return the result.
|
|
190
|
+
|
|
191
|
+
This method dispatches to the appropriate handler method based on the
|
|
192
|
+
command type (view, create, str_replace, insert, delete, rename).
|
|
193
|
+
|
|
194
|
+
You typically don't need to override this method.
|
|
195
|
+
"""
|
|
196
|
+
if command.command == "view":
|
|
197
|
+
return await self.view(command)
|
|
198
|
+
elif command.command == "create":
|
|
199
|
+
return await self.create(command)
|
|
200
|
+
elif command.command == "str_replace":
|
|
201
|
+
return await self.str_replace(command)
|
|
202
|
+
elif command.command == "insert":
|
|
203
|
+
return await self.insert(command)
|
|
204
|
+
elif command.command == "delete":
|
|
205
|
+
return await self.delete(command)
|
|
206
|
+
elif command.command == "rename":
|
|
207
|
+
return await self.rename(command)
|
|
208
|
+
elif TYPE_CHECKING: # type: ignore[unreachable]
|
|
209
|
+
assert_never(command)
|
|
210
|
+
else:
|
|
211
|
+
raise NotImplementedError(f"Unknown command: {command.command}")
|
|
212
|
+
|
|
213
|
+
@abstractmethod
|
|
214
|
+
async def view(self, command: BetaMemoryTool20250818ViewCommand) -> BetaFunctionToolResultType:
|
|
215
|
+
"""View the contents of a memory path."""
|
|
216
|
+
pass
|
|
217
|
+
|
|
218
|
+
@abstractmethod
|
|
219
|
+
async def create(self, command: BetaMemoryTool20250818CreateCommand) -> BetaFunctionToolResultType:
|
|
220
|
+
"""Create a new memory file with the specified content."""
|
|
221
|
+
pass
|
|
222
|
+
|
|
223
|
+
@abstractmethod
|
|
224
|
+
async def str_replace(self, command: BetaMemoryTool20250818StrReplaceCommand) -> BetaFunctionToolResultType:
|
|
225
|
+
"""Replace text in a memory file."""
|
|
226
|
+
pass
|
|
227
|
+
|
|
228
|
+
@abstractmethod
|
|
229
|
+
async def insert(self, command: BetaMemoryTool20250818InsertCommand) -> BetaFunctionToolResultType:
|
|
230
|
+
"""Insert text at a specific line number in a memory file."""
|
|
231
|
+
pass
|
|
232
|
+
|
|
233
|
+
@abstractmethod
|
|
234
|
+
async def delete(self, command: BetaMemoryTool20250818DeleteCommand) -> BetaFunctionToolResultType:
|
|
235
|
+
"""Delete a memory file or directory."""
|
|
236
|
+
pass
|
|
237
|
+
|
|
238
|
+
@abstractmethod
|
|
239
|
+
async def rename(self, command: BetaMemoryTool20250818RenameCommand) -> BetaFunctionToolResultType:
|
|
240
|
+
"""Rename or move a memory file or directory."""
|
|
241
|
+
pass
|
|
242
|
+
|
|
243
|
+
async def clear_all_memory(self) -> BetaFunctionToolResultType:
|
|
244
|
+
"""Clear all memory data."""
|
|
245
|
+
raise NotImplementedError("clear_all_memory not implemented")
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
3
|
import logging
|
|
4
|
+
from abc import ABC, abstractmethod
|
|
4
5
|
from typing import Any, Union, Generic, TypeVar, Callable, Iterable, Coroutine, cast, overload
|
|
5
6
|
from inspect import iscoroutinefunction
|
|
6
7
|
from typing_extensions import TypeAlias, override
|
|
@@ -13,6 +14,7 @@ from ... import _compat
|
|
|
13
14
|
from ..._utils import is_dict
|
|
14
15
|
from ..._compat import cached_property
|
|
15
16
|
from ..._models import TypeAdapter
|
|
17
|
+
from ...types.beta import BetaToolUnionParam
|
|
16
18
|
from ..._utils._utils import CallableT
|
|
17
19
|
from ...types.tool_param import ToolParam, InputSchema
|
|
18
20
|
from ...types.beta.beta_tool_result_block_param import Content as BetaContent
|
|
@@ -28,6 +30,30 @@ AsyncFunction = Callable[..., Coroutine[Any, Any, BetaFunctionToolResultType]]
|
|
|
28
30
|
AsyncFunctionT = TypeVar("AsyncFunctionT", bound=AsyncFunction)
|
|
29
31
|
|
|
30
32
|
|
|
33
|
+
class BetaBuiltinFunctionTool(ABC):
|
|
34
|
+
@abstractmethod
|
|
35
|
+
def to_dict(self) -> BetaToolUnionParam: ...
|
|
36
|
+
|
|
37
|
+
@abstractmethod
|
|
38
|
+
def call(self, input: object) -> BetaFunctionToolResultType: ...
|
|
39
|
+
|
|
40
|
+
@property
|
|
41
|
+
def name(self) -> str:
|
|
42
|
+
return self.to_dict()["name"]
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
class BetaAsyncBuiltinFunctionTool(ABC):
|
|
46
|
+
@abstractmethod
|
|
47
|
+
def to_dict(self) -> BetaToolUnionParam: ...
|
|
48
|
+
|
|
49
|
+
@abstractmethod
|
|
50
|
+
async def call(self, input: object) -> BetaFunctionToolResultType: ...
|
|
51
|
+
|
|
52
|
+
@property
|
|
53
|
+
def name(self) -> str:
|
|
54
|
+
return self.to_dict()["name"]
|
|
55
|
+
|
|
56
|
+
|
|
31
57
|
class BaseFunctionTool(Generic[CallableT]):
|
|
32
58
|
func: CallableT
|
|
33
59
|
"""The function this tool is wrapping"""
|
|
@@ -287,3 +313,7 @@ def beta_async_tool(
|
|
|
287
313
|
)
|
|
288
314
|
|
|
289
315
|
return decorator
|
|
316
|
+
|
|
317
|
+
|
|
318
|
+
BetaRunnableTool = Union[BetaFunctionTool[Any], BetaBuiltinFunctionTool]
|
|
319
|
+
BetaAsyncRunnableTool = Union[BetaAsyncFunctionTool[Any], BetaAsyncBuiltinFunctionTool]
|
|
@@ -22,7 +22,14 @@ import httpx
|
|
|
22
22
|
from ..._types import Body, Query, Headers, NotGiven
|
|
23
23
|
from ..._utils import consume_sync_iterator, consume_async_iterator
|
|
24
24
|
from ...types.beta import BetaMessage, BetaContentBlock, BetaMessageParam
|
|
25
|
-
from ._beta_functions import
|
|
25
|
+
from ._beta_functions import (
|
|
26
|
+
BetaFunctionTool,
|
|
27
|
+
BetaRunnableTool,
|
|
28
|
+
BetaAsyncFunctionTool,
|
|
29
|
+
BetaAsyncRunnableTool,
|
|
30
|
+
BetaBuiltinFunctionTool,
|
|
31
|
+
BetaAsyncBuiltinFunctionTool,
|
|
32
|
+
)
|
|
26
33
|
from ..streaming._beta_messages import BetaMessageStream, BetaAsyncMessageStream
|
|
27
34
|
from ...types.beta.message_create_params import MessageCreateParamsBase
|
|
28
35
|
from ...types.beta.beta_tool_result_block_param import BetaToolResultBlockParam
|
|
@@ -31,7 +38,12 @@ if TYPE_CHECKING:
|
|
|
31
38
|
from ..._client import Anthropic, AsyncAnthropic
|
|
32
39
|
|
|
33
40
|
|
|
34
|
-
AnyFunctionToolT = TypeVar(
|
|
41
|
+
AnyFunctionToolT = TypeVar(
|
|
42
|
+
"AnyFunctionToolT",
|
|
43
|
+
bound=Union[
|
|
44
|
+
BetaFunctionTool[Any], BetaAsyncFunctionTool[Any], BetaBuiltinFunctionTool, BetaAsyncBuiltinFunctionTool
|
|
45
|
+
],
|
|
46
|
+
)
|
|
35
47
|
RunnerItemT = TypeVar("RunnerItemT")
|
|
36
48
|
|
|
37
49
|
log = logging.getLogger(__name__)
|
|
@@ -97,13 +109,13 @@ class BaseToolRunner(Generic[AnyFunctionToolT]):
|
|
|
97
109
|
return False
|
|
98
110
|
|
|
99
111
|
|
|
100
|
-
class BaseSyncToolRunner(BaseToolRunner[
|
|
112
|
+
class BaseSyncToolRunner(BaseToolRunner[BetaRunnableTool], Generic[RunnerItemT], ABC):
|
|
101
113
|
def __init__(
|
|
102
114
|
self,
|
|
103
115
|
*,
|
|
104
116
|
params: MessageCreateParamsBase,
|
|
105
117
|
options: RequestOptions,
|
|
106
|
-
tools: Iterable[
|
|
118
|
+
tools: Iterable[BetaRunnableTool],
|
|
107
119
|
client: Anthropic,
|
|
108
120
|
max_iterations: int | None = None,
|
|
109
121
|
) -> None:
|
|
@@ -250,13 +262,13 @@ class BetaStreamingToolRunner(BaseSyncToolRunner[BetaMessageStream]):
|
|
|
250
262
|
message = stream.get_final_message()
|
|
251
263
|
|
|
252
264
|
|
|
253
|
-
class BaseAsyncToolRunner(BaseToolRunner[
|
|
265
|
+
class BaseAsyncToolRunner(BaseToolRunner[BetaAsyncRunnableTool], Generic[RunnerItemT], ABC):
|
|
254
266
|
def __init__(
|
|
255
267
|
self,
|
|
256
268
|
*,
|
|
257
269
|
params: MessageCreateParamsBase,
|
|
258
270
|
options: RequestOptions,
|
|
259
|
-
tools: Iterable[
|
|
271
|
+
tools: Iterable[BetaAsyncRunnableTool],
|
|
260
272
|
client: AsyncAnthropic,
|
|
261
273
|
max_iterations: int | None = None,
|
|
262
274
|
) -> None:
|
|
@@ -98,7 +98,7 @@ class Files(SyncAPIResource):
|
|
|
98
98
|
{
|
|
99
99
|
"anthropic-beta": ",".join(chain((str(e) for e in betas), ["files-api-2025-04-14"]))
|
|
100
100
|
if is_given(betas)
|
|
101
|
-
else
|
|
101
|
+
else not_given
|
|
102
102
|
}
|
|
103
103
|
),
|
|
104
104
|
**(extra_headers or {}),
|
|
@@ -159,7 +159,7 @@ class Files(SyncAPIResource):
|
|
|
159
159
|
{
|
|
160
160
|
"anthropic-beta": ",".join(chain((str(e) for e in betas), ["files-api-2025-04-14"]))
|
|
161
161
|
if is_given(betas)
|
|
162
|
-
else
|
|
162
|
+
else not_given
|
|
163
163
|
}
|
|
164
164
|
),
|
|
165
165
|
**(extra_headers or {}),
|
|
@@ -209,7 +209,7 @@ class Files(SyncAPIResource):
|
|
|
209
209
|
{
|
|
210
210
|
"anthropic-beta": ",".join(chain((str(e) for e in betas), ["files-api-2025-04-14"]))
|
|
211
211
|
if is_given(betas)
|
|
212
|
-
else
|
|
212
|
+
else not_given
|
|
213
213
|
}
|
|
214
214
|
),
|
|
215
215
|
**(extra_headers or {}),
|
|
@@ -258,7 +258,7 @@ class Files(SyncAPIResource):
|
|
|
258
258
|
{
|
|
259
259
|
"anthropic-beta": ",".join(chain((str(e) for e in betas), ["files-api-2025-04-14"]))
|
|
260
260
|
if is_given(betas)
|
|
261
|
-
else
|
|
261
|
+
else not_given
|
|
262
262
|
}
|
|
263
263
|
),
|
|
264
264
|
**(extra_headers or {}),
|
|
@@ -305,7 +305,7 @@ class Files(SyncAPIResource):
|
|
|
305
305
|
{
|
|
306
306
|
"anthropic-beta": ",".join(chain((str(e) for e in betas), ["files-api-2025-04-14"]))
|
|
307
307
|
if is_given(betas)
|
|
308
|
-
else
|
|
308
|
+
else not_given
|
|
309
309
|
}
|
|
310
310
|
),
|
|
311
311
|
**(extra_headers or {}),
|
|
@@ -392,7 +392,7 @@ class AsyncFiles(AsyncAPIResource):
|
|
|
392
392
|
{
|
|
393
393
|
"anthropic-beta": ",".join(chain((str(e) for e in betas), ["files-api-2025-04-14"]))
|
|
394
394
|
if is_given(betas)
|
|
395
|
-
else
|
|
395
|
+
else not_given
|
|
396
396
|
}
|
|
397
397
|
),
|
|
398
398
|
**(extra_headers or {}),
|
|
@@ -453,7 +453,7 @@ class AsyncFiles(AsyncAPIResource):
|
|
|
453
453
|
{
|
|
454
454
|
"anthropic-beta": ",".join(chain((str(e) for e in betas), ["files-api-2025-04-14"]))
|
|
455
455
|
if is_given(betas)
|
|
456
|
-
else
|
|
456
|
+
else not_given
|
|
457
457
|
}
|
|
458
458
|
),
|
|
459
459
|
**(extra_headers or {}),
|
|
@@ -503,7 +503,7 @@ class AsyncFiles(AsyncAPIResource):
|
|
|
503
503
|
{
|
|
504
504
|
"anthropic-beta": ",".join(chain((str(e) for e in betas), ["files-api-2025-04-14"]))
|
|
505
505
|
if is_given(betas)
|
|
506
|
-
else
|
|
506
|
+
else not_given
|
|
507
507
|
}
|
|
508
508
|
),
|
|
509
509
|
**(extra_headers or {}),
|
|
@@ -552,7 +552,7 @@ class AsyncFiles(AsyncAPIResource):
|
|
|
552
552
|
{
|
|
553
553
|
"anthropic-beta": ",".join(chain((str(e) for e in betas), ["files-api-2025-04-14"]))
|
|
554
554
|
if is_given(betas)
|
|
555
|
-
else
|
|
555
|
+
else not_given
|
|
556
556
|
}
|
|
557
557
|
),
|
|
558
558
|
**(extra_headers or {}),
|
|
@@ -599,7 +599,7 @@ class AsyncFiles(AsyncAPIResource):
|
|
|
599
599
|
{
|
|
600
600
|
"anthropic-beta": ",".join(chain((str(e) for e in betas), ["files-api-2025-04-14"]))
|
|
601
601
|
if is_given(betas)
|
|
602
|
-
else
|
|
602
|
+
else not_given
|
|
603
603
|
}
|
|
604
604
|
),
|
|
605
605
|
**(extra_headers or {}),
|
|
@@ -87,7 +87,7 @@ class Batches(SyncAPIResource):
|
|
|
87
87
|
{
|
|
88
88
|
"anthropic-beta": ",".join(chain((str(e) for e in betas), ["message-batches-2024-09-24"]))
|
|
89
89
|
if is_given(betas)
|
|
90
|
-
else
|
|
90
|
+
else not_given
|
|
91
91
|
}
|
|
92
92
|
),
|
|
93
93
|
**(extra_headers or {}),
|
|
@@ -143,7 +143,7 @@ class Batches(SyncAPIResource):
|
|
|
143
143
|
{
|
|
144
144
|
"anthropic-beta": ",".join(chain((str(e) for e in betas), ["message-batches-2024-09-24"]))
|
|
145
145
|
if is_given(betas)
|
|
146
|
-
else
|
|
146
|
+
else not_given
|
|
147
147
|
}
|
|
148
148
|
),
|
|
149
149
|
**(extra_headers or {}),
|
|
@@ -205,7 +205,7 @@ class Batches(SyncAPIResource):
|
|
|
205
205
|
{
|
|
206
206
|
"anthropic-beta": ",".join(chain((str(e) for e in betas), ["message-batches-2024-09-24"]))
|
|
207
207
|
if is_given(betas)
|
|
208
|
-
else
|
|
208
|
+
else not_given
|
|
209
209
|
}
|
|
210
210
|
),
|
|
211
211
|
**(extra_headers or {}),
|
|
@@ -272,7 +272,7 @@ class Batches(SyncAPIResource):
|
|
|
272
272
|
{
|
|
273
273
|
"anthropic-beta": ",".join(chain((str(e) for e in betas), ["message-batches-2024-09-24"]))
|
|
274
274
|
if is_given(betas)
|
|
275
|
-
else
|
|
275
|
+
else not_given
|
|
276
276
|
}
|
|
277
277
|
),
|
|
278
278
|
**(extra_headers or {}),
|
|
@@ -333,7 +333,7 @@ class Batches(SyncAPIResource):
|
|
|
333
333
|
{
|
|
334
334
|
"anthropic-beta": ",".join(chain((str(e) for e in betas), ["message-batches-2024-09-24"]))
|
|
335
335
|
if is_given(betas)
|
|
336
|
-
else
|
|
336
|
+
else not_given
|
|
337
337
|
}
|
|
338
338
|
),
|
|
339
339
|
**(extra_headers or {}),
|
|
@@ -397,7 +397,7 @@ class Batches(SyncAPIResource):
|
|
|
397
397
|
{
|
|
398
398
|
"anthropic-beta": ",".join(chain((str(e) for e in betas), ["message-batches-2024-09-24"]))
|
|
399
399
|
if is_given(betas)
|
|
400
|
-
else
|
|
400
|
+
else not_given
|
|
401
401
|
}
|
|
402
402
|
),
|
|
403
403
|
**(extra_headers or {}),
|
|
@@ -474,7 +474,7 @@ class AsyncBatches(AsyncAPIResource):
|
|
|
474
474
|
{
|
|
475
475
|
"anthropic-beta": ",".join(chain((str(e) for e in betas), ["message-batches-2024-09-24"]))
|
|
476
476
|
if is_given(betas)
|
|
477
|
-
else
|
|
477
|
+
else not_given
|
|
478
478
|
}
|
|
479
479
|
),
|
|
480
480
|
**(extra_headers or {}),
|
|
@@ -530,7 +530,7 @@ class AsyncBatches(AsyncAPIResource):
|
|
|
530
530
|
{
|
|
531
531
|
"anthropic-beta": ",".join(chain((str(e) for e in betas), ["message-batches-2024-09-24"]))
|
|
532
532
|
if is_given(betas)
|
|
533
|
-
else
|
|
533
|
+
else not_given
|
|
534
534
|
}
|
|
535
535
|
),
|
|
536
536
|
**(extra_headers or {}),
|
|
@@ -592,7 +592,7 @@ class AsyncBatches(AsyncAPIResource):
|
|
|
592
592
|
{
|
|
593
593
|
"anthropic-beta": ",".join(chain((str(e) for e in betas), ["message-batches-2024-09-24"]))
|
|
594
594
|
if is_given(betas)
|
|
595
|
-
else
|
|
595
|
+
else not_given
|
|
596
596
|
}
|
|
597
597
|
),
|
|
598
598
|
**(extra_headers or {}),
|
|
@@ -659,7 +659,7 @@ class AsyncBatches(AsyncAPIResource):
|
|
|
659
659
|
{
|
|
660
660
|
"anthropic-beta": ",".join(chain((str(e) for e in betas), ["message-batches-2024-09-24"]))
|
|
661
661
|
if is_given(betas)
|
|
662
|
-
else
|
|
662
|
+
else not_given
|
|
663
663
|
}
|
|
664
664
|
),
|
|
665
665
|
**(extra_headers or {}),
|
|
@@ -720,7 +720,7 @@ class AsyncBatches(AsyncAPIResource):
|
|
|
720
720
|
{
|
|
721
721
|
"anthropic-beta": ",".join(chain((str(e) for e in betas), ["message-batches-2024-09-24"]))
|
|
722
722
|
if is_given(betas)
|
|
723
|
-
else
|
|
723
|
+
else not_given
|
|
724
724
|
}
|
|
725
725
|
),
|
|
726
726
|
**(extra_headers or {}),
|
|
@@ -784,7 +784,7 @@ class AsyncBatches(AsyncAPIResource):
|
|
|
784
784
|
{
|
|
785
785
|
"anthropic-beta": ",".join(chain((str(e) for e in betas), ["message-batches-2024-09-24"]))
|
|
786
786
|
if is_given(betas)
|
|
787
|
-
else
|
|
787
|
+
else not_given
|
|
788
788
|
}
|
|
789
789
|
),
|
|
790
790
|
**(extra_headers or {}),
|