feat(datafabric): add fetch_ontology tool to DF inner SQL agent#911
Open
sankalp-uipath wants to merge 2 commits into
Open
feat(datafabric): add fetch_ontology tool to DF inner SQL agent#911sankalp-uipath wants to merge 2 commits into
sankalp-uipath wants to merge 2 commits into
Conversation
|
There was a problem hiding this comment.
Pull request overview
Adds an optional fetch_ontology inner tool to the Data Fabric SQL sub-agent so the inner LLM can retrieve a configured ontology’s OWL schema from the QueryEngine REST API and use it to generate semantically-correct SQL.
Changes:
- Introduces an ontology REST client (
fetch_ontology_owl) with name validation and size limiting. - Adds a
fetch_ontologyleaf tool with an instance-level cache and wires it into the inner Data Fabric subgraph alongsideexecute_sql. - Threads
ontology_name/folder_keyinto the Data Fabric tool construction path (with an env-var fallback).
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
src/uipath_langchain/agent/tools/datafabric_tool/ontology_fetch_tool.py |
New leaf tool (fetch_ontology) and cached fetcher wrapper for inner SQL agent use. |
src/uipath_langchain/agent/tools/datafabric_tool/ontology_client.py |
New client helper to fetch OWL content via EntitiesService.request_async, including name validation and payload cap. |
src/uipath_langchain/agent/tools/datafabric_tool/models.py |
Adds an intentionally-empty args schema (OntologyFetchInput) for the new tool. |
src/uipath_langchain/agent/tools/datafabric_tool/datafabric_tool.py |
Plumbs ontology_name / folder_key into the query handler creation (currently with env-var fallback). |
src/uipath_langchain/agent/tools/datafabric_tool/datafabric_subgraph.py |
Adds optional fetch_ontology tool binding and dispatch-by-tool-name inside the inner subgraph. |
Comment on lines
+159
to
+163
| Dispatches by tool name so the sub-graph can host more than one tool | ||
| (e.g. ``execute_sql`` and ``fetch_ontology``). Only a successful | ||
| ``execute_sql`` that returned rows is terminal; every other tool | ||
| (including ontology fetch) reports ``False`` so the router loops back to | ||
| the inner LLM, letting it use the result to write or refine SQL. |
Comment on lines
+171
to
+175
| # Ontology name is pinned from configuration (not chosen by the LLM). | ||
| # Falls back to env vars for local/demo runs that have no Agent Builder UI. | ||
| # When unset, no fetch_ontology tool is added (fully backward compatible). | ||
| ontology_name = config.get(ONTOLOGY_NAME) or os.getenv("UIPATH_ONTOLOGY_NAME") | ||
| folder_key = config.get(FOLDER_KEY) or os.getenv("UIPATH_FOLDER_KEY") |
Comment on lines
+31
to
+33
| # Defensive cap so a malformed or oversized file can never blow up the prompt | ||
| # or token budget. Real OWL 2 QL files are a few KB; QueryEngine caps at 10 MB. | ||
| _MAX_OWL_BYTES = 1_000_000 |
Comment on lines
+47
to
+50
| The result is cached on this instance. Because the instance lives as long | ||
| as the compiled sub-graph (which the handler caches), repeated calls across | ||
| queries hit the API at most once, surviving the per-query reset of the | ||
| inner sub-graph state. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


What
Adds an inner-level
fetch_ontologytool alongsideexecute_sqlin the Data Fabric tool's SQL sub-agent. When enabled, the inner LLM can fetch a configured ontology's OWL from the QueryEngine ontology REST API and use it to write semantically-correct SQL (exact class/property names, value formats, join keys).Why
The inner SQL agent gets columns/types but not their meaning — it guesses value formats (
'in_transit'vs'In Transit'), boolean shapes (= truevs= 1), and joins. The ontology supplies these, so SQL is correct on the first attempt instead of failing and retrying.How
ontology_client.py—GET datafabric_/api/ontologies/{name}/files/owlvia the authenticatedEntitiesService(reuses auth + tenant/account scoping). Name regex-validated, 1 MB cap, notation-agnostic (Turtle or OWL Functional Notation) via the JSON wrapper.ontology_fetch_tool.py—fetch_ontologyleaf tool + cached fetcher; fenced/labelled output; graceful degradation on failure.datafabric_subgraph.py— binds the tool when configured; dispatches inner tool calls by name (only a successfulexecute_sqlis terminal, sofetch_ontologyloops back to the inner LLM).datafabric_tool.py— threadsontology_name/folder_keyfromagent_configor env (UIPATH_ONTOLOGY_NAME/UIPATH_FOLDER_KEY).Notes
ruff+py_compileclean.Open items
ecommerceontology exists in the QueryEngine store.fetch_ontology.