OpenAI adapter, TuiML tools in OpenAI's function-calling shape.
Works with both the Chat Completions API (
client.chat.completions.create) and the new Agents SDK (agents.Agent(tools=[...])). For the Agents SDK, the recommended path is usually the native MCP integration (MCPServerStdio("tuiml-mcp")); this adapter exists for the Chat Completions and Responses paths that don't yet understand MCP.
python
>>> from tuiml.agent.adapters import openai as tuiml_openai
>>> from tuiml.agent import invoke as tuiml_invoke
>>> tools = tuiml_openai.get_tools()
>>> # pass tools=tools to client.chat.completions.create(...)
>>> # when the model returns a tool_call, dispatch it via tuiml_invoke(name, **args)
Functions
get_tools() -> List[Dict[str, Any]]
Return every TuiML workflow tool as an OpenAI function-calling dict.
Returns
list of dict
One dict per workflow tool in OpenAI's function-calling shape:: {"type": "function", "function": {"name": ..., "description": ..., "parameters": {...}}} where
"parameters" is a JSON Schema object. OpenAI accepts this format on both Chat Completions and the Responses API.
python
>>> from tuiml.agent.adapters import openai as tuiml_openai
>>> tools = tuiml_openai.get_tools()
>>> response = client.chat.completions.create(
... model="gpt-4o",
... tools=tools,
... messages=[
... {"role": "system", "content": tuiml_openai.system_prompt()},
... {"role": "user", "content": "Train a model on iris"},
... ],
... )
dispatch_tool_call(tool_call: Any) -> Dict[str, Any]
Execute an OpenAI tool-call object and return the structured result.
Parameters
tool_call
Any
Either a Chat Completions
tool_calls[i] entry (a Pydantic-like object with .function.name and .function.arguments) or a raw dict of the same shape. JSON-string arguments are decoded.
Returns
dict
The TuiML structured result dict for the tool call (with a
"status" key plus tool-specific fields).