Add Document Parsing to AI Agent
Quick Start
1
Install Dependencies
Install PraisonAI with MCP support:This integration requires
praisonaiagents 1.6.154 or later. Connecting to a remote streamable-HTTP MCP server needs 1.6.152, and the result-aware loop guard from 1.6.154 keeps a long-running transform from being halted as “no progress” while the agent polls for status.2
Set API Keys
Set your Unstructured API key (from transform.unstructured.io) and your model’s API key as environment variables:
3
Create a file
Create a new file Two details make a multi-minute transform complete. The
unstructured_transform.py with the following code:wait_seconds function, passed alongside the
MCP tools, gives the agent a way to pace its polling: without it the agent checks the status every
couple of seconds and then concludes the job is taking too long while it is still running. And
ExecutionConfig(max_tool_calls_per_turn=100) raises the default cap of 10 tool calls per turn, which
a polling loop passes well before a job finishes.4
Run the Agent
Execute your script:Transform is asynchronous: the agent starts a job with
start_transform_job, waits with wait_seconds, polls check_job_status until it is complete, then retrieves the output with get_job_results. Large or scanned documents can take a few minutes.Extract Structured Data
To pull named fields out of a document instead of converting the whole document, ask the agent for an extraction:output_ref that get_job_results returns for it. It drafts a schema with suggest_extraction_schema_for_file when you have not supplied one, runs start_extraction_job, then polls with the same check_job_status and get_job_results tools. Two jobs run back to back, so an extraction takes longer than a parse alone.
Results come back as JSON matching the schema, wrapped with the source filename and the element JSON reference they were taken from. Extraction can only surface what the parse captured, so ask for a higher-fidelity parse if a first attempt comes back sparse. For prompt patterns, see Structured data extraction.
Requirements
- Python 3.10 or higher
praisonaiagents1.6.154 or later (remote streamable-HTTP MCP support, plus the result-aware loop guard needed for async polling)- An Unstructured API key
- An OpenAI API key (for the agent’s LLM)

