ontocast.integrations.langgraph¶
Embed the OntoCast pipeline as a node in someone else's LangGraph.
AgentState declares no Annotated[..., reducer] channels and every node
returns the whole state, so adding the compiled graph directly to a parent
StateGraph only works when the parent's state literally has raw_input,
docling_doc, aggregated_facts and the rest. input_schema and
output_schema narrow which of AgentState's own keys cross the boundary
but cannot rename them, so they do not bridge a foreign state either.
:func:make_ontocast_node therefore asks for the mapping explicitly. That is
30 lines of adapter instead of a reducer refactor, and it is honest about where
the boundary is.
make_ontocast_node(tools, *, to_agent_state, from_agent_state, recursion_limit=None, graph=None)
¶
Build a node that runs the OntoCast pipeline inside another graph.
to_state, from_state = text_in_turtle_out()
node = make_ontocast_node(tools, to_agent_state=to_state, from_agent_state=from_state)
builder = StateGraph(MyState)
builder.add_node("extract", node)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tools
|
'ToolBox'
|
The dependency container. The graph is compiled once here, not per invocation. |
required |
to_agent_state
|
Callable[[Any], AgentState]
|
Maps the parent state to a fresh |
required |
from_agent_state
|
Callable[[AgentState, Any], dict[str, Any]]
|
Maps the finished |
required |
recursion_limit
|
int | None
|
LangGraph recursion limit for the inner run. Defaults to a value derived from the configured chunk budget. Leaving this unset is safer than passing LangGraph's default of 25, which a multi-chunk document exceeds. |
None
|
graph
|
CompiledStateGraph | None
|
A pre-compiled OntoCast graph to reuse instead of compiling one. |
None
|
Returns:
| Type | Description |
|---|---|
Callable[[Any, RunnableConfig], Awaitable[dict[str, Any]]]
|
An async node callable suitable for |
Source code in ontocast/integrations/langgraph.py
text_in_turtle_out(*, text_key='input', ontology_key='ontology_ttl', facts_key='facts_ttl')
¶
Return a ready-made mapping pair for the common text-to-Turtle case.
Reads a string off the parent state and writes back two Turtle strings, so a parent state needs only those three plain keys.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text_key
|
str
|
Parent-state key holding the source text. |
'input'
|
ontology_key
|
str
|
Parent-state key to write the ontology Turtle to. |
'ontology_ttl'
|
facts_key
|
str
|
Parent-state key to write the facts Turtle to. |
'facts_ttl'
|
Returns:
| Type | Description |
|---|---|
tuple[Callable[[Any], AgentState], Callable[[AgentState, Any], dict[str, Any]]]
|
The |