Skip to main content

UniversalDocAgent (unidoc_agent)

UniversalDocAgent is a Python package designed to intelligently detect document types and automatically extract or summarize their contents using a set of specialized tools. It supports a wide range of file types such as PDFs, Word documents, emails, source code, Excel files, XML, OCR-recognizable images, and plain text.

You can optionally integrate with an LLM backend like Ollama to generate summaries and maintain conversation history across sessions.


🚧 Installation

pip install .

Run this from the root directory of your cloned project or package.


📂 Supported Document Types

File Type Handled By
.pdf PDFTool
.docx WordTool
.txt TextTool
.py, .js, etc. CodeTool
.eml EmailTool
.xlsx ExcelTool
.jpg, .png, etc. OCRTool
.xml XMLTool

🚀 Usage Examples

1. Extracting Content

from unidoc_agent.agent import read_document

file_path = "sample.pdf"
content = read_document(file_path)
print(content)

2. Summarizing Content

summary = read_document("example.docx", summarize=True)
print(summary)

🧠 Advanced: Use Ollama LLM Backend

Custom LLM model or session

from unidoc_agent.agent import UniversalDocAgent
from unidoc_agent.agent import tools

agent = UniversalDocAgent(tools=tools, llm_backend="ollama")
summary = agent.summarize_content("report.txt")
print(summary)

💬 Conversation History with OllamaClient

The OllamaClient class is used internally to manage conversation context for summarization.

  • Caching: Stores conversation history locally in ~/.unidoc_ollama_cache/{model}_{session_id}.json
  • Session Management: Custom session IDs let you manage multiple user contexts

Clearing History

from unidoc_agent.ollama_client import OllamaClient

client = OllamaClient(session_id="user123")
client.clear_history()

🔧 API Reference

read_document(file_path, summarize=False)

  • file_path: Path to the input document
  • summarize: If True, returns a summary via LLM; else returns extracted content

UniversalDocAgent

  • extract_content(file_path): Extracts raw content
  • summarize_content(file_path): Summarizes content using the selected tool + LLM

🔮 Tests

Make sure you have pytest or unittest installed:

pytest

Or:

python -m unittest discover tests/

📄 License

This project is licensed under the MIT License. See the LICENSE file for details.


📊 Use Cases

  • ✉️ Email Parsing – Automatically extract the body of .eml files and summarize them.
  • 📄 Document Summary – Get concise summaries of long reports, manuals, or meeting notes.
  • 📈 Spreadsheet Reader – Read .xlsx Excel files and extract tables or data grids.
  • 🔧 OCR Scanning – Use OCRTool to read text from images (e.g., scanned receipts).
  • 📁 Source Code Insight – Extract and analyze comments or logic from .py or .js files.
  • 📖 Multi-format Aggregation – Use the same interface (read_document) for any supported format.

🚀 Contributing

Pull requests are welcome. Please open issues for bugs or feature requests.


✨ Acknowledgements

Thanks to OpenAI, Ollama, and the open-source contributors whose tools helped build this module.

Metadata

Release files for unidoc-agent 0.2.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for unidoc-agent 0.2.6
File Size Uploaded
unidoc_agent-0.2.6.tar.gz 9.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for unidoc-agent 0.2.6
File Interpreter ABI Platform
unidoc_agent-0.2.6-py3-none-any.whl Python 3 none any Details

Total release size: 20.2 kB

Release files / unidoc_agent-0.2.6.tar.gz

Download URL unidoc_agent-0.2.6.tar.gz
Size 9.5 kB
Tags Source
SHA-256 checksum
How to use checksums
349e8155dca888e4537e0d6942e5e126813439d6cf82d1eae0e4a27b949c84ab
BLAKE2b-256 checksum
How to use checksums
522e1532e380c006cba1068266e931fbde8989807321f85425207df46f2c39bc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.8.12

Release files / unidoc_agent-0.2.6-py3-none-any.whl

Download URL unidoc_agent-0.2.6-py3-none-any.whl
Size 10.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8431a05ddd2cdfb197bf02ed9d4b45ae52d14d1b835c5a7e0ddf9d081e68f230
BLAKE2b-256 checksum
How to use checksums
d6deb50304e7cd5e7d8a1878804388b8396651dd7703ae89823cca5d5fe50d11
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.8.12

Release history Release notifications | RSS feed

This release

0.2.6 This release

2 release files

0.2.5

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page