Skip to documentation
Documentation navigation

Documentation navigation

Documentation / guides

ToolUseBlock

Represent a model tool call with raw, provider-neutral arguments.

developer

ToolUseBlock is the assistant’s request to execute a named tool. Its arguments stay as json.RawMessage so the inference layer can preserve provider JSON exactly and let the tool runner perform domain validation.

API surface

type ToolUseBlock struct {
	ID    string
	Name  string
	Input json.RawMessage
}
FieldMeaning
IDProvider/tool-call identifier used to correlate the result
NameTool name declared in the request
InputRaw JSON argument object, including partial JSON while a stream is being accumulated

Core does not parse or validate Input. Treat it as untrusted until the selected tool validates it against its own contract.

Example

package main

import (
	"encoding/json"
	"fmt"

	"github.com/looprig/core/content"
)

func main() {
	call := &content.ToolUseBlock{
		ID: "call_42", Name: "weather",
		Input: json.RawMessage(`{"city":"Boston"}`),
	}
	wire, err := content.MarshalBlock(call)
	if err != nil {
		panic(err)
	}
	decoded, err := content.UnmarshalBlock(wire)
	if err != nil {
		panic(err)
	}
	fmt.Println(decoded.(*content.ToolUseBlock).Name)
}

During streaming, ToolUseChunk.InputJSON fragments are concatenated by streamaccumulator.ToolUses; the resulting ToolUseBlock.Input is deliberately left for the caller to parse.

Proof

Related: Tool definitions, Tool-call deltas, ToolResultBlock.

← back to documentation