Skip to content

fix: update BetaAsyncAbstractMemoryTool docstring for async usage - #1291

Open
mmporong wants to merge 3 commits into
anthropics:mainfrom
mmporong:fix/async-memory-tool-docstring
Open

mmporong wants to merge 3 commits into
anthropics:mainfrom
mmporong:fix/async-memory-tool-docstring

Conversation

@mmporong

@mmporong mmporong commented Mar 25, 2026 •

Copy link
Copy Markdown

Summary

The BetaAsyncAbstractMemoryTool docstring example was copy-pasted from the sync BetaAbstractMemoryTool without being updated for async usage, so the async class showed a sync base class, sync methods, and a sync client.

Changes

  • Use BetaAsyncAbstractMemoryTool as base class (not BetaAbstractMemoryTool)
  • Add async keyword to method definitions
  • Replace Anthropic() with AsyncAnthropic() and await the until_done() call

Fixes #1290

The docstring example was copy-pasted from the sync BetaAbstractMemoryTool
without being updated. Following the example verbatim raises TypeError
at instantiation time.

Changes:
- Use BetaAsyncAbstractMemoryTool as base class (not BetaAbstractMemoryTool)
- Add async keyword to method definitions
- Replace Anthropic() with AsyncAnthropic()
- Wrap usage in async def main() / asyncio.run(main())

Fixes anthropics#1290

@RobertCraigie RobertCraigie left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing this!

Comment on lines 186 to 197
async def main() -> None:
client = AsyncAnthropic()
memory_tool = MyMemoryTool()
message = await client.beta.messages.run_tools(
model="claude-sonnet-4-5",
messages=[{"role": "user", "content": "Remember that I like coffee"}],
tools=[memory_tool],
).until_done()


asyncio.run(main())
```

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: we generally assume the code snippet is already being ran in an async context, so you can remove the asyncio usage and the main() function wrapper.

@mmporong

Copy link
Copy Markdown
Author

Thanks, and sorry for the long delay. I dropped the asyncio import and the main() wrapper, and merged main to resolve the conflict with the model name update.

While checking against main: both memory tool examples (sync and async) still call client.beta.messages.run_tools(...) without max_tokens, but the method is tool_runner() and it requires max_tokens. I left that out to keep this PR to your comment. I can fix both examples here or in a separate PR, whichever you prefer.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants