API Reference / agent / adapters /

anthropic.py

Anthropic adapter, TuiML tools in the Messages API tools shape.

Anthropic's native MCP support already lets Claude Desktop / Claude Code consume the tuiml-mcp server directly. This adapter is for code that calls the Messages API (client.messages.create) and wants to hand-roll the tool-use loop, e.g., server-side agents, custom UIs, or Anthropic SDK usage outside an MCP-aware client.
python
>>> from tuiml.agent.adapters import anthropic as tuiml_anthropic
>>> from tuiml.agent import invoke as tuiml_invoke
>>> tools = tuiml_anthropic.get_tools()
>>> # In your tool-use loop: when response.stop_reason == "tool_use",
>>> # iterate response.content for tool_use blocks and call tuiml_anthropic.dispatch_tool_use(block).

Functions

Func

get_tools

Line 25
get_tools() -> List[Dict[str, Any]]

Return every TuiML workflow tool as an Anthropic Messages tool dict.

Returns

list of dict
One dict per workflow tool in the Messages API tools shape:: {"name": ..., "description": ..., "input_schema": {...}} where "input_schema" is a JSON Schema object. Pass this list directly to client.messages.create(tools=tools, ...).
python
>>> from tuiml.agent.adapters import anthropic as tuiml_anthropic
>>> tools = tuiml_anthropic.get_tools()
>>> response = client.messages.create(
...     model="claude-sonnet-4-6",
...     system=tuiml_anthropic.system_prompt(),
...     tools=tools,
...     messages=[{"role": "user", "content": "Train a model on iris"}],
...     max_tokens=1024,
... )
Func

dispatch_tool_use

Line 60
dispatch_tool_use(block: Any) -> Dict[str, Any]

Execute an Anthropic tool_use content block and return the result.

Parameters

block
Any
Either an SDK block object (with .name and .input) or the raw dict form {"type": "tool_use", "name": ..., "input": ...}.

Returns

dict
The TuiML structured result dict for the tool call (with a "status" key plus tool-specific fields).
Func

system_prompt

Line 84
system_prompt() -> str

Return the canonical TuiML system prompt (SKILL.md) to pass as the system= parameter on client.messages.create.

Returns

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