Docling
Convert documents to Markdown, JSON, HTML, and other formats with configurable OCR using the [Docling library](https://github.com/docling-project/docling).
Prerequisites
uv pip install -U agno docling openai
# Required for the OCR example
uv pip install -U easyocr
# Required for the runner's audio/video examples
uv pip install -U "docling[asr]" "docling-slim[format-video]"export OPENAI_API_KEY="your_openai_api_key_here"ffmpeg is also required for audio/video processing:
- macOS:
brew install ffmpeg - Ubuntu:
sudo apt-get install ffmpeg - Windows: Download from ffmpeg.org
Example
from agno.agent import Agent
from agno.tools.docling import DoclingTools
agent = Agent(
tools=[DoclingTools(all=True)],
description="You are an agent that converts documents from all Docling parsers and exports to all supported output formats.",
)
# Convert a PDF to Markdown
agent.print_response(
"Convert to Markdown: cookbook/07_knowledge/testing_resources/cv_1.pdf",
markdown=True,
)
# Convert a PDF to JSON
agent.print_response(
"Convert to JSON and return the full JSON without summarizing: cookbook/07_knowledge/testing_resources/cv_1.pdf",
markdown=True,
)
# Convert inline string content
agent.print_response(
"Use convert_string_content to convert this markdown string to JSON: # Inline Markdown\n\nThis is a parser test.",
markdown=True,
)OCR Configuration
from agno.agent import Agent
from agno.tools.docling import DoclingTools
ocr_tools = DoclingTools(
pdf_enable_ocr=True,
pdf_ocr_engine="easyocr",
pdf_ocr_lang=["pt", "en"],
pdf_force_full_page_ocr=True,
pdf_enable_table_structure=True,
pdf_enable_picture_description=False,
pdf_document_timeout=120.0,
)
ocr_agent = Agent(
tools=[ocr_tools],
description="You are an agent that converts PDFs using advanced OCR.",
)
ocr_agent.print_response(
"Convert to Markdown: cookbook/07_knowledge/testing_resources/cv_1.pdf",
markdown=True,
)Run from the Agno checkout below so the PDF and other test files exist. The runner also executes media examples beyond the two snippets shown here, and initial conversions can download model weights. The model may summarize returned exports; call DoclingTools methods directly when you need their exact output.
Run the Example
git clone https://github.com/agno-agi/agno.git
cd agno
git checkout d703c34f3abf3c41275d3fb2da6e0518a8881f24
# Create and activate virtual environment
./scripts/demo_setup.sh
source .venvs/demo/bin/activate
uv pip install -U "docling[asr]" "docling-slim[format-video]" easyocr openai
python cookbook/91_tools/docling_tools/run.pyFor details, see Docling Tools cookbook.