Skip to content

The memory example incorrectly adds assistant content to the messages #1050

@HQidea

Description

@HQidea

I found 2 bugs that cause the memory example not to work as expected in https://github.com/anthropics/anthropic-sdk-python/blob/main/examples/memory/basic.py

  • Variable scope: The assistant_content variable was declared outside the message processing loop, causing content accumulation across multiple messages
  • Message ordering: Assistant messages were being stored after tool results, which violates the correct conversation flow where assistant messages should come before tool results

To fix these problems, I opened a PR at #1049.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions