Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/anthropic/lib/streaming/_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,14 @@ def accumulate_event(
json_buf += bytes(event.delta.partial_json, "utf-8")

if json_buf:
content.input = from_json(json_buf, partial_mode=True)
try:
content.input = from_json(json_buf, partial_mode=True)
except ValueError as e:
raise ValueError(
f"Unable to parse tool parameter JSON from model. "
f"Please retry your request or adjust your prompt. "
f"Error: {e}. JSON: {json_buf.decode('utf-8')}"
) from e

setattr(content, JSON_BUF_PROPERTY, json_buf)
elif event.delta.type == "citations_delta":
Expand Down
10 changes: 5 additions & 5 deletions src/anthropic/lib/tools/_beta_builtin_memory_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,21 +166,21 @@ class BetaAsyncAbstractMemoryTool(BetaAsyncBuiltinFunctionTool):
Example usage:

```py
class MyMemoryTool(BetaAbstractMemoryTool):
def view(self, command: BetaMemoryTool20250818ViewCommand) -> BetaFunctionToolResultType:
class MyMemoryTool(BetaAsyncAbstractMemoryTool):
async def view(self, command: BetaMemoryTool20250818ViewCommand) -> BetaFunctionToolResultType:
...
return "view result"

def create(self, command: BetaMemoryTool20250818CreateCommand) -> BetaFunctionToolResultType:
async def create(self, command: BetaMemoryTool20250818CreateCommand) -> BetaFunctionToolResultType:
...
return "created successfully"

# ... implement other abstract methods


client = Anthropic()
client = AsyncAnthropic()
memory_tool = MyMemoryTool()
message = client.beta.messages.run_tools(
message = await client.beta.messages.run_tools(
model="claude-sonnet-4-5",
messages=[{"role": "user", "content": "Remember that I like coffee"}],
tools=[memory_tool],
Expand Down