GetSubjectGraphWorkflow
What it is
- A workflow that retrieves the subject graph for a given RDF individual/instance URI from a configured triple store.
- Returns the graph serialized as Turtle (
text/turtle) in a single string.
Public API
Classes
-
GetSubjectGraphWorkflowConfiguration(WorkflowConfiguration)- Workflow configuration placeholder (no additional fields).
-
GetSubjectGraphWorkflowParameters(WorkflowParameters)- Input parameters:
uri: str(required) — URI of the individual; validated againstURI_REGEX.depth: int(optional, default2) — traversal depth for the subject graph.
- Input parameters:
-
GetSubjectGraphWorkflow(Workflow)__init__(configuration: GetSubjectGraphWorkflowConfiguration)- Initializes SPARQL utilities using
ABIModule.get_instance().engine.services.triple_store.
- Initializes SPARQL utilities using
get_subject_graph(parameters: GetSubjectGraphWorkflowParameters) -> str- Fetches the subject graph via
SPARQLUtils.get_subject_graph(uri, depth)and serializes it to Turtle.
- Fetches the subject graph via
as_tools() -> list[BaseTool]- Exposes a LangChain
StructuredToolnamedget_subject_graphwithGetSubjectGraphWorkflowParametersas the argument schema.
- Exposes a LangChain
as_api(router: APIRouter, ...) -> None- Present but does not register any routes (returns
None).
- Present but does not register any routes (returns
Configuration/Dependencies
- Depends on:
naas_abi.ABIModulesingleton providingengine.services.triple_store.naas_abi_core.utils.SPARQL.SPARQLUtilsfor graph retrieval.langchain_core.tools.StructuredToolfor tool exposure.pydantic.Field/typing.Annotatedfor parameter schema and validation.URI_REGEXfor URI format validation.
Usage
from naas_abi.workflows.GetSubjectGraphWorkflow import (
GetSubjectGraphWorkflow,
GetSubjectGraphWorkflowConfiguration,
GetSubjectGraphWorkflowParameters,
)
wf = GetSubjectGraphWorkflow(GetSubjectGraphWorkflowConfiguration())
params = GetSubjectGraphWorkflowParameters(
uri="http://ontology.naas.ai/abi/a25ef0cc-56cf-458a-88c0-fabccb69e9b7",
depth=2,
)
turtle = wf.get_subject_graph(params)
print(turtle)
Using as a LangChain tool:
wf = GetSubjectGraphWorkflow(GetSubjectGraphWorkflowConfiguration())
tool = wf.as_tools()[0]
result = tool.run({
"uri": "http://ontology.naas.ai/abi/a25ef0cc-56cf-458a-88c0-fabccb69e9b7",
"depth": 2,
})
print(result)
Caveats
as_api(...)is a no-op in this implementation (no API routes are created).- Requires a working
ABIModuleinstance with an availabletriple_store; otherwise initialization or graph retrieval will fail.