Skip to content

Document Conversion

AgentPool provides document conversion capabilities to transform various document formats (PDFs, Office documents, HTML, etc.) into markdown text that can be processed by language models.

Overview

The conversion system:

  • Supports multiple document formats through different converters
  • Can handle both files and raw content
  • Uses async I/O for file operations
  • Includes a fallback plain text converter

Usage

Through Conversation Manager

Documents can be added to an agent's context:

# Add document from path
await agent.conversation.add_context_from_path(
    "document.pdf",
    convert_to_md=True  # Enable markdown conversion
)

# Add raw text
agent.conversation.add_context_message(text, source="notes.txt")

Automatic Conversion

When passing paths to Agent.run(), documents are automatically converted if needed:

# Will convert PDF if model doesn't support it directly
await agent.run(Path("document.pdf"))

# Multiple inputs
await agent.run(
    "Analyze this document:",
    Path("document.pdf"),
    "And compare it with:",
    Path("other.docx")
)

Configuration

Document conversion is configured globally in the manifest's conversion section; the converters come from docler:

conversion:
  default_provider: markitdown
  max_size: 10485760      # bytes
  providers:
    - type: markitdown
    - type: marker

The same converter configs are used by toolsets that convert documents (for example the file_access toolset's conversion option).

ConversionConfig

Global conversion configuration.

ConversionConfig (YAML)
1
2
3
4
conversion:
  providers: null  # List of configured converter providers.
  default_provider: null  # Name of default provider for conversions.
  max_size: null  # Global size limit for all converters.

Available Converters

type Name Description
datalab DataLabConfig Configuration for DataLab-based converter.
docling DoclingConverterConfig Configuration for docling-based converter.
docling_remote DoclingRemoteConfig Configuration for remote Docling service.
llm LLMConverterConfig Configuration for LLM-based converter.
markitdown MarkItDownConfig Configuration for MarkItDown-based converter.
mistral MistralConfig Configuration for Mistral-based converter.
llamaparse LlamaParseConfig Configuration for LlamaParse-based converter.
azure AzureConfig Configuration for Azure Document Intelligence converter.
upstage UpstageConfig Configuration for Upstage Document AI converter.
aggregated AggregatedConverterConfig Configuration for the aggregated converter.
marker MarkerConfig Configuration for Marker-based converter.

DataLabConfig

Configuration for DataLab-based converter.

DataLabConfig (YAML)
1
2
3
4
5
6
7
8
9
providers:
- type: datalab
  page_range: null  # Page range(s) to extract, like "1-5,7-10" (1-based).
  languages: !!set  # List of supported languages for the converter.
    en: null
  api_key: '!ENV ENV_VAR_NAME'  # DataLab API key. If None, will try env var DATALAB_API_KEY.
  force_ocr: false  # Whether to force OCR on every page.
  use_llm: false  # Whether to use LLM for enhanced accuracy.
  max_pages: null  # Maximum number of pages to process.

DoclingConverterConfig

Configuration for docling-based converter.

DoclingConverterConfig (YAML)
1
2
3
4
5
6
7
8
providers:
- type: docling
  page_range: null  # Page range(s) to extract, like "1-5,7-10" (1-based).
  languages: !!set  # List of supported languages for the converter.
    en: null
  image_scale: 2.0  # Scale factor for image resizing.
  generate_images: true  # Whether to generate images.
  ocr_engine: rapid_ocr  # OCR engine to use. Defaults to RapidOCR, which the docling extra installs.

DoclingRemoteConfig

Configuration for remote Docling service.

DoclingRemoteConfig (YAML)
providers:
- type: docling_remote
  page_range: null  # Page range(s) to extract, like "1-5,7-10" (1-based).
  languages: !!set  # List of supported languages for the converter.
    en: null
  api_key: '!ENV ENV_VAR_NAME'  # Optional API key for auth.
  endpoint: !!python/object:pydantic.networks.HttpUrl  # Base URL of the Docling service.
    _url: !!python/object/new:pydantic_core._pydantic_core.Url
    - http://localhost:5001/
  ocr_engine: easy_ocr  # OCR engine to use.
  pdf_backend: dlparse_v4  # PDF backend to use.
  table_mode: fast  # Table mode to use.
  force_ocr: false  # Whether to force OCR even on digital documents.
  image_scale: 2.0  # Scale factor for image resolution.
  do_table_structure: true  # Extract table structure.
  do_code_enrichment: false  # Enable code extraction.
  do_formula_enrichment: false  # Enable formula extraction.
  do_picture_classification: false  # Enable picture classification.
  do_picture_description: false  # Enable picture description.

LLMConverterConfig

Configuration for LLM-based converter.

LLMConverterConfig (YAML)
providers:
- type: llm
  page_range: null  # Page range(s) to extract, like "1-5,7-10" (1-based).
  languages: !!set  # List of supported languages for the converter.
    en: null
  model: google-gla:gemini-3.8-flash  # Identifier for an AI model, optionally including provider.
  system_prompt: '  # Optional system prompt to guide conversion.

    You are a OCR engine that can parse PDF documents & images into markdown formatted
    text.

    '
  user_prompt: '  # Custom prompt for the conversion task.

    Convert this PDF document to markdown format

    Preserve the original formatting and structure where possible.

    Include any important tables or lists.

    Describe any images you see in brackets.

    Indicate page breaks with a specially formatted JSON comment,

    like <!-- docler:page_break {"next_page":2} --> for page 2.

    Only respond with the content, nothing else.

    '

MarkItDownConfig

Configuration for MarkItDown-based converter.

MarkItDownConfig (YAML)
1
2
3
4
5
providers:
- type: markitdown
  page_range: null  # Page range(s) to extract, like "1-5,7-10" (1-based).
  languages: !!set  # List of supported languages for the converter.
    en: null

MistralConfig

Configuration for Mistral-based converter.

MistralConfig (YAML)
1
2
3
4
5
6
providers:
- type: mistral
  page_range: null  # Page range(s) to extract, like "1-5,7-10" (1-based).
  languages: !!set  # List of supported languages for the converter.
    en: null
  api_key: '!ENV ENV_VAR_NAME'  # Mistral API key. If None, will try env var MISTRAL_API_KEY.

LlamaParseConfig

Configuration for LlamaParse-based converter.

LlamaParseConfig (YAML)
providers:
- type: llamaparse
  page_range: null  # Page range(s) to extract, like "1-5,7-10" (1-based).
  languages: !!set  # List of supported languages for the converter.
    en: null
  api_key: '!ENV ENV_VAR_NAME'  # LlamaParse API key. Falls back to LLAMAPARSE_API_KEY env var.
  adaptive_long_table: false  # Whether to use adaptive long table.
  parse_mode: parse_page_with_llm  # Legacy parse mode, used when no tier is set.
  tier: null  # Parsing tier. Takes precedence over parse_mode when set.
  skip_diagonal_text: false  # Whether to skip diagonal text.
  disable_ocr: false  # Whether to disable OCR for images.
  continuous_mode: true  # Merge tables spanning pages. Only supported with a tier.
  html_tables: false  # Whether to output HTML tables instead of markdown.

AzureConfig

Configuration for Azure Document Intelligence converter.

AzureConfig (YAML)
1
2
3
4
5
6
7
8
9
providers:
- type: azure
  page_range: null  # Page range(s) to extract, like "1-5,7-10" (1-based).
  languages: !!set  # List of supported languages for the converter.
    en: null
  endpoint: null  # Azure endpoint URL. Falls back to AZURE_DOC_INTELLIGENCE_ENDPOINT envvar.
  api_key: '!ENV ENV_VAR_NAME'  # Azure API key. Falls back to AZURE_DOC_INTELLIGENCE_KEY env var.
  model: prebuilt-layout  # Pre-trained model to use.
  additional_features: !!set {}  # Optional add-on capabilities like BARCODES, FORMULAS, OCR_HIGH_RESOLUTION etc.

UpstageConfig

Configuration for Upstage Document AI converter.

UpstageConfig (YAML)
providers:
- type: upstage
  page_range: null  # Page range(s) to extract, like "1-5,7-10" (1-based).
  api_key: '!ENV ENV_VAR_NAME'  # Upstage API key. Falls back to UPSTAGE_API_KEY env var.
  base_url: !!python/object:pydantic.networks.HttpUrl  # API endpoint URL.
    _url: !!python/object/new:pydantic_core._pydantic_core.Url
    - https://api.upstage.ai/v1/document-ai/document-parse
  ocr: auto  # OCR mode ('auto' or 'force').
  base64_categories: !!set  # Element categories to encode in base64.
    figure: null
    chart: null

AggregatedConverterConfig

Configuration for the aggregated converter.

AggregatedConverterConfig (YAML)
1
2
3
4
5
providers:
- type: aggregated
  page_range: null
  converters: []
  mime_preferences: {}

MarkerConfig

Configuration for Marker-based converter.

MarkerConfig (YAML)
1
2
3
4
5
providers:
- type: marker
  page_range: null  # Page range(s) to extract, like "1-5,7-10" (1-based).
  dpi: 192  # DPI setting for image extraction.
  llm_provider: null  # Language model provider to use for OCR.