Skip to main content
The model proposes. HeavenBase can execute — or just hand you the JSON and step back.
Tool use is where chat stops being text-only. Pass tools to chat, stream, or LLMSession, and HeavenBase normalizes schemas, runs executable callables, and projects the full turn through include.

1. What You Can Pass

The tools list accepts:
  • OpenAI-compatible function schema dictionaries.
  • Plain Python callables with type annotations and docstrings.
  • HeavenBase Tool objects.
  • HeavenBase Toolkit objects, including MCP servers imported with Toolkit.from_fastmcp(...).
Schema-only tools are sent to the provider and returned as tool_calls. Executable tools run automatically, and their role="tool" result messages appear in delta and messages. Tool execution errors serialize as structured tool-result content:

2. Schema-Only Tools

Use schema-only tools when another process will execute the calls:
Tool calls are collected from streaming deltas and returned in the standard OpenAI tool_calls shape.

3. Executable Tools

Use functions or Toolkits when HeavenBase should run the tools for the model:
When the model calls add, HeavenBase appends the assistant tool-call message, a tool-result message, then asks the model for the final answer. A typical delta looks like:
Control how many assistant iterations run with max_tool_turns (default 8 in Python, mapped from --max-steps in the CLI):
Async callables require achat instead of chat.

4. MCP as Toolkit

MCP servers become normal tools by importing them as a HeavenBase Toolkit:
The same pattern works with HTTP/SSE MCP URLs accepted by FastMCP clients. The CLI exposes the same execution path:
Inside a session, add another MCP source with /mcp SOURCE. hb llm chat --max-steps caps assistant iterations in a tool loop; the default is 20.

5. Structured Output

Pass OpenAI-compatible response_format arguments directly:
Most providers stream structured output through the normal path. When a model is known to be unreliable for streaming structured JSON, its model defaults can set structured_stream: false. Force a non-streaming structured call when you need a single reliable payload:
For stream(..., enforce_non_stream_structured=True), HeavenBase performs one non-streaming request and yields a single projected chunk.

6. Tool-Call Repair

Some providers return malformed JSON in tool_calls[].function.arguments. HeavenBase can repair common mistakes — fenced code blocks, unbalanced braces, missing required fields — before execution. Repair is off by default. Enable it globally:
Or per instance:
Set strict: true in config to raise when repair fails instead of returning the original arguments. See Advanced LLM for repair behavior details.

Further Exploration

Related resources:
  • Sessions — multi-turn tool use with LLMSession and hb llm session.
  • LLM Chat — CLI --mcp for single-turn agentic calls.
  • First MCP — attach a math Toolkit from the quickstart.