package anthropic

  1. Overview
  2. Docs

Module Anthropic.ToolsSource

Tools module for handling tool execution patterns.

This module provides utilities to simplify tool handling in conversations.

Sourcetype tool_execution_result =
  1. | Success of Yojson.Safe.t
  2. | Error of string
    (*

    Result of executing a tool.

    *)
Sourceval make_tool_result : tool_use_id:string -> result:tool_execution_result -> input_content_block

make_tool_result ~tool_use_id ~result creates a tool result content block.

Example:

  let result =
    Tools.make_tool_result ~tool_use_id:"tool_123"
      ~result:(Success (`Assoc [ ("answer", `Int 42) ]))
Sourceval requires_tool_execution : Messages.response_content_block list -> bool

requires_tool_execution blocks checks if response contains tool use requests.

Sourceval extract_tool_calls : Messages.response_content_block list -> (string * string * Yojson.Safe.t) list

extract_tool_calls blocks extracts all tool calls from response blocks. Returns a list of (id, name, input) tuples.