Skip to content

LLM-Driven Extraction of Unstructured Data — Built for API Deployments & ETL Pipeline Workflows

UN-2975 [FEAT] Agentic Prompt Studio - Backend (#1739)

harini-venkataramanc86e2cd637ea
diff --git a/backend/tool_instance_v2/tool_instance_helper.py b/backend/tool_instance_v2/tool_instance_helper.py
index d202aa0b9..08f425f74 100644
--- a/backend/tool_instance_v2/tool_instance_helper.py
+++ b/backend/tool_instance_v2/tool_instance_helper.py
@@ -22,6 +22,14 @@ from unstract.tool_registry.constants import AdapterPropertyKey
from unstract.tool_registry.dto import Spec, Tool
from unstract.tool_registry.tool_utils import ToolUtils
+# Import agentic registry if available (cloud-only feature)
+try:
+ from pluggable_apps.agentic_studio_registry.models import AgenticStudioRegistry
+
+ IS_AGENTIC_REGISTRY_AVAILABLE = True
+except ImportError:
+ IS_AGENTIC_REGISTRY_AVAILABLE = False
+
logger = logging.getLogger(__name__)
@@ -504,18 +512,53 @@ class ToolInstanceHelper:
user: User,
tool_uid: str,
) -> None:
- # HACK: Assume tool_uid is a prompt studio exported tool and query it.
- # We suppress ValidationError when tool_uid is of a static tool.
+ """Validate user access to a tool (prompt studio or agentic studio).
+
+ Args:
+ user: User requesting access
+ tool_uid: Tool UID (could be prompt_registry_id or agentic_registry_id)
+
+ Raises:
+ PermissionDenied: If user doesn't have access to the tool
+ """
+ # Try to find the tool in PromptStudioRegistry first
try:
prompt_registry_tool = PromptStudioRegistry.objects.get(pk=tool_uid)
+ if (
+ prompt_registry_tool.shared_to_org
+ or prompt_registry_tool.shared_users.filter(pk=user.pk).exists()
+ ):
+ return
+ raise PermissionDenied("You don't have permission to perform this action.")
+ except PromptStudioRegistry.DoesNotExist:
+ # Not a prompt studio tool, try agentic studio if available
+ pass
except DjangoValidationError:
+ # Invalid UUID format, might be a static tool
logger.info(f"Not validating tool access for tool: {tool_uid}")
return
- if (
- prompt_registry_tool.shared_to_org
- or prompt_registry_tool.shared_users.filter(pk=user.pk).exists()
- ):
- return
- else:
- raise PermissionDenied("You don't have permission to perform this action.")
+ # Try to find the tool in AgenticStudioRegistry if available
+ if IS_AGENTIC_REGISTRY_AVAILABLE:
+ try:
+ agentic_registry_tool = AgenticStudioRegistry.objects.get(pk=tool_uid)
+ if (
+ agentic_registry_tool.shared_to_org
+ or agentic_registry_tool.shared_users.filter(pk=user.pk).exists()
+ ):
+ return
+ raise PermissionDenied(
+ "You don't have permission to perform this action."
+ )
+ except AgenticStudioRegistry.DoesNotExist:
+ # Not an agentic studio tool either
+ pass
+ except DjangoValidationError:
+ # Invalid UUID format, might be a static tool
+ logger.info(f"Not validating tool access for tool: {tool_uid}")
+ return
+
+ # If we reach here, it's likely a static tool from registry
+ # No validation needed for static tools
+ logger.info(f"Not validating tool access for tool: {tool_uid}")
+ return
diff --git a/backend/tool_instance_v2/tool_processor.py b/backend/tool_instance_v2/tool_processor.py
index 34efd99a7..5e33cceec 100644
--- a/backend/tool_instance_v2/tool_processor.py
+++ b/backend/tool_instance_v2/tool_processor.py
@@ -15,6 +15,16 @@ from unstract.tool_registry.dto import Spec, Tool
from unstract.tool_registry.tool_registry import ToolRegistry
from unstract.tool_registry.tool_utils import ToolUtils
+# Import agentic registry if available (cloud-only feature)
+try:
+ from pluggable_apps.agentic_studio_registry.registry_helper import (
+ AgenticRegistryHelper,
+ )
+
+ IS_AGENTIC_REGISTRY_AVAILABLE = True
+except ImportError:
+ IS_AGENTIC_REGISTRY_AVAILABLE = False
+
logger = logging.getLogger(__name__)
@@ -28,12 +38,20 @@ class ToolProcessor:
"""
tool_registry = ToolRegistry()
tool: Tool | None = tool_registry.get_tool_by_uid(tool_uid)
+
# HACK: Assume tool_uid is prompt_registry_id for fetching a dynamic
# tool made with Prompt Studio.
if not tool:
tool = PromptStudioRegistryHelper.get_tool_by_prompt_registry_id(
prompt_registry_id=tool_uid
)
+
+ # Check if it's an agentic studio tool (cloud-only feature)
+ if not tool and IS_AGENTIC_REGISTRY_AVAILABLE:
+ tool = AgenticRegistryHelper.get_tool_by_registry_id(
+ agentic_registry_id=tool_uid
+ )
+
if not tool:
raise ToolDoesNotExist(
f"{ToolProcessor.TOOL_NOT_IN_REGISTRY_MESSAGE}: {tool_uid}"
@@ -120,6 +138,14 @@ class ToolProcessor:
)
tool_list: list[dict[str, Any]] = tool_registry.fetch_tools_descriptions()
tool_list = tool_list + prompt_studio_tools
+
+ # Add agentic studio tools if available (cloud-only feature)
+ if IS_AGENTIC_REGISTRY_AVAILABLE:
+ agentic_tools: list[dict[str, Any]] = (
+ AgenticRegistryHelper.fetch_registry_list(user)
+ )
+ tool_list = tool_list + agentic_tools
+
return tool_list
@staticmethod
diff --git a/platform-service/src/unstract/platform_service/constants.py b/platform-service/src/unstract/platform_service/constants.py
index f5ed0aa7e..e01188624 100644
--- a/platform-service/src/unstract/platform_service/constants.py
+++ b/platform-service/src/unstract/platform_service/constants.py
@@ -4,6 +4,7 @@ class DBTable:
ORGANIZATION = "organization"
ADAPTER_INSTANCE = "adapter_instance"
PROMPT_STUDIO_REGISTRY = "prompt_studio_registry"
+ AGENTIC_STUDIO_REGISTRY = "agentic_studio_registry"
PLATFORM_KEY = "platform_key"
TOKEN_USAGE = "usage"
PAGE_USAGE = "page_usage"
diff --git a/platform-service/src/unstract/platform_service/controller/platform.py b/platform-service/src/unstract/platform_service/controller/platform.py
index f8cb28f51..cb8dd29e0 100644
--- a/platform-service/src/unstract/platform_service/controller/platform.py
+++ b/platform-service/src/unstract/platform_service/controller/platform.py
@@ -439,9 +439,11 @@ def custom_tool_instance() -> Any:
prompt_registry_id=prompt_registry_id,
)
return jsonify(data_dict)
+ except APIError:
+ # Let APIError propagate naturally
+ raise
except Exception as e:
- if isinstance(e, APIError):
- raise e
+ # Wrap other exceptions
msg = (
f"Error while getting data for Prompt Studio project "
f"{prompt_registry_id}: {e}"
@@ -449,6 +451,47 @@ def custom_tool_instance() -> Any:
raise APIError(message=msg) from e
+@platform_bp.route(
+ "/agentic_tool_instance",
+ methods=["GET"],
+ endpoint="agentic_tool_instance",
+)
+@authentication_middleware
+def agentic_tool_instance() -> Any:
+ """Fetching exported agentic tool instance.
+
+ Sample Usage:
+ curl -X GET
+ -H "Authorization: 0xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
+ http://localhost:3001/db/agentic_tool_instance/agentic_registry_id=id1
+ """
+ bearer_token = get_token_from_auth_header(request)
+ _, organization_id = get_organization_from_bearer_token(bearer_token)
+ if not organization_id:
+ return Env.INVALID_ORGANIZATOIN, 403
+
+ agentic_registry_id = request.args.get("agentic_registry_id")
+ if not agentic_registry_id:
+ raise APIError(message="agentic_registry_id is required", code=400)
+
+ try:
+ data_dict = PromptStudioRequestHelper.get_agentic_instance_from_db(
+ organization_id=organization_id,
+ agentic_registry_id=agentic_registry_id,
+ )
+ return jsonify(data_dict)
+ except APIError:
+ # Let APIError propagate naturally
+ raise
+ except Exception as e:
+ # Wrap other exceptions
+ msg = (
+ f"Error while getting data for Agentic Studio project "
+ f"{agentic_registry_id}: {e}"
+ )
+ raise APIError(message=msg) from e
+
+
@platform_bp.route(
"/llm_profile_instance",
methods=["GET"],
@@ -470,8 +513,10 @@ def llm_profile_instance() -> Any:
llm_profile_id=llm_profile_id,
)
return jsonify(data_dict)
+ except APIError:
+ # Let APIError propagate naturally
+ raise
except Exception as e:
- if isinstance(e, APIError):
- raise e
+ # Wrap other exceptions
msg = f"Error while getting data for LLM profile {llm_profile_id}: {e}"
raise APIError(message=msg) from e
diff --git a/platform-service/src/unstract/platform_service/helper/__init__.py b/platform-service/src/unstract/platform_service/helper/__init__.py
new file mode 100644
index 000000000..769fadd67
--- /dev/null
+++ b/platform-service/src/unstract/platform_service/helper/__init__.py
@@ -0,0 +1 @@
+"""Helper modules for platform service."""
diff --git a/platform-service/src/unstract/platform_service/helper/prompt_studio.py b/platform-service/src/unstract/platform_service/helper/prompt_studio.py
index 0122dd830..1af330755 100644
--- a/platform-service/src/unstract/platform_service/helper/prompt_studio.py
+++ b/platform-service/src/unstract/platform_service/helper/prompt_studio.py
@@ -40,6 +40,37 @@ class PromptStudioRequestHelper:
data_dict: dict[str, Any] = dict(zip(columns, result_row, strict=False))
return data_dict
+ @staticmethod
+ def get_agentic_instance_from_db(
+ organization_id: str,
+ agentic_registry_id: str,
+ ) -> dict[str, Any]:
+ """Get agentic studio registry from Backend Database.
+
+ Args:
+ organization_id (str): organization schema id
+ agentic_registry_id (str): agentic_registry_id
+
+ Returns:
+ dict[str, Any]: Agentic registry data
+ """
+ query = (
+ "SELECT registry_id, tool_spec, "
+ "tool_metadata, tool_property FROM "
+ f'"{DB_SCHEMA}".{DBTable.AGENTIC_STUDIO_REGISTRY} x '
+ "WHERE registry_id=%s"
+ )
+ with safe_cursor(query, (agentic_registry_id,)) as cursor:
+ result_row = cursor.fetchone()
+ if not result_row:
+ raise APIError(
+ message=f"Agentic studio project with UUID '{agentic_registry_id}' is not found.",
+ code=404,
+ )
+ columns = [desc[0] for desc in cursor.description]
+ data_dict: dict[str, Any] = dict(zip(columns, result_row, strict=False))
+ return data_dict
+
@staticmethod
def get_llm_profile_instance_from_db(
organization_id: str,
diff --git a/tools/structure/src/main.py b/tools/structure/src/main.py
index a097886c7..2ff293985 100644
--- a/tools/structure/src/main.py
+++ b/tools/structure/src/main.py
@@ -144,6 +144,14 @@ class StructureTool(BaseTool):
if enable_challenge and not challenge_llm:
raise ValueError("Challenge LLM is not set after enabling Challenge")
+ def _is_agentic_project(self, tool_metadata: dict[str, Any]) -> bool:
+ """Check if metadata indicates an agentic project.
+
+ Agentic projects have project_id and json_schema fields.
+ Prompt studio projects have tool_id and outputs fields.
+ """
+ return "project_id" in tool_metadata and "json_schema" in tool_metadata
+
def run(
self,
settings: dict[str, Any],
@@ -160,35 +168,82 @@ class StructureTool(BaseTool):
)
challenge_llm: str = settings.get(SettingsKeys.CHALLENGE_LLM_ADAPTER_ID, "")
is_highlight_enabled: bool = settings.get(SettingsKeys.ENABLE_HIGHLIGHT, False)
- is_word_confidence_enabled: bool = settings.get(
- SettingsKeys.ENABLE_WORD_CONFIDENCE, False
- )
responder: PromptTool = PromptTool(
tool=self,
prompt_port=self.get_env_or_die(SettingsKeys.PROMPT_PORT),
prompt_host=self.get_env_or_die(SettingsKeys.PROMPT_HOST),
request_id=self.file_execution_id,
)
- self.stream_log(
- f"Fetching prompt studio exported tool with UUID '{prompt_registry_id}'"
+ self.stream_log(f"Fetching exported tool with UUID '{prompt_registry_id}'")
+
+ platform_helper: PlatformHelper = PlatformHelper(
+ tool=self,
+ platform_port=self.get_env_or_die(ToolEnv.PLATFORM_PORT),
+ platform_host=self.get_env_or_die(ToolEnv.PLATFORM_HOST),
+ request_id=self.file_execution_id,
)
+
+ # Try to fetch as prompt studio tool first
+ tool_metadata = None
+ is_agentic = False
+ exported_tool = None
+
try:
- platform_helper: PlatformHelper = PlatformHelper(
- tool=self,
- platform_port=self.get_env_or_die(ToolEnv.PLATFORM_PORT),
- platform_host=self.get_env_or_die(ToolEnv.PLATFORM_HOST),
- request_id=self.file_execution_id,
- )
exported_tool = platform_helper.get_prompt_studio_tool(
prompt_registry_id=prompt_registry_id
)
- llm_profile_id = self.get_exec_metadata.get(SettingsKeys.LLM_PROFILE_ID)
- llm_profile_to_override = None
- if llm_profile_id:
- llm_profile = platform_helper.get_llm_profile(llm_profile_id)
- llm_profile_to_override = llm_profile # Use the entire profile data
+ except Exception as e:
+ # If prompt studio lookup fails, try as agentic project
+ self.stream_log(
+ f"Not found as prompt studio project, trying agentic registry: {e}"
+ )
+ if exported_tool and SettingsKeys.TOOL_METADATA in exported_tool:
tool_metadata = exported_tool[SettingsKeys.TOOL_METADATA]
+ is_agentic = False
+ # Explicitly mark metadata for clarity
+ tool_metadata["is_agentic"] = False
+ else:
+ # Try agentic registry as fallback
+ try:
+ agentic_tool = platform_helper.get_agentic_studio_tool(
+ agentic_registry_id=prompt_registry_id
+ )
+ if not agentic_tool or SettingsKeys.TOOL_METADATA not in agentic_tool:
+ self.stream_error_and_exit(
+ f"Error fetching project: Registry returned empty response for {prompt_registry_id}"
+ )
+ tool_metadata = agentic_tool[SettingsKeys.TOOL_METADATA]
+ is_agentic = True
+ # Explicitly mark metadata for clarity
+ tool_metadata["is_agentic"] = True
+ self.stream_log(
+ f"Retrieved agentic project: {tool_metadata.get('name', prompt_registry_id)}"
+ )
+ except Exception as agentic_error:
+ self.stream_error_and_exit(
+ f"Error fetching project from both registries "
+ f"for ID '{prompt_registry_id}': {agentic_error}"
+ )
+
+ # Route to appropriate extraction method
+ if is_agentic:
+ return self._run_agentic_extraction(
+ tool_metadata=tool_metadata,
+ input_file=input_file,
+ output_dir=output_dir,
+ settings=settings,
+ responder=responder,
+ platform_helper=platform_helper,
+ )
+
+ # Continue with regular prompt studio extraction
+ llm_profile_id = self.get_exec_metadata.get(SettingsKeys.LLM_PROFILE_ID)
+ llm_profile_to_override = None
+ try:
+ if llm_profile_id:
+ llm_profile = platform_helper.get_llm_profile(llm_profile_id)
+ llm_profile_to_override = llm_profile
# Apply profile overrides if available
STHelper.handle_profile_overrides(
@@ -198,15 +253,15 @@ class StructureTool(BaseTool):
tool_metadata,
self._apply_profile_overrides,
)
- ps_project_name = tool_metadata.get("name", prompt_registry_id)
- # Count only the active (enabled) prompts
- total_prompt_count = len(tool_metadata[SettingsKeys.OUTPUTS])
- self.stream_log(
- f"Retrieved prompt studio exported tool '{ps_project_name}' having "
- f"'{total_prompt_count}' prompts"
- )
except Exception as e:
self.stream_error_and_exit(f"Error fetching prompt studio project: {e}")
+ ps_project_name = tool_metadata.get("name", prompt_registry_id)
+ # Count only the active (enabled) prompts
+ total_prompt_count = len(tool_metadata[SettingsKeys.OUTPUTS])
+ self.stream_log(
+ f"Retrieved prompt studio exported tool '{ps_project_name}' having "
+ f"'{total_prompt_count}' prompts"
+ )
active_prompt_count = len(
[
@@ -234,7 +289,6 @@ class StructureTool(BaseTool):
tool_settings[SettingsKeys.ENABLE_SINGLE_PASS_EXTRACTION] = is_single_pass_enabled
tool_settings[SettingsKeys.SUMMARIZE_AS_SOURCE] = is_summarization_enabled
tool_settings[SettingsKeys.ENABLE_HIGHLIGHT] = is_highlight_enabled
- tool_settings[SettingsKeys.ENABLE_WORD_CONFIDENCE] = is_word_confidence_enabled
_, file_name = os.path.split(input_file)
if is_summarization_enabled:
file_name = SettingsKeys.SUMMARIZE
@@ -430,6 +484,26 @@ class StructureTool(BaseTool):
self.stream_error_and_exit(f"Error encoding JSON: {e}")
self.write_tool_result(data=structured_output)
+ def _remove_source_refs(self, data: Any) -> Any:
+ """Recursively remove _source_refs from data structure.
+
+ Args:
+ data: Data structure (dict, list, or primitive) to clean
+
+ Returns:
+ Cleaned data structure without _source_refs fields
+ """
+ if isinstance(data, dict):
+ return {
+ key: self._remove_source_refs(value)
+ for key, value in data.items()
+ if key != "_source_refs"
+ }
+ elif isinstance(data, list):
+ return [self._remove_source_refs(item) for item in data]
+ else:
+ return data
+
def _merge_metrics(self, metrics1: dict, metrics2: dict) -> dict:
"""Intelligently merge two metrics dictionaries.
@@ -465,6 +539,175 @@ class StructureTool(BaseTool):
return merged_metrics
+ def _run_agentic_extraction(
+ self,
+ tool_metadata: dict[str, Any],
+ input_file: str,
+ output_dir: str,
+ settings: dict[str, Any],
+ responder: PromptTool,
+ platform_helper: PlatformHelper,
+ ) -> None:
+ """Execute agentic extraction pipeline.
+
+ Args:
+ tool_metadata: Complete agentic project metadata
+ input_file: Path to input document
+ output_dir: Directory for output files
+ settings: Workflow settings (contains adapter overrides)
+ responder: PromptTool instance for API calls
+ platform_helper: PlatformHelper instance for platform API calls
+ """
+ from unstract.sdk1.x2txt import X2Text
+
+ # Extract agentic-specific metadata
+ project_id = tool_metadata.get("project_id")
+ project_name = tool_metadata.get("name", project_id)
+ json_schema = tool_metadata.get("json_schema", {})
+ prompt_text = tool_metadata.get("prompt_text", "")
+ prompt_version = tool_metadata.get("prompt_version", 1)
+ schema_version = tool_metadata.get("schema_version", 1)
+ adapter_config = tool_metadata.get("adapter_config", {})
+
+ self.stream_log(
+ f"Executing agentic extraction for project '{project_name}' "
+ f"(schema v{schema_version}, prompt v{prompt_version})"
+ )
+
+ # Get adapter IDs from settings (workflow UI overrides)
+ # or fall back to exported defaults
+ extractor_llm = settings.get(
+ "extractor_llm_adapter_id", adapter_config.get("extractor_llm")
+ )
+ llmwhisperer = settings.get(
+ "llmwhisperer_adapter_id", adapter_config.get("llmwhisperer")
+ )
+ enable_highlight = settings.get(
+ SettingsKeys.ENABLE_HIGHLIGHT, tool_metadata.get("enable_highlight", False)
+ )
+
+ # Get platform details for organization_id
+ platform_details = platform_helper.get_platform_details()
+ organization_id = (
+ platform_details.get("organization_id") if platform_details else None
+ )
+
+ if not organization_id:
+ self.stream_error_and_exit("Failed to get organization_id from platform")
+
+ # Update GUI
+ input_log = (
+ f"## Loaded Agentic Project '{project_name}'\n"
+ f"- **Project ID**: {project_id}\n"
+ f"- **Schema Version**: {schema_version}\n"
+ f"- **Prompt Version**: {prompt_version}\n"
+ f"- **Extractor LLM**: {extractor_llm}\n"
+ )
+ output_log = (
+ f"## Processing '{self.source_file_name}'\n"
+ "Executing agentic extraction pipeline...\n"
+ "- Extracting document text\n"
+ "- Running LLM extraction\n"
+ )
+ self.stream_update(input_log, state=LogState.INPUT_UPDATE)
+ self.stream_update(output_log, state=LogState.OUTPUT_UPDATE)
+
+ try:
+ # Step 1: Extract text from document using X2Text/LLMWhisperer
+ self.stream_log("Extracting text from document...")
+ x2text = X2Text(tool=self, adapter_instance_id=llmwhisperer)
+
+ extraction_result = x2text.process(
+ input_file_path=input_file,
+ enable_highlight=enable_highlight,
+ fs=self.workflow_filestorage,
+ )
+
+ document_text = extraction_result.extracted_text
+ line_metadata = (
+ extraction_result.extraction_metadata.line_metadata
+ if extraction_result.extraction_metadata
+ else None
+ )
+
+ self.stream_log(f"Extracted {len(document_text)} characters of text")
+
+ # Step 2: Build extraction payload for /agentic/extract endpoint
+ payload = {
+ "document_id": self.file_execution_id, # Use run ID as document ID
+ "prompt_text": prompt_text,
+ "document_text": document_text,
+ "schema": json_schema,
+ "organization_id": organization_id,
+ "adapter_instance_id": extractor_llm,
+ "include_source_refs": enable_highlight,
+ }
+
+ # Add line_metadata if available for highlighting
+ if line_metadata and enable_highlight:
+ payload["line_metadata"] = line_metadata
+ self.stream_log(
+ f"Including {len(line_metadata)} line metadata entries for highlighting"
+ )
+
+ # Step 3: Call agentic extraction endpoint
+ self.stream_log("Calling agentic extraction endpoint...")
+ extraction_response = responder.agentic_extraction(payload=payload)
+
+ # Step 4: Transform response to match expected structure
+ # Cloud endpoint returns: {document_id, extracted_data, highlights, highlight_data, ...}
+ # We need: {data: {...}, metadata: {...}}
+ extracted_data = extraction_response.get("extracted_data", {})
+
+ # Remove _source_refs from extracted data
+ try:
+ extracted_data = self._remove_source_refs(extracted_data)
+ except Exception as e:
+ self.stream_log(
+ f"Warning: Failed to remove _source_refs: {e}. "
+ "Proceeding with original data."
+ )
+ # Continue with original extracted_data if removal fails
+
+ structured_output = {
+ "data": extracted_data,
+ SettingsKeys.METADATA: {
+ SettingsKeys.FILE_NAME: self.source_file_name,
+ "project_id": project_id,
+ "schema_version": schema_version,
+ "prompt_version": prompt_version,
+ "document_id": self.file_execution_id,
+ },
+ }
+
+ # Add highlight data if available
+ if "highlights" in extraction_response:
+ structured_output["highlights"] = extraction_response["highlights"]
+ if "highlight_data" in extraction_response:
+ structured_output["highlight_data"] = extraction_response[
+ "highlight_data"
+ ]
+
+ # Update GUI with results
+ output_log = (
+ f"## Agentic Extraction Complete\n"
+ f"Successfully extracted data from '{self.source_file_name}'\n"
+ f"{json_to_markdown(structured_output)}\n"
+ )
+ self.stream_update(output_log, state=LogState.OUTPUT_UPDATE)
+
+ # Write output to file
+ self.stream_log("Writing agentic extraction output to workflow storage")
+ output_path = Path(output_dir) / f"{Path(self.source_file_name).stem}.json"
+ self.workflow_filestorage.json_dump(path=output_path, data=structured_output)
+ self.stream_log("Output written successfully to workflow storage")
+
+ # Write tool result
+ self.write_tool_result(data=structured_output)
+
+ except Exception as e:
+ self.stream_error_and_exit(f"Error during agentic extraction: {e}")
+
def _summarize(
self,
tool_settings: dict[str, Any],
diff --git a/unstract/sdk1/src/unstract/sdk1/adapters/x2text/dto.py b/unstract/sdk1/src/unstract/sdk1/adapters/x2text/dto.py
index 8fa226ea0..95c60bbe8 100644
--- a/unstract/sdk1/src/unstract/sdk1/adapters/x2text/dto.py
+++ b/unstract/sdk1/src/unstract/sdk1/adapters/x2text/dto.py
@@ -1,9 +1,11 @@
from dataclasses import dataclass
+from typing import Any
@dataclass
class TextExtractionMetadata:
whisper_hash: str
+ line_metadata: dict[Any, Any] | None = None
@dataclass
diff --git a/unstract/sdk1/src/unstract/sdk1/adapters/x2text/llm_whisperer_v2/src/llm_whisperer_v2.py b/unstract/sdk1/src/unstract/sdk1/adapters/x2text/llm_whisperer_v2/src/llm_whisperer_v2.py
index 9325320d4..892339a9b 100644
--- a/unstract/sdk1/src/unstract/sdk1/adapters/x2text/llm_whisperer_v2/src/llm_whisperer_v2.py
+++ b/unstract/sdk1/src/unstract/sdk1/adapters/x2text/llm_whisperer_v2/src/llm_whisperer_v2.py
@@ -93,7 +93,8 @@ class LLMWhispererV2(X2TextAdapter):
extra_params=extra_params,
)
metadata = TextExtractionMetadata(
- whisper_hash=response.get(X2TextConstants.WHISPER_HASH_V2, "")
+ whisper_hash=response.get(X2TextConstants.WHISPER_HASH_V2, ""),
+ line_metadata=response.get("line_metadata"),
)
return TextExtractionResult(
diff --git a/unstract/sdk1/src/unstract/sdk1/platform.py b/unstract/sdk1/src/unstract/sdk1/platform.py
index 58ca2617f..4f212461b 100644
--- a/unstract/sdk1/src/unstract/sdk1/platform.py
+++ b/unstract/sdk1/src/unstract/sdk1/platform.py
@@ -284,6 +284,17 @@ class PlatformHelper:
error_message = response_json["error"]
elif response.text:
error_message = response.text
+
+ # For 404 errors on tool lookups, raise exception to allow fallback
+ # For other errors, exit immediately (existing behavior)
+ if response.status_code == 404 and url_path in [
+ "custom_tool_instance",
+ "agentic_tool_instance",
+ ]:
+ raise RequestException(
+ f"Error from platform service. {error_message}"
+ ) from e
+
self.tool.stream_error_and_exit(
f"Error from platform service. {error_message}"
)
@@ -324,6 +335,24 @@ class PlatformHelper:
method="GET",
)
+ def get_agentic_studio_tool(self: Self, agentic_registry_id: str) -> dict[str, Any]:
+ """Get exported agentic tool by the help of unstract DB tool.
+
+ Args:
+ agentic_registry_id (str): ID of the agentic_registry_id
+ Required env variables:
+ PLATFORM_HOST: Host of platform service
+ PLATFORM_PORT: Port of platform service
+ """
+ query_params = {"agentic_registry_id": agentic_registry_id}
+ return self._call_service(
+ url_path="agentic_tool_instance",
+ payload=None,
+ params=query_params,
+ headers=None,
+ method="GET",
+ )
+
def get_llm_profile(self: Self, llm_profile_id: str) -> dict[str, Any]:
"""Get llm profile by the help of unstract DB tool.
diff --git a/unstract/sdk1/src/unstract/sdk1/prompt.py b/unstract/sdk1/src/unstract/sdk1/prompt.py
index 85e87a527..f46737c65 100644
--- a/unstract/sdk1/src/unstract/sdk1/prompt.py
+++ b/unstract/sdk1/src/unstract/sdk1/prompt.py
@@ -171,6 +171,32 @@ class PromptTool:
headers=headers,
)
+ @log_elapsed(operation="AGENTIC_EXTRACTION")
+ @handle_service_exceptions("executing agentic extraction")
+ def agentic_extraction(
+ self,
+ payload: dict[str, Any],
+ params: dict[str, str] | None = None,
+ headers: dict[str, str] | None = None,
+ ) -> dict[str, Any]:
+ """Execute agentic extraction via prompt service.
+
+ Args:
+ payload: Extraction payload containing project_id, json_schema,
+ prompt_text, adapter IDs, etc.
+ params: Optional query parameters
+ headers: Optional headers
+
+ Returns:
+ dict: Extraction results with data, metadata, and metrics
+ """
+ return self._call_service(
+ url_path="agentic/extract",
+ payload=payload,
+ params=params,
+ headers=headers,
+ )
+
def _get_headers(self, headers: dict[str, str] | None = None) -> dict[str, str]:
"""Get default headers for requests.