Skip to content

models - anthropic - document - plain text #141

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 29, 2025

Conversation

pgrayy
Copy link
Member

@pgrayy pgrayy commented May 29, 2025

Description

Our Anthropic model provider passes along all document content in the same manner. However, we need special handling for plain text documents (docs). This PR adds the fix.

Related Issues

strands-agents/tools#53

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update
  • Other (please describe):

Testing

  • hatch fmt --linter
  • hatch fmt --formatter
  • hatch test --all
  • Verify that the changes do not break functionality or introduce warnings in consuming repositories: agents-docs, agents-tools, agents-cli
  • hatch run test-lint
  • python test_doc.py: Ran the following test script:
from strands import Agent
from strands.models.anthropic import AnthropicModel

with open("cat.wikipedia.page1.txt", "rb") as fp:
    doc = fp.read()

agent = Agent(
    messages=[
        {
            "role": "user",
            "content": [
                {
                    "document": {
                        "format": "txt",
                        "name": "test doc",
                        "source": {
                            "bytes": doc,
                        },
                    },
                },
            ],
        },
    ],
    model=AnthropicModel(client_args={"api_key": "***"}, model_id="claude-3-5-sonnet-latest", max_tokens=8000)
)
agent("Can you summarize the provided document?")

Checklist

  • I have read the CONTRIBUTING document
  • I have added tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
  • I have added an appropriate example to the documentation to outline the feature
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@pgrayy pgrayy requested a review from a team as a code owner May 29, 2025 13:59
@pgrayy pgrayy merged commit 5d785a1 into strands-agents:main May 29, 2025
20 checks passed
jer96 pushed a commit to lukehau/sdk-python that referenced this pull request Jun 3, 2025
@pgrayy pgrayy deleted the anthropic-documents branch June 10, 2025 14:40
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.

2 participants