Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
c6e73eb
feat(datafabric): add fetch_ontology tool to DF inner SQL agent
sankalp-uipath Jun 16, 2026
b67e170
Merge branch 'main' into feat/datafabric-ontology-fetch-tool
sankalp-uipath Jun 16, 2026
da19087
feat(datafabric): resolve ontology from agent.json binding (name + fo…
sankalp-uipath Jun 17, 2026
4c22b8f
refactor(datafabric): fetch ontology via SDK EntitiesService.get_onto…
sankalp-uipath Jun 17, 2026
68f7cbf
feat(datafabric): support multiple ontologies per context (ontologySet)
sankalp-uipath Jun 17, 2026
ab77d65
Merge remote-tracking branch 'origin/main' into feat/datafabric-ontol…
sankalp-uipath Jun 17, 2026
40acdec
fix(datafabric): end loop on any successful SQL; drop env-var ontolog…
sankalp-uipath Jun 22, 2026
7a5bb69
test(datafabric): cover ontology fetch tool, subgraph routing, and fa…
sankalp-uipath Jun 22, 2026
04f79c5
fix(datafabric): return only terminal tool msgs on END; drop ToolMess…
sankalp-uipath Jun 22, 2026
0ed6210
perf(datafabric): fetch configured ontologies concurrently (asyncio.g…
sankalp-uipath Jun 22, 2026
e9c4cfb
feat(datafabric): resolve ontologies via ontology_refs
sankalp-uipath Jun 23, 2026
be5ef26
Merge branch 'main' into feat/datafabric-ontology-fetch-tool
sankalp-uipath Jun 23, 2026
1fd7a30
chore: consume uipath dev build (#1728) to unblock CI
sankalp-uipath Jun 23, 2026
a871a0a
chore: revert temp dev-build pin; fix datafabric test mypy
sankalp-uipath Jun 23, 2026
dfdd3d6
Merge branch 'main' into feat/datafabric-ontology-fetch-tool
sankalp-uipath Jun 23, 2026
a07adb9
Merge branch 'main' into feat/datafabric-ontology-fetch-tool
sankalp-uipath Jun 24, 2026
54db78f
refactor(datafabric): resolve ontologies from nested ontologySet
sankalp-uipath Jun 25, 2026
941f3ff
refactor(datafabric): gather ontologies from datafabricontology context
sankalp-uipath Jun 25, 2026
86e5912
feat(datafabric): gate fetch_ontology behind DataFabricOntologyEnable…
sankalp-uipath Jun 29, 2026
826f036
test(datafabric): drop ontology referenceKey fixture
sankalp-uipath Jun 30, 2026
e57d1b0
refactor(datafabric): gate ontology flag at every entry; share flag c…
sankalp-uipath Jun 30, 2026
2f41f40
Merge remote-tracking branch 'origin/main' into feat/datafabric-ontol…
sankalp-uipath Jun 30, 2026
7fab6d5
refactor(datafabric): address review nits (split bind test, single-st…
sankalp-uipath Jun 30, 2026
a35807b
refactor(datafabric): inject ontology into system prompt, drop fetch_…
sankalp-uipath Jul 1, 2026
4edb26a
feat(datafabric): standalone ontology tool (R2RML-driven, flag-gated)
sankalp-uipath Jul 2, 2026
eebdfc2
refactor(datafabric): call get_ontology_bundle_async (SDK rename)
sankalp-uipath Jul 2, 2026
0f99ac0
Revert "refactor(datafabric): call get_ontology_bundle_async (SDK ren…
sankalp-uipath Jul 3, 2026
ee0532c
build(datafabric): require uipath>=2.12.5 / uipath-platform>=0.1.91
sankalp-uipath Jul 3, 2026
72dc9cb
refactor(datafabric): keep entity prompt builder untouched; ontology …
sankalp-uipath Jul 3, 2026
28d284d
Merge remote-tracking branch 'origin/main' into feat/datafabric-ontol…
sankalp-uipath Jul 3, 2026
89cb44e
refactor(datafabric): drop unused logger from ontology_fetcher
sankalp-uipath Jul 3, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ description = "Python SDK that enables developers to build and deploy LangGraph
readme = { file = "README.md", content-type = "text/markdown" }
requires-python = ">=3.11"
dependencies = [
"uipath>=2.11.14, <2.12.0",
"uipath>=2.12.5, <2.13.0",
"uipath-core>=0.5.20, <0.6.0",
"uipath-platform>=0.1.86, <0.2.0",
"uipath-platform>=0.1.91, <0.2.0",
Comment thread
sankalp-uipath marked this conversation as resolved.
"uipath-runtime>=0.11.4, <0.12.0",
"langgraph>=1.1.8, <2.0.0",
"langchain-core>=1.2.27, <2.0.0",
Expand Down
28 changes: 28 additions & 0 deletions src/uipath_langchain/agent/tools/context_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,37 @@ def create_context_tool(
) -> StructuredTool | BaseTool | None:
tool_name = sanitize_tool_name(resource.name)

# A Data Fabric ontology context is a standalone tool (flag-gated): the agent
# selects ontologies and the tool derives its entities from the R2RML mapping.
# With the flag off it is inert (returns None) and the agent runs without it.
if resource.context_type == AgentContextType.DATA_FABRIC_ONTOLOGY:
from uipath.core.feature_flags import FeatureFlags

from .datafabric_tool.datafabric_tool import (
BASE_SYSTEM_PROMPT,
DATAFABRIC_ONTOLOGY_FF,
)

if not FeatureFlags.is_flag_enabled(DATAFABRIC_ONTOLOGY_FF, default=False):
return None
if llm is None:
raise ValueError("Data Fabric ontology tools require an LLM instance")

from .datafabric_tool.datafabric_ontology_tool import (
create_datafabric_ontology_tool,
)

return create_datafabric_ontology_tool(
resource,
llm,
tool_name=tool_name,
agent_config={BASE_SYSTEM_PROMPT: _extract_system_prompt(agent)},
)

if resource.context_type == AgentContextType.DATA_FABRIC_ENTITY_SET:
if llm is None:
raise ValueError("Data Fabric entity set tools require an LLM instance")

from .datafabric_tool import create_datafabric_query_tool
from .datafabric_tool.datafabric_tool import BASE_SYSTEM_PROMPT

Expand Down
9 changes: 5 additions & 4 deletions src/uipath_langchain/agent/tools/datafabric_tool/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
"""Data Fabric tool module for entity-based SQL queries."""
"""Data Fabric tool module for entity-based and ontology-based SQL queries."""

from .datafabric_tool import (
create_datafabric_query_tool,
)
from .datafabric_ontology_tool import create_datafabric_ontology_tool
from .datafabric_tool import DATAFABRIC_ONTOLOGY_FF, create_datafabric_query_tool

__all__ = [
"DATAFABRIC_ONTOLOGY_FF",
"create_datafabric_ontology_tool",
"create_datafabric_query_tool",
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
"""Inner system-prompt builder for the Data Fabric **ontology** tool.

Separate from the entity tool's ``datafabric_prompt_builder`` so the two prompts
can evolve independently. This builder assembles an ontology-grounded prompt:
the OWL (authoritative semantic schema) and the R2RML (ontology→table/column
mapping) come first, then the SQL strategy/constraints and the entity schema
tables.

It reuses only ``build_sql_context`` (entity-context + strategy prompt
construction) from ``datafabric_prompt_builder``; the top-level layout, the
ontology-specific framing, and the entity-schema rendering are all owned here so
the shared entity-tool builder is not modified by this feature.
"""

from uipath.platform.entities import Entity

from .datafabric_prompt_builder import SQLContext, build_sql_context


def _render_entity_schema_sections(ctx: SQLContext) -> list[str]:
"""Render the entity-schema tables + query patterns as prompt lines."""
lines: list[str] = ["## All available Data Fabric Entities", ""]

for entity_ctx in ctx.entity_contexts:
entity = entity_ctx.entity_schema
lines.append(
f"### Entity: {entity.display_name} (SQL table: `{entity.entity_name}`)"
)
if entity.description:
lines.append(f"_{entity.description}_")
lines.append("")
lines.append("| Field | Type | Description |")
lines.append("|-------|------|-------------|")
for field in entity.fields:
desc = (field.description or "").replace("|", r"\|").replace("\n", " ")
lines.append(f"| {field.name} | {field.display_type} | {desc} |")

lines.append("")

lines.append(f"**Query Patterns for {entity.entity_name}:**")
lines.append("")
lines.append("| User Intent | SQL Pattern |")
lines.append("|-------------|-------------|")
for p in entity_ctx.query_patterns:
lines.append(f"| '{p.intent}' | `{p.sql}` |")
lines.append("")

return lines
Comment thread
sankalp-uipath marked this conversation as resolved.


def format_ontology_context(
ctx: SQLContext,
ontology_text: str = "",
r2rml_text: str = "",
) -> str:
"""Format a SQLContext + ontology artifacts as the ontology-tool prompt."""
lines: list[str] = []

if ctx.base_system_prompt:
lines.append("## Agent Instructions")
lines.append("")
lines.append(ctx.base_system_prompt)
lines.append("")

if ontology_text:
lines.append(
"## Available Ontology (authoritative semantic schema)\n\n"
"The ontology below is the authoritative source for the exact column "
"names, value formats (date formats, codes, zero-padding), allowed "
"values, and the relationships between entities — richer and more "
"reliable than the field list further down, which omits value formats "
"and semantics. Base your column names, filter values, and joins on "
"it; when it and the entity tables disagree, the ontology wins.\n\n"
f"{ontology_text}"
)
lines.append("")

if r2rml_text:
lines.append(
"## Ontology→Table Mapping (R2RML)\n\n"
"The R2RML below maps the ontology to the physical tables and columns "
"you must use in SQL: `rr:tableName` is the SQL table, `rr:column` is "
"the SQL column for each ontology predicate, and `rr:joinCondition` "
"(child/parent) gives the exact columns to join on. Use it to turn "
"ontology terms into precise SQL identifiers and joins.\n\n"
f"{r2rml_text}"
)
lines.append("")

if ctx.sql_expert_system_prompt:
lines.append("## SQL Query Generation Guidelines")
lines.append("")
lines.append(ctx.sql_expert_system_prompt)
lines.append("")

if ctx.constraints:
lines.append("## SQL Constraints")
lines.append("")
lines.append(ctx.constraints)
lines.append("")

if ctx.resource_description:
lines.append("## Ontology description")
lines.append("")
lines.append(ctx.resource_description)
lines.append("")

lines.extend(_render_entity_schema_sections(ctx))

return "\n".join(lines)


def build(
entities: list[Entity],
resource_description: str = "",
base_system_prompt: str = "",
ontology_text: str = "",
r2rml_text: str = "",
prompt_version: str | None = None,
) -> str:
"""Build the ontology-tool inner system prompt.

Args:
entities: Resolved Data Fabric entities (from the R2RML allow-list).
resource_description: Optional description of the ontology context.
base_system_prompt: Optional system prompt from the outer agent.
ontology_text: The fetched ontology OWL content (authoritative schema).
r2rml_text: The fetched ontology R2RML mapping (ontology→table/column).
prompt_version: Optional SQL-strategy prompt version key.

Returns:
Formatted prompt string for the inner LLM system message.
"""
if not entities:
return ""

ctx = build_sql_context(
entities,
resource_description,
base_system_prompt,
prompt_version=prompt_version,
)
return format_ontology_context(
ctx, ontology_text=ontology_text, r2rml_text=r2rml_text
)
Loading
Loading