Skip to content

feat(email-attachments): read email attachments inline with OCR fallback#5172

Open
Katsoragi wants to merge 5 commits into
odysseus-dev:devfrom
Katsoragi:personal/email-attachments-reader
Open

feat(email-attachments): read email attachments inline with OCR fallback#5172
Katsoragi wants to merge 5 commits into
odysseus-dev:devfrom
Katsoragi:personal/email-attachments-reader

Conversation

@Katsoragi

@Katsoragi Katsoragi commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Summary

Enable the agent to extract and read email attachments inline, including scanned/image-only PDFs via OCR fallback.

Changes

  • read_email_attachment inline text extraction (plain text, HTML, PDF)
  • download_attachment save-to-disk fallback
  • _try_pdf_ocr fallback for scanned PDFs using tesseract/pdf2image/PyMuPDF
  • Added attachment tools to FUNCTION_TOOL_SCHEMAS and BUILTIN_EMAIL_TOOLS
  • Fixed MCP schema filter to match qualified and bare tool names
  • Added email domain context preservation when active_email is set
  • Added keyword hints for attachment/pdf in tool_index
  • Updated Dockerfile and requirements-optional.txt for optional OCR

Target branch

  • This PR targets dev, not main. All PRs land in dev; main is curated by the maintainer at each release. If your PR is on main by accident, click "Edit" on this PR and change the base.

Linked Issue

Fixes #5171

Type of Change

  • Bug fix (non-breaking — fixes a confirmed issue)
  • New feature (non-breaking — adds new behaviour)
  • Breaking change (changes or removes existing behaviour)
  • Refactor / cleanup (behaviour unchanged)
  • Documentation only
  • CI / tooling / configuration

Checklist

  • I searched open issues and open PRs — this is not a duplicate.
  • This PR targets dev
  • My changes are limited to the scope described above — no unrelated refactors or whitespace changes mixed in.
  • I actually ran the app (docker compose up or uvicorn app:app) and verified the change works end-to-end. Type-checks and unit tests are not enough.

How to Test

  1. Fetch or load an email with a plain text, HTML, or PDF attachment in the chat UI.
  2. Ask the agent to read or summarize the attachment.
  3. Verify the agent successfully extracts the text inline using read_email_attachment without requiring manual file downloading.
  4. For scanned/image-only PDFs, verify that OCR runs automatically and extracts the text successfully.

Checks Run

uv run pytest tests/test_email_attachment_reading.py -v
uv run pytest tests/ -k agent -v
docker compose build --build-arg INSTALL_OPTIONAL=true odysseus

19/19 email tests passed. Core email attachment reading verified via live agent test (OCR extracted 26k+ chars from scanned PDF).

@github-actions github-actions Bot added needs work PR description incomplete — please update before review ready for review Description complete — ready for maintainer review and removed needs work PR description incomplete — please update before review labels Jul 3, 2026
- Add read_email_attachment tool for inline text extraction
- Add download_attachment tool for saving to disk
- Add pypdf PDF extraction with has_real_text empty detection
- Add _try_pdf_ocr fallback (pdf2image/pytesseract, PyMuPDF)
- Add attachment/email tools to FUNCTION_TOOL_SCHEMAS
- Add MCP bare-name schema filter fix
- Add email domain context preservation when active_email is set
- Add keyword hints for attachment/pdf in tool_index
- Add read_email_attachment/download_attachment to BUILTIN_EMAIL_TOOLS
- Update Dockerfile and requirements-optional.txt for OCR
- Add tests for text, HTML, PDF, unsupported formats
- Add docs: feature spec and agent interaction guide
- Clean up debug logs from production code
@Katsoragi
Katsoragi force-pushed the personal/email-attachments-reader branch from f17c787 to 6f934f3 Compare July 12, 2026 15:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready for review Description complete — ready for maintainer review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(email): add inline attachment reading with OCR fallback for scanned PDFs

1 participant