Skip to content

Conversation

@devin-ai-integration
Copy link
Contributor

@devin-ai-integration devin-ai-integration bot commented Nov 27, 2025

Summary

Fixes #3984

AddImageTool now converts local file paths to base64 data URLs before returning them to the LLM. This enables multimodal functionality with Anthropic models (Claude 3.5 Sonnet, etc.) which require images in base64 format rather than raw file paths.

The new _normalize_image_url method handles:

  • HTTP/HTTPS URLs → returned unchanged
  • Data URLs → returned unchanged
  • file:// URLs → converted to base64 data URLs
  • Local file paths (absolute, relative, ~ expansion) → converted to base64 data URLs
  • Unknown schemes (e.g., s3://) → returned unchanged (allows downstream handling)

Review & Testing Checklist for Human

  • Test with Anthropic API: The unit tests verify base64 conversion logic but don't test actual Anthropic API calls. Please test a multimodal agent with Claude 3.5 Sonnet using a local image file to confirm the fix works end-to-end.
  • Regression test with OpenAI: Verify that HTTP URLs still work correctly with OpenAI's vision models (should be unchanged behavior).
  • Large file behavior: No size limit is enforced when reading files into memory. Consider testing with a large image (10MB+) to verify acceptable behavior.

Recommended Test Plan

from crewai import Agent, Task, Crew

agent = Agent(
    role="Image Analyst",
    goal="Analyze images",
    backstory="Expert at analyzing images",
    llm="anthropic/claude-3-5-sonnet-20241022",  # or your Anthropic model
    multimodal=True,
)

task = Task(
    description="Describe the image at /path/to/local/image.png",
    expected_output="A description of the image",
    agent=agent,
)

crew = Crew(agents=[agent], tasks=[task])
result = crew.kickoff()

Notes

… compatibility

Fixes #3984

AddImageTool now converts local file paths to base64 data URLs before
returning them to the LLM. This enables multimodal functionality with
Anthropic models (Claude 3.5 Sonnet, etc.) which require images in
base64 format.

Changes:
- Add _normalize_image_url method to detect and convert local files
- Support absolute paths, relative paths, file:// URLs, and ~ expansion
- Preserve HTTP/HTTPS URLs and existing data URLs unchanged
- Add comprehensive tests for all conversion scenarios

Co-Authored-By: João <[email protected]>
@devin-ai-integration
Copy link
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

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.

AddImageTool doesn't convert local file paths to base64, breaking Anthropic Vision API

2 participants