Execute agentic extraction pipeline via dispatcher. Unpacks metadata, extracts document text via X2Text, then dispatches with flat executor_params matching what AgenticPromptStudioExecutor expects (adapter_instance_id, document_text, etc.).
(
tool_metadata: dict,
input_file_path: str,
output_dir_path: str,
tool_instance_metadata: dict,
dispatcher: ExecutionDispatcher,
shim: Any,
file_execution_id: str,
execution_id: str,
organization_id: str,
source_file_name: str,
fs: Any,
execution_data_dir: str = "",
)
| 671 | |
| 672 | |
| 673 | def _run_agentic_extraction( |
| 674 | tool_metadata: dict, |
| 675 | input_file_path: str, |
| 676 | output_dir_path: str, |
| 677 | tool_instance_metadata: dict, |
| 678 | dispatcher: ExecutionDispatcher, |
| 679 | shim: Any, |
| 680 | file_execution_id: str, |
| 681 | execution_id: str, |
| 682 | organization_id: str, |
| 683 | source_file_name: str, |
| 684 | fs: Any, |
| 685 | execution_data_dir: str = "", |
| 686 | ) -> dict: |
| 687 | """Execute agentic extraction pipeline via dispatcher. |
| 688 | |
| 689 | Unpacks metadata, extracts document text via X2Text, then dispatches |
| 690 | with flat executor_params matching what AgenticPromptStudioExecutor |
| 691 | expects (adapter_instance_id, document_text, etc.). |
| 692 | """ |
| 693 | from unstract.sdk1.x2txt import X2Text |
| 694 | |
| 695 | # 1. Unpack agentic project metadata (matches registry_helper export format) |
| 696 | adapter_config = tool_metadata.get("adapter_config", {}) |
| 697 | prompt_text = tool_metadata.get("prompt_text", "") |
| 698 | json_schema = tool_metadata.get("json_schema", {}) |
| 699 | enable_highlight = tool_instance_metadata.get( |
| 700 | "enable_highlight", |
| 701 | tool_metadata.get("enable_highlight", False), |
| 702 | ) |
| 703 | |
| 704 | # 2. Get adapter IDs: workflow UI overrides → exported defaults |
| 705 | # (mirrors tools/structure/src/main.py) |
| 706 | extractor_llm = tool_instance_metadata.get( |
| 707 | "extractor_llm_adapter_id", adapter_config.get("extractor_llm", "") |
| 708 | ) |
| 709 | llmwhisperer = tool_instance_metadata.get( |
| 710 | "llmwhisperer_adapter_id", adapter_config.get("llmwhisperer", "") |
| 711 | ) |
| 712 | platform_service_api_key = shim.platform_api_key |
| 713 | |
| 714 | # 3. Extract text from document using X2Text/LLMWhisperer |
| 715 | x2text = X2Text(tool=shim, adapter_instance_id=llmwhisperer) |
| 716 | extraction_result = x2text.process( |
| 717 | input_file_path=input_file_path, |
| 718 | enable_highlight=enable_highlight, |
| 719 | fs=fs, |
| 720 | ) |
| 721 | document_text = extraction_result.extracted_text |
| 722 | |
| 723 | # Parse json_schema if stored as string |
| 724 | if isinstance(json_schema, str): |
| 725 | json_schema = json.loads(json_schema) |
| 726 | |
| 727 | # 4. Dispatch with flat executor_params matching executor expectations |
| 728 | start_time = time.monotonic() |
| 729 | agentic_ctx = ExecutionContext( |
| 730 | executor_name="agentic", |