anthropics / anthropics/anthropic-sdk-python

BetaAsyncAbstractMemoryTool docstring contains sync-only example (copy-paste from sync class)

未關閉
#1,290 2 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
sdk
主要語言
Python
星號
3.9k
分支
853
平均合併
1 天 18 小時
30 天內合併 PR
11

描述

## Bug report

The `BetaAsyncAbstractMemoryTool` class docstring in `src/anthropic/lib/tools/_beta_builtin_memory_tool.py` (lines 159-188) contains a usage example that was copy-pasted from the synchronous `BetaAbstractMemoryTool` without being updated for async usage. Following the example verbatim raises `TypeError` at instantiation time.

## Three errors in the docstring example

**1. Wrong base class (line 169):**

```python
# Current (broken)
class MyMemoryTool(BetaAbstractMemoryTool): # sync base class

# Should be
class MyMemoryTool(BetaAsyncAbstractMemoryTool):
```

**2. Sync method definitions instead of async (lines 170, 174):**

```python
# Current (broken)
def view(self, command: ...) -> BetaFunctionToolResultType:
def create(self, command: ...) -> BetaFunctionToolResultType:

# Should be
async def view(self, command: ...) -> BetaFunctionToolResultType:
async def create(self, command: ...) -> BetaFunctionToolResultType:
```

**3. Sync client instead of async (lines 181-187):**

```python
# Current (broken)
client = Anthropic()
message = client.beta.messages.run_tools(...)

# Should be
client = AsyncAnthropic()
# with await and async def main()
```

## Expected behavior

The docstring example for the async class should use `BetaAsyncAbstractMemoryTool` as base class, `async def` methods, and `AsyncAnthropic()` client — matching async conventions.

## Evidence this is a copy-paste error

The sync counterpart `BetaAbstractMemoryTool` docstring (lines 46-76 in the same file) is correctly written. The async class docstring is a verbatim copy that was never updated.

## Suggested fix

Update the `BetaAsyncAbstractMemoryTool` docstring to:
- Change base class to `BetaAsyncAbstractMemoryTool`
- Add `async` keyword to all method definitions
- Replace `Anthropic()` with `AsyncAnthropic()`
- Wrap usage in `async def main()` / `asyncio.run(main())`

Happy to submit a PR if helpful.

貢獻指南

開啟貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。