ontocast.integrations.langchain¶
Expose OntoCast capabilities as LangChain tools.
ontocast_tools(tools) returns a list of BaseTool objects that any
LangChain or LangGraph agent can call:
from langchain.agents import create_agent
from ontocast import Config, ToolBox, ontocast_tools
tools = await ToolBox.acreate(Config.in_memory())
await tools.initialize()
agent = create_agent(model, tools=[*ontocast_tools(tools)])
Two design rules run through this module.
Capability gating. A tool whose backend is missing is not returned, rather
than returned and made to fail on first call. A base install has no Qdrant, no
docling, and possibly no SPARQL-capable store, and an agent handed a tool that
always errors will keep retrying it. :func:ontocast_tool_diagnostics explains
each omission, since "my agent has six tools instead of eleven" is otherwise
unbreakable.
Mutation is opt-in. The write tools are excluded unless mutating=True.
ontocast_delete_ontology drops a named graph, unlinks a file from disk, and
deletes vectors -- three irreversible effects from one model-chosen string.
ontocast_tool_diagnostics(tools)
¶
Explain why each unavailable tool is unavailable.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tools
|
'ToolBox'
|
The ToolBox the tools would be built against. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, str]
|
Mapping of tool name to the reason it would be skipped. Tools that are |
dict[str, str]
|
available are absent from the mapping. |
Source code in ontocast/integrations/langchain.py
ontocast_tool_names(tools, *, mutating=False)
¶
Return the names :func:ontocast_tools would produce, without building them.
Source code in ontocast/integrations/langchain.py
ontocast_tools(tools, *, include=None, exclude=None, mutating=False, max_chars=20000)
¶
Wrap OntoCast capabilities as LangChain structured tools.
Only tools whose backend is installed and configured are returned; call
:func:ontocast_tool_diagnostics to see why something is missing.
All tools are async-only. Agents must invoke them with ainvoke; a
synchronous invoke raises NotImplementedError. Several of the
underlying calls are coroutines already, and the rest are CPU-heavy enough
that running them on the caller's event loop would stall it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tools
|
'ToolBox'
|
A constructed ToolBox. Call |
required |
include
|
Iterable[str] | None
|
Restrict to these tool names. |
None
|
exclude
|
Iterable[str] | None
|
Drop these names from whatever |
None
|
mutating
|
bool
|
Include the write tools. Off by default; each one changes stored state irreversibly. |
False
|
max_chars
|
int
|
Truncation budget applied to each tool's rendered result. |
20000
|
Returns:
| Type | Description |
|---|---|
list[BaseTool]
|
Available tools in a stable order. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |