API Reference / agent / adapters /

langchain.py

LangChain / LangGraph adapter, TuiML tools as StructuredTool objects.

LangGraph consumes LangChain tools directly (ToolNode(tools=[...])), so this module covers both frameworks.
python
>>> from tuiml.agent.adapters.langchain import get_tools, system_prompt
>>> from langgraph.prebuilt import create_react_agent
>>> from langchain_anthropic import ChatAnthropic
>>>
>>> agent = create_react_agent(
...     model=ChatAnthropic(model="claude-sonnet-4-6"),
...     tools=get_tools(),
...     prompt=system_prompt(),
... )
>>> agent.invoke({"messages": [("user", "Train a random forest on iris")]})

Functions

Func

get_tools

Line 27
get_tools() -> List[Any]

Return every TuiML workflow tool wrapped in a LangChain StructuredTool.

Returns

list of langchain_core.tools.StructuredTool
One StructuredTool per workflow tool, each with a Pydantic args schema and a function that routes to the TuiML executor. Pass directly to LangChain agents or LangGraph ToolNode(tools=[...]).

Raises

ImportError
If langchain_core is not installed.
python
>>> from tuiml.agent.adapters.langchain import get_tools
>>> tools = get_tools()
>>> [t.name for t in tools][:2]  # doctest: +SKIP
['tuiml_train', 'tuiml_predict']
Func

system_prompt

Line 92
system_prompt() -> str

Return the canonical TuiML system prompt (SKILL.md) for prompt=.

Returns

str
The contents of the canonical SKILL.md system prompt.