docling-agent 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- docling_agent-0.1.0/.gitignore +214 -0
- docling_agent-0.1.0/LICENSE +21 -0
- docling_agent-0.1.0/PKG-INFO +208 -0
- docling_agent-0.1.0/README.md +163 -0
- docling_agent-0.1.0/docling_agent/__init__.py +0 -0
- docling_agent-0.1.0/docling_agent/agent/__init__.py +0 -0
- docling_agent-0.1.0/docling_agent/agent/base.py +80 -0
- docling_agent-0.1.0/docling_agent/agent/base_functions.py +590 -0
- docling_agent-0.1.0/docling_agent/agent/editor.py +383 -0
- docling_agent-0.1.0/docling_agent/agent/enricher.py +631 -0
- docling_agent-0.1.0/docling_agent/agent/extractor.py +148 -0
- docling_agent-0.1.0/docling_agent/agent/library.py +231 -0
- docling_agent-0.1.0/docling_agent/agent/orchestrator.py +531 -0
- docling_agent-0.1.0/docling_agent/agent/rag.py +449 -0
- docling_agent-0.1.0/docling_agent/agent/rag_models.py +36 -0
- docling_agent-0.1.0/docling_agent/agent/writer.py +615 -0
- docling_agent-0.1.0/docling_agent/agent_models.py +137 -0
- docling_agent-0.1.0/docling_agent/agents.py +36 -0
- docling_agent-0.1.0/docling_agent/cli/__init__.py +148 -0
- docling_agent-0.1.0/docling_agent/logging.py +45 -0
- docling_agent-0.1.0/docling_agent/py.typed +0 -0
- docling_agent-0.1.0/docling_agent/resources/__init__.py +1 -0
- docling_agent-0.1.0/docling_agent/resources/prompts.py +128 -0
- docling_agent-0.1.0/docling_agent/task_model.py +156 -0
- docling_agent-0.1.0/pyproject.toml +209 -0
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
*~
|
|
2
|
+
*.DS_Store
|
|
3
|
+
examples/example_02_edit_resources/*.html
|
|
4
|
+
|
|
5
|
+
# Byte-compiled / optimized / DLL files
|
|
6
|
+
__pycache__/
|
|
7
|
+
*.py[codz]
|
|
8
|
+
*$py.class
|
|
9
|
+
|
|
10
|
+
# C extensions
|
|
11
|
+
*.so
|
|
12
|
+
|
|
13
|
+
# Distribution / packaging
|
|
14
|
+
.Python
|
|
15
|
+
build/
|
|
16
|
+
develop-eggs/
|
|
17
|
+
dist/
|
|
18
|
+
downloads/
|
|
19
|
+
eggs/
|
|
20
|
+
.eggs/
|
|
21
|
+
lib/
|
|
22
|
+
lib64/
|
|
23
|
+
parts/
|
|
24
|
+
sdist/
|
|
25
|
+
var/
|
|
26
|
+
wheels/
|
|
27
|
+
share/python-wheels/
|
|
28
|
+
*.egg-info/
|
|
29
|
+
.installed.cfg
|
|
30
|
+
*.egg
|
|
31
|
+
MANIFEST
|
|
32
|
+
|
|
33
|
+
# PyInstaller
|
|
34
|
+
# Usually these files are written by a python script from a template
|
|
35
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
36
|
+
*.manifest
|
|
37
|
+
*.spec
|
|
38
|
+
|
|
39
|
+
# Installer logs
|
|
40
|
+
pip-log.txt
|
|
41
|
+
pip-delete-this-directory.txt
|
|
42
|
+
|
|
43
|
+
# Unit test / coverage reports
|
|
44
|
+
htmlcov/
|
|
45
|
+
.tox/
|
|
46
|
+
.nox/
|
|
47
|
+
.coverage
|
|
48
|
+
.coverage.*
|
|
49
|
+
.cache
|
|
50
|
+
nosetests.xml
|
|
51
|
+
coverage.xml
|
|
52
|
+
*.cover
|
|
53
|
+
*.py.cover
|
|
54
|
+
.hypothesis/
|
|
55
|
+
.pytest_cache/
|
|
56
|
+
cover/
|
|
57
|
+
|
|
58
|
+
# Translations
|
|
59
|
+
*.mo
|
|
60
|
+
*.pot
|
|
61
|
+
|
|
62
|
+
# Django stuff:
|
|
63
|
+
*.log
|
|
64
|
+
local_settings.py
|
|
65
|
+
db.sqlite3
|
|
66
|
+
db.sqlite3-journal
|
|
67
|
+
|
|
68
|
+
# Flask stuff:
|
|
69
|
+
instance/
|
|
70
|
+
.webassets-cache
|
|
71
|
+
|
|
72
|
+
# Scrapy stuff:
|
|
73
|
+
.scrapy
|
|
74
|
+
|
|
75
|
+
# Sphinx documentation
|
|
76
|
+
docs/_build/
|
|
77
|
+
|
|
78
|
+
# PyBuilder
|
|
79
|
+
.pybuilder/
|
|
80
|
+
target/
|
|
81
|
+
|
|
82
|
+
# Jupyter Notebook
|
|
83
|
+
.ipynb_checkpoints
|
|
84
|
+
|
|
85
|
+
# IPython
|
|
86
|
+
profile_default/
|
|
87
|
+
ipython_config.py
|
|
88
|
+
|
|
89
|
+
# pyenv
|
|
90
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
91
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
92
|
+
# .python-version
|
|
93
|
+
|
|
94
|
+
# pipenv
|
|
95
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
96
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
97
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
98
|
+
# install all needed dependencies.
|
|
99
|
+
#Pipfile.lock
|
|
100
|
+
|
|
101
|
+
# UV
|
|
102
|
+
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
|
|
103
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
104
|
+
# commonly ignored for libraries.
|
|
105
|
+
#uv.lock
|
|
106
|
+
|
|
107
|
+
# poetry
|
|
108
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
109
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
110
|
+
# commonly ignored for libraries.
|
|
111
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
112
|
+
#poetry.lock
|
|
113
|
+
#poetry.toml
|
|
114
|
+
|
|
115
|
+
# pdm
|
|
116
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
117
|
+
# pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
|
|
118
|
+
# https://pdm-project.org/en/latest/usage/project/#working-with-version-control
|
|
119
|
+
#pdm.lock
|
|
120
|
+
#pdm.toml
|
|
121
|
+
.pdm-python
|
|
122
|
+
.pdm-build/
|
|
123
|
+
|
|
124
|
+
# pixi
|
|
125
|
+
# Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
|
|
126
|
+
#pixi.lock
|
|
127
|
+
# Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
|
|
128
|
+
# in the .venv directory. It is recommended not to include this directory in version control.
|
|
129
|
+
.pixi
|
|
130
|
+
|
|
131
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
132
|
+
__pypackages__/
|
|
133
|
+
|
|
134
|
+
# Celery stuff
|
|
135
|
+
celerybeat-schedule
|
|
136
|
+
celerybeat.pid
|
|
137
|
+
|
|
138
|
+
# SageMath parsed files
|
|
139
|
+
*.sage.py
|
|
140
|
+
|
|
141
|
+
# Environments
|
|
142
|
+
.env
|
|
143
|
+
.envrc
|
|
144
|
+
.venv
|
|
145
|
+
env/
|
|
146
|
+
venv/
|
|
147
|
+
ENV/
|
|
148
|
+
env.bak/
|
|
149
|
+
venv.bak/
|
|
150
|
+
|
|
151
|
+
# Spyder project settings
|
|
152
|
+
.spyderproject
|
|
153
|
+
.spyproject
|
|
154
|
+
|
|
155
|
+
# Rope project settings
|
|
156
|
+
.ropeproject
|
|
157
|
+
|
|
158
|
+
# mkdocs documentation
|
|
159
|
+
/site
|
|
160
|
+
|
|
161
|
+
# mypy
|
|
162
|
+
.mypy_cache/
|
|
163
|
+
.dmypy.json
|
|
164
|
+
dmypy.json
|
|
165
|
+
|
|
166
|
+
# Pyre type checker
|
|
167
|
+
.pyre/
|
|
168
|
+
|
|
169
|
+
# pytype static type analyzer
|
|
170
|
+
.pytype/
|
|
171
|
+
|
|
172
|
+
# Cython debug symbols
|
|
173
|
+
cython_debug/
|
|
174
|
+
|
|
175
|
+
# PyCharm
|
|
176
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
177
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
178
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
179
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
180
|
+
#.idea/
|
|
181
|
+
|
|
182
|
+
# Abstra
|
|
183
|
+
# Abstra is an AI-powered process automation framework.
|
|
184
|
+
# Ignore directories containing user credentials, local state, and settings.
|
|
185
|
+
# Learn more at https://abstra.io/docs
|
|
186
|
+
.abstra/
|
|
187
|
+
|
|
188
|
+
# Visual Studio Code
|
|
189
|
+
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
|
|
190
|
+
# that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
|
|
191
|
+
# and can be added to the global gitignore or merged into this file. However, if you prefer,
|
|
192
|
+
# you could uncomment the following to ignore the entire vscode folder
|
|
193
|
+
# .vscode/
|
|
194
|
+
|
|
195
|
+
# Ruff stuff:
|
|
196
|
+
.ruff_cache/
|
|
197
|
+
|
|
198
|
+
# PyPI configuration file
|
|
199
|
+
.pypirc
|
|
200
|
+
|
|
201
|
+
# Cursor
|
|
202
|
+
# Cursor is an AI-powered code editor. `.cursorignore` specifies files/directories to
|
|
203
|
+
# exclude from AI features like autocomplete and code analysis. Recommended for sensitive data
|
|
204
|
+
# refer to https://docs.cursor.com/context/ignore-files
|
|
205
|
+
.cursorignore
|
|
206
|
+
.cursorindexingignore
|
|
207
|
+
|
|
208
|
+
# Marimo
|
|
209
|
+
marimo/_static/
|
|
210
|
+
marimo/_lsp/
|
|
211
|
+
__marimo__/
|
|
212
|
+
|
|
213
|
+
# Folder for example runs
|
|
214
|
+
scratch/
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Docling Project
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: docling-agent
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A python library to simplify agentic operations on documents, such as writing, editing, summarizing, extracting, and enriching.
|
|
5
|
+
Project-URL: homepage, https://github.com/docling-project
|
|
6
|
+
Project-URL: repository, https://github.com/docling-project/docling-agent
|
|
7
|
+
Project-URL: issues, https://github.com/docling-project/docling-agent/issues
|
|
8
|
+
Project-URL: changelog, https://github.com/docling-project/docling-agent/blob/main/CHANGELOG.md
|
|
9
|
+
Author-email: Peter Staar <taa@zurich.ibm.com>
|
|
10
|
+
Maintainer-email: Michele Dolfi <dol@zurich.ibm.com>, Cesar Berrospi Ramis <ceb@zurich.ibm.com>, Panos Vagenas <pva@zurich.ibm.com>, Christoph Auer <cau@zurich.ibm.com>, Peter Staar <taa@zurich.ibm.com>
|
|
11
|
+
License-Expression: MIT
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Keywords: agent,agentic,docling,document processing,editing,enrichment,extraction,summarization,writing
|
|
14
|
+
Classifier: Development Status :: 3 - Alpha
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: Intended Audience :: Science/Research
|
|
17
|
+
Classifier: Natural Language :: English
|
|
18
|
+
Classifier: Operating System :: OS Independent
|
|
19
|
+
Classifier: Programming Language :: Python :: 3
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
25
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
26
|
+
Classifier: Topic :: Scientific/Engineering :: Information Analysis
|
|
27
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
28
|
+
Classifier: Typing :: Typed
|
|
29
|
+
Requires-Python: <4.0,>=3.10
|
|
30
|
+
Requires-Dist: boto3~=1.35
|
|
31
|
+
Requires-Dist: docling-core>=2.70.2
|
|
32
|
+
Requires-Dist: docling>=2.61.0
|
|
33
|
+
Requires-Dist: fastparquet~=2024.11
|
|
34
|
+
Requires-Dist: httpx~=0.28
|
|
35
|
+
Requires-Dist: mellea>=0.3
|
|
36
|
+
Requires-Dist: pandas~=2.2
|
|
37
|
+
Requires-Dist: pyarrow>=19.0
|
|
38
|
+
Requires-Dist: pydantic-settings~=2.4
|
|
39
|
+
Requires-Dist: pydantic~=2.10
|
|
40
|
+
Requires-Dist: pyyaml>=6.0
|
|
41
|
+
Requires-Dist: typer>=0.12.5
|
|
42
|
+
Provides-Extra: vlm
|
|
43
|
+
Requires-Dist: docling[vlm]~=2.53; extra == 'vlm'
|
|
44
|
+
Description-Content-Type: text/markdown
|
|
45
|
+
|
|
46
|
+
[](https://github.com/astral-sh/uv)
|
|
47
|
+
[](https://github.com/astral-sh/ruff)
|
|
48
|
+
[](https://pydantic.dev)
|
|
49
|
+
[](https://github.com/pre-commit/pre-commit)
|
|
50
|
+
[](https://opensource.org/licenses/MIT)
|
|
51
|
+
[](https://lfaidata.foundation/projects/)
|
|
52
|
+
|
|
53
|
+
# Docling-Agent
|
|
54
|
+
|
|
55
|
+
Docling-agent simplifies agentic operation on documents, such as writing, editing, summarizing, etc.
|
|
56
|
+
|
|
57
|
+
> [!NOTE]
|
|
58
|
+
> **This package is still immature and work-in-progress. We are happy to get comments, suggestions, code contributions, etc!**
|
|
59
|
+
|
|
60
|
+
## Features
|
|
61
|
+
|
|
62
|
+
- [Document writing](examples/example_01_write_report.py): Generate well-structured reports from natural prompts and export to JSON/Markdown/HTML.
|
|
63
|
+
- [Targeted editing](examples/example_02_edit_report.py): Load an existing Docling JSON and apply focused edits with natural-language tasks.
|
|
64
|
+
- [Schema-guided extraction](examples/example_03_extract_schema.py): Extract typed fields from PDFs/images using a simple schema and produce HTML reports. See examples on curriculum_vitae, papers, invoices, etc.
|
|
65
|
+
- [Document enrichment](examples/example_04_enrich_document.py): Enrich existing documents with summaries, search keywords, key entities, and item classifications (language/function).
|
|
66
|
+
- Model-agnostic: Plug in different backends via [Mellea](https://github.com/generative-computing/mellea) `model_ids` (e.g., OpenAI GPT OSS, IBM Granite).
|
|
67
|
+
- Simple API surface: Use `agent.run(...)` with `DoclingDocument` in/out; save via `save_as_*` helpers.
|
|
68
|
+
- Optional tools: Integrate external tools (e.g., MCP) when available.
|
|
69
|
+
|
|
70
|
+
Quick start (writing):
|
|
71
|
+
|
|
72
|
+
```python
|
|
73
|
+
from mellea.backends import model_ids
|
|
74
|
+
from docling_agent.agents import DoclingWritingAgent
|
|
75
|
+
|
|
76
|
+
agent = DoclingWritingAgent(model_id=model_ids.OPENAI_GPT_OSS_20B)
|
|
77
|
+
doc = agent.run("Write a one-page summary about polymers in food packaging.")
|
|
78
|
+
doc.save_as_html("report.html")
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Installation
|
|
82
|
+
|
|
83
|
+
**Coming soon**
|
|
84
|
+
|
|
85
|
+
## Getting started
|
|
86
|
+
|
|
87
|
+
Below are three minimal, end-to-end examples mirroring the scripts in the examples folder. Each snippet shows how to initialize an agent, run a task, and save the result.
|
|
88
|
+
|
|
89
|
+
### Write a new document (see [example](examples/example_01_write_report.py)):
|
|
90
|
+
|
|
91
|
+
```python
|
|
92
|
+
from mellea.backends import model_ids
|
|
93
|
+
from docling_agent.agents import DoclingWritingAgent
|
|
94
|
+
|
|
95
|
+
agent = DoclingWritingAgent(model_id=model_ids.OPENAI_GPT_OSS_20B)
|
|
96
|
+
doc = agent.run("Write a brief report on polymers in food packaging with a small comparison table.")
|
|
97
|
+
doc.save_as_html("./scratch/report.html")
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### Edit an existing document (see [example](examples/example_02_edit_report.py)):
|
|
101
|
+
|
|
102
|
+
Use natural-language tasks to update a Docling JSON. You can run multiple tasks to iteratively refine content, structure, or formatting.
|
|
103
|
+
|
|
104
|
+
```python
|
|
105
|
+
from pathlib import Path
|
|
106
|
+
from mellea.backends import model_ids
|
|
107
|
+
from docling_core.types.doc.document import DoclingDocument
|
|
108
|
+
from docling_agent.agents import DoclingEditingAgent
|
|
109
|
+
|
|
110
|
+
ipath = Path("./examples/example_02_edit_resources/20250815_125216.json")
|
|
111
|
+
doc = DoclingDocument.load_from_json(ipath)
|
|
112
|
+
|
|
113
|
+
agent = DoclingEditingAgent(model_id=model_ids.OPENAI_GPT_OSS_20B)
|
|
114
|
+
updated = agent.run(task="Put polymer abbreviations in a separate column in the first table.", document=doc)
|
|
115
|
+
updated.save_as_html("./scratch/updated_table.html")
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### Extract structured data with a schema (see [example](examples/example_03_extract_schema.py)):
|
|
119
|
+
|
|
120
|
+
Define a simple schema and provide a list of files (PDFs/images). The agent produces an HTML report with extracted fields.
|
|
121
|
+
|
|
122
|
+
```python
|
|
123
|
+
from pathlib import Path
|
|
124
|
+
from mellea.backends import model_ids
|
|
125
|
+
from docling_agent.agents import DoclingExtractingAgent
|
|
126
|
+
|
|
127
|
+
schema = {"invoice-number": "string", "total": "float", "currency": "string"}
|
|
128
|
+
sources = sorted([p for p in Path("./examples/example_03_extract/invoices").rglob("*.*") if p.suffix.lower() in {".pdf", ".png", ".jpg", ".jpeg"}])
|
|
129
|
+
|
|
130
|
+
agent = DoclingExtractingAgent(model_id=model_ids.OPENAI_GPT_OSS_20B)
|
|
131
|
+
report = agent.run(task=str(schema), sources=sources)
|
|
132
|
+
report.save_as_html("./scratch/invoices_extraction_report.html")
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### Enrich an existing document (see [example](examples/example_04_enrich_document.py)):
|
|
136
|
+
|
|
137
|
+
Run enrichment passes like summaries, keywords, entities, and classifications on a Docling JSON.
|
|
138
|
+
|
|
139
|
+
```python
|
|
140
|
+
from pathlib import Path
|
|
141
|
+
from mellea.backends import model_ids
|
|
142
|
+
from docling_core.types.doc.document import DoclingDocument
|
|
143
|
+
from docling_agent.agents import DoclingEnrichingAgent
|
|
144
|
+
|
|
145
|
+
ipath = Path("./examples/example_02_edit_resources/20250815_125216.json")
|
|
146
|
+
doc = DoclingDocument.load_from_json(ipath)
|
|
147
|
+
|
|
148
|
+
agent = DoclingEnrichingAgent(model_id=model_ids.OPENAI_GPT_OSS_20B)
|
|
149
|
+
enriched = agent.run(task="Summarize each paragraph, table, and section header.", document=doc)
|
|
150
|
+
enriched.save_as_html("./scratch/enriched_summaries.html")
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
## Documentation
|
|
154
|
+
|
|
155
|
+
**Coming soon**
|
|
156
|
+
|
|
157
|
+
## Examples
|
|
158
|
+
|
|
159
|
+
Go hands-on with our [examples](https://docling-project.github.io/docling/examples/),
|
|
160
|
+
demonstrating how to address different application use cases with Docling.
|
|
161
|
+
|
|
162
|
+
## Integrations
|
|
163
|
+
|
|
164
|
+
To further accelerate your AI application development, check out Docling's native
|
|
165
|
+
[integrations](https://docling-project.github.io/docling/integrations/) with popular frameworks
|
|
166
|
+
and tools.
|
|
167
|
+
|
|
168
|
+
## Get help and support
|
|
169
|
+
|
|
170
|
+
Please feel free to connect with us using the [discussion section](https://github.com/docling-project/docling/discussions).
|
|
171
|
+
|
|
172
|
+
## Technical report
|
|
173
|
+
|
|
174
|
+
For more details on Docling's inner workings, check out the [Docling Technical Report](https://arxiv.org/abs/2408.09869).
|
|
175
|
+
|
|
176
|
+
## Contributing
|
|
177
|
+
|
|
178
|
+
Please read [Contributing to Docling](https://github.com/docling-project/docling/blob/main/CONTRIBUTING.md) for details.
|
|
179
|
+
|
|
180
|
+
## References
|
|
181
|
+
|
|
182
|
+
If you use Docling or Docling-agent in your projects, please consider citing the following:
|
|
183
|
+
|
|
184
|
+
```bib
|
|
185
|
+
@techreport{Docling,
|
|
186
|
+
author = {Deep Search Team},
|
|
187
|
+
month = {8},
|
|
188
|
+
title = {Docling Technical Report},
|
|
189
|
+
url = {https://arxiv.org/abs/2408.09869},
|
|
190
|
+
eprint = {2408.09869},
|
|
191
|
+
doi = {10.48550/arXiv.2408.09869},
|
|
192
|
+
version = {1.0.0},
|
|
193
|
+
year = {2024}
|
|
194
|
+
}
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
## License
|
|
198
|
+
|
|
199
|
+
The Docling codebase is under MIT license.
|
|
200
|
+
For individual model usage, please refer to the model licenses found in the original packages.
|
|
201
|
+
|
|
202
|
+
## LF AI & Data
|
|
203
|
+
|
|
204
|
+
Docling is hosted as a project in the [LF AI & Data Foundation](https://lfaidata.foundation/projects/).
|
|
205
|
+
|
|
206
|
+
### IBM ❤️ Open Source AI
|
|
207
|
+
|
|
208
|
+
The project was started by the AI for knowledge team at IBM Research Zurich.
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
[](https://github.com/astral-sh/uv)
|
|
2
|
+
[](https://github.com/astral-sh/ruff)
|
|
3
|
+
[](https://pydantic.dev)
|
|
4
|
+
[](https://github.com/pre-commit/pre-commit)
|
|
5
|
+
[](https://opensource.org/licenses/MIT)
|
|
6
|
+
[](https://lfaidata.foundation/projects/)
|
|
7
|
+
|
|
8
|
+
# Docling-Agent
|
|
9
|
+
|
|
10
|
+
Docling-agent simplifies agentic operation on documents, such as writing, editing, summarizing, etc.
|
|
11
|
+
|
|
12
|
+
> [!NOTE]
|
|
13
|
+
> **This package is still immature and work-in-progress. We are happy to get comments, suggestions, code contributions, etc!**
|
|
14
|
+
|
|
15
|
+
## Features
|
|
16
|
+
|
|
17
|
+
- [Document writing](examples/example_01_write_report.py): Generate well-structured reports from natural prompts and export to JSON/Markdown/HTML.
|
|
18
|
+
- [Targeted editing](examples/example_02_edit_report.py): Load an existing Docling JSON and apply focused edits with natural-language tasks.
|
|
19
|
+
- [Schema-guided extraction](examples/example_03_extract_schema.py): Extract typed fields from PDFs/images using a simple schema and produce HTML reports. See examples on curriculum_vitae, papers, invoices, etc.
|
|
20
|
+
- [Document enrichment](examples/example_04_enrich_document.py): Enrich existing documents with summaries, search keywords, key entities, and item classifications (language/function).
|
|
21
|
+
- Model-agnostic: Plug in different backends via [Mellea](https://github.com/generative-computing/mellea) `model_ids` (e.g., OpenAI GPT OSS, IBM Granite).
|
|
22
|
+
- Simple API surface: Use `agent.run(...)` with `DoclingDocument` in/out; save via `save_as_*` helpers.
|
|
23
|
+
- Optional tools: Integrate external tools (e.g., MCP) when available.
|
|
24
|
+
|
|
25
|
+
Quick start (writing):
|
|
26
|
+
|
|
27
|
+
```python
|
|
28
|
+
from mellea.backends import model_ids
|
|
29
|
+
from docling_agent.agents import DoclingWritingAgent
|
|
30
|
+
|
|
31
|
+
agent = DoclingWritingAgent(model_id=model_ids.OPENAI_GPT_OSS_20B)
|
|
32
|
+
doc = agent.run("Write a one-page summary about polymers in food packaging.")
|
|
33
|
+
doc.save_as_html("report.html")
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Installation
|
|
37
|
+
|
|
38
|
+
**Coming soon**
|
|
39
|
+
|
|
40
|
+
## Getting started
|
|
41
|
+
|
|
42
|
+
Below are three minimal, end-to-end examples mirroring the scripts in the examples folder. Each snippet shows how to initialize an agent, run a task, and save the result.
|
|
43
|
+
|
|
44
|
+
### Write a new document (see [example](examples/example_01_write_report.py)):
|
|
45
|
+
|
|
46
|
+
```python
|
|
47
|
+
from mellea.backends import model_ids
|
|
48
|
+
from docling_agent.agents import DoclingWritingAgent
|
|
49
|
+
|
|
50
|
+
agent = DoclingWritingAgent(model_id=model_ids.OPENAI_GPT_OSS_20B)
|
|
51
|
+
doc = agent.run("Write a brief report on polymers in food packaging with a small comparison table.")
|
|
52
|
+
doc.save_as_html("./scratch/report.html")
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Edit an existing document (see [example](examples/example_02_edit_report.py)):
|
|
56
|
+
|
|
57
|
+
Use natural-language tasks to update a Docling JSON. You can run multiple tasks to iteratively refine content, structure, or formatting.
|
|
58
|
+
|
|
59
|
+
```python
|
|
60
|
+
from pathlib import Path
|
|
61
|
+
from mellea.backends import model_ids
|
|
62
|
+
from docling_core.types.doc.document import DoclingDocument
|
|
63
|
+
from docling_agent.agents import DoclingEditingAgent
|
|
64
|
+
|
|
65
|
+
ipath = Path("./examples/example_02_edit_resources/20250815_125216.json")
|
|
66
|
+
doc = DoclingDocument.load_from_json(ipath)
|
|
67
|
+
|
|
68
|
+
agent = DoclingEditingAgent(model_id=model_ids.OPENAI_GPT_OSS_20B)
|
|
69
|
+
updated = agent.run(task="Put polymer abbreviations in a separate column in the first table.", document=doc)
|
|
70
|
+
updated.save_as_html("./scratch/updated_table.html")
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### Extract structured data with a schema (see [example](examples/example_03_extract_schema.py)):
|
|
74
|
+
|
|
75
|
+
Define a simple schema and provide a list of files (PDFs/images). The agent produces an HTML report with extracted fields.
|
|
76
|
+
|
|
77
|
+
```python
|
|
78
|
+
from pathlib import Path
|
|
79
|
+
from mellea.backends import model_ids
|
|
80
|
+
from docling_agent.agents import DoclingExtractingAgent
|
|
81
|
+
|
|
82
|
+
schema = {"invoice-number": "string", "total": "float", "currency": "string"}
|
|
83
|
+
sources = sorted([p for p in Path("./examples/example_03_extract/invoices").rglob("*.*") if p.suffix.lower() in {".pdf", ".png", ".jpg", ".jpeg"}])
|
|
84
|
+
|
|
85
|
+
agent = DoclingExtractingAgent(model_id=model_ids.OPENAI_GPT_OSS_20B)
|
|
86
|
+
report = agent.run(task=str(schema), sources=sources)
|
|
87
|
+
report.save_as_html("./scratch/invoices_extraction_report.html")
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Enrich an existing document (see [example](examples/example_04_enrich_document.py)):
|
|
91
|
+
|
|
92
|
+
Run enrichment passes like summaries, keywords, entities, and classifications on a Docling JSON.
|
|
93
|
+
|
|
94
|
+
```python
|
|
95
|
+
from pathlib import Path
|
|
96
|
+
from mellea.backends import model_ids
|
|
97
|
+
from docling_core.types.doc.document import DoclingDocument
|
|
98
|
+
from docling_agent.agents import DoclingEnrichingAgent
|
|
99
|
+
|
|
100
|
+
ipath = Path("./examples/example_02_edit_resources/20250815_125216.json")
|
|
101
|
+
doc = DoclingDocument.load_from_json(ipath)
|
|
102
|
+
|
|
103
|
+
agent = DoclingEnrichingAgent(model_id=model_ids.OPENAI_GPT_OSS_20B)
|
|
104
|
+
enriched = agent.run(task="Summarize each paragraph, table, and section header.", document=doc)
|
|
105
|
+
enriched.save_as_html("./scratch/enriched_summaries.html")
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## Documentation
|
|
109
|
+
|
|
110
|
+
**Coming soon**
|
|
111
|
+
|
|
112
|
+
## Examples
|
|
113
|
+
|
|
114
|
+
Go hands-on with our [examples](https://docling-project.github.io/docling/examples/),
|
|
115
|
+
demonstrating how to address different application use cases with Docling.
|
|
116
|
+
|
|
117
|
+
## Integrations
|
|
118
|
+
|
|
119
|
+
To further accelerate your AI application development, check out Docling's native
|
|
120
|
+
[integrations](https://docling-project.github.io/docling/integrations/) with popular frameworks
|
|
121
|
+
and tools.
|
|
122
|
+
|
|
123
|
+
## Get help and support
|
|
124
|
+
|
|
125
|
+
Please feel free to connect with us using the [discussion section](https://github.com/docling-project/docling/discussions).
|
|
126
|
+
|
|
127
|
+
## Technical report
|
|
128
|
+
|
|
129
|
+
For more details on Docling's inner workings, check out the [Docling Technical Report](https://arxiv.org/abs/2408.09869).
|
|
130
|
+
|
|
131
|
+
## Contributing
|
|
132
|
+
|
|
133
|
+
Please read [Contributing to Docling](https://github.com/docling-project/docling/blob/main/CONTRIBUTING.md) for details.
|
|
134
|
+
|
|
135
|
+
## References
|
|
136
|
+
|
|
137
|
+
If you use Docling or Docling-agent in your projects, please consider citing the following:
|
|
138
|
+
|
|
139
|
+
```bib
|
|
140
|
+
@techreport{Docling,
|
|
141
|
+
author = {Deep Search Team},
|
|
142
|
+
month = {8},
|
|
143
|
+
title = {Docling Technical Report},
|
|
144
|
+
url = {https://arxiv.org/abs/2408.09869},
|
|
145
|
+
eprint = {2408.09869},
|
|
146
|
+
doi = {10.48550/arXiv.2408.09869},
|
|
147
|
+
version = {1.0.0},
|
|
148
|
+
year = {2024}
|
|
149
|
+
}
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
## License
|
|
153
|
+
|
|
154
|
+
The Docling codebase is under MIT license.
|
|
155
|
+
For individual model usage, please refer to the model licenses found in the original packages.
|
|
156
|
+
|
|
157
|
+
## LF AI & Data
|
|
158
|
+
|
|
159
|
+
Docling is hosted as a project in the [LF AI & Data Foundation](https://lfaidata.foundation/projects/).
|
|
160
|
+
|
|
161
|
+
### IBM ❤️ Open Source AI
|
|
162
|
+
|
|
163
|
+
The project was started by the AI for knowledge team at IBM Research Zurich.
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from abc import abstractmethod
|
|
4
|
+
from enum import Enum
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
from typing import TYPE_CHECKING
|
|
7
|
+
|
|
8
|
+
# from smolagents import MCPClient, Tool, ToolCollection
|
|
9
|
+
# from smolagents.models import ChatMessage, MessageRole, Model
|
|
10
|
+
from mellea.backends.model_ids import ModelIdentifier
|
|
11
|
+
from pydantic import BaseModel, ConfigDict
|
|
12
|
+
|
|
13
|
+
if TYPE_CHECKING:
|
|
14
|
+
from docling_core.types.doc.document import DoclingDocument
|
|
15
|
+
|
|
16
|
+
# Use shared logger from docling_agent.agents
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class DoclingAgentType(Enum):
|
|
20
|
+
"""Enumeration of supported agent types."""
|
|
21
|
+
|
|
22
|
+
# Core agent types
|
|
23
|
+
DOCLING_DOCUMENT_WRITER = "writer"
|
|
24
|
+
DOCLING_DOCUMENT_EDITOR = "editor"
|
|
25
|
+
DOCLING_DOCUMENT_EXTRACTOR = "extractor"
|
|
26
|
+
DOCLING_DOCUMENT_ENRICHER = "enricher"
|
|
27
|
+
DOCLING_DOCUMENT_RAG = "rag"
|
|
28
|
+
DOCLING_DOCUMENT_ORCHESTRATOR = "orchestrator"
|
|
29
|
+
|
|
30
|
+
def __str__(self) -> str:
|
|
31
|
+
"""Return the string value of the enum."""
|
|
32
|
+
return self.value
|
|
33
|
+
|
|
34
|
+
@classmethod
|
|
35
|
+
def from_string(cls, value: str) -> DoclingAgentType:
|
|
36
|
+
"""Create AgentType from string value."""
|
|
37
|
+
for agent_type in cls:
|
|
38
|
+
if agent_type.value == value:
|
|
39
|
+
return agent_type
|
|
40
|
+
raise ValueError(f"Invalid agent type: {value}. Valid types: {[t.value for t in cls]}")
|
|
41
|
+
|
|
42
|
+
@classmethod
|
|
43
|
+
def get_all_types(cls) -> list[str]:
|
|
44
|
+
"""Get all available agent type strings."""
|
|
45
|
+
return [agent_type.value for agent_type in cls]
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
class BaseDoclingAgent(BaseModel):
|
|
49
|
+
model_config = ConfigDict(arbitrary_types_allowed=True)
|
|
50
|
+
|
|
51
|
+
agent_type: DoclingAgentType
|
|
52
|
+
model_id: ModelIdentifier
|
|
53
|
+
tools: list
|
|
54
|
+
|
|
55
|
+
# model needed for reasoning/instruction following
|
|
56
|
+
reasoning_model_id: ModelIdentifier | None = None
|
|
57
|
+
|
|
58
|
+
# model needed for writing, summarizing, etc
|
|
59
|
+
writing_model_id: ModelIdentifier | None = None
|
|
60
|
+
|
|
61
|
+
max_iteration: int = 16
|
|
62
|
+
|
|
63
|
+
def get_reasoning_model_id(self) -> ModelIdentifier:
|
|
64
|
+
"""Return the reasoning model id, falling back to the primary model."""
|
|
65
|
+
return self.reasoning_model_id or self.model_id
|
|
66
|
+
|
|
67
|
+
def get_writing_model_id(self) -> ModelIdentifier:
|
|
68
|
+
"""Return the writing model id, falling back to the primary model."""
|
|
69
|
+
return self.writing_model_id or self.model_id
|
|
70
|
+
|
|
71
|
+
@abstractmethod
|
|
72
|
+
def run(
|
|
73
|
+
self,
|
|
74
|
+
task: str,
|
|
75
|
+
document: DoclingDocument | None = None,
|
|
76
|
+
sources: list[DoclingDocument | Path] = [],
|
|
77
|
+
**kwargs,
|
|
78
|
+
) -> DoclingDocument:
|
|
79
|
+
"""Execute the agent for a task and return a document."""
|
|
80
|
+
raise NotImplementedError
|