Documentation
¶
Index ¶
- Constants
- func BashTool(options ...BashToolOption) *api.ProviderDefinedTool
- func ComputerTool(displayWidth, displayHeight int, options ...ComputerToolOption) *api.ProviderDefinedTool
- func DecodeResponse(msg *anthropic.BetaMessage) (*api.Response, error)
- func EncodeAssistantMessage(msg *api.AssistantMessage) (anthropic.BetaMessageParam, error)
- func EncodeFileBlock(block *api.FileBlock) (anthropic.BetaRequestDocumentBlockParam, []anthropic.AnthropicBeta, error)
- func EncodeFunctionTool(tool *api.FunctionTool) (anthropic.BetaToolUnionParam, error)
- func EncodeImageBlock(block *api.ImageBlock) (anthropic.BetaImageBlockParam, error)
- func EncodeParams(modelID string, prompt []api.Message, opts api.CallOptions) (anthropic.BetaMessageNewParams, []api.CallWarning, error)
- func EncodeProviderDefinedTool(tool *api.ProviderDefinedTool) (anthropic.BetaToolUnionParam, []anthropic.AnthropicBeta, []api.CallWarning, ...)
- func EncodeReasoningBlock(block *api.ReasoningBlock) (anthropic.BetaContentBlockParamUnion, error)
- func EncodeSystemMessage(msg *api.SystemMessage) (anthropic.BetaTextBlockParam, error)
- func EncodeTextBlock(block *api.TextBlock) (anthropic.BetaTextBlockParam, error)
- func EncodeToolCallBlock(block *api.ToolCallBlock) (anthropic.BetaToolUseBlockParam, error)
- func EncodeToolChoice(toolChoice *api.ToolChoice) (anthropic.BetaToolChoiceUnionParam, error)
- func EncodeToolMessage(msg *api.ToolMessage) (anthropic.BetaMessageParam, error)
- func EncodeUserContentBlock(block api.ContentBlock) (anthropic.BetaContentBlockParamUnion, []anthropic.AnthropicBeta, error)
- func EncodeUserMessage(msg *api.UserMessage) (anthropic.BetaMessageParam, []anthropic.AnthropicBeta, error)
- func NewAssistantMessage(blocks ...anthropic.BetaContentBlockParamUnion) anthropic.BetaMessageParam
- func NewImageBlockBase64(mediaType, encodedData string) anthropic.BetaImageBlockParam
- func NewTextBlock(text string) anthropic.BetaTextBlockParam
- func NewToolResultBlock(toolUseID, content string, isError bool) anthropic.BetaToolResultBlockParam
- func NewToolUseBlockParam(id, name string, input interface{}) anthropic.BetaToolUseBlockParam
- func NewUserMessage(blocks ...anthropic.BetaContentBlockParamUnion) anthropic.BetaMessageParam
- func TextEditorTool(options ...TextEditorToolOption) *api.ProviderDefinedTool
- type AnthropicPrompt
- type AnthropicTools
- type BashToolArgs
- type BashToolOption
- type ComputerAction
- type ComputerToolArgs
- type ComputerToolCall
- type ComputerToolOption
- type Metadata
- type ScrollDirection
- type TextEditorToolArgs
- type TextEditorToolOption
- type ThinkingConfig
- type Usage
Constants ¶
const ( DefaultToolVersion = "20250124" RecommendedDisplayWidth = 1280 RecommendedDisplayHeight = 800 )
Default versions and recommended settings for Anthropic tools
const ( ScrollUp = "up" ScrollDown = "down" ScrollLeft = "left" ScrollRight = "right" )
Variables ¶
This section is empty.
Functions ¶
func BashTool ¶
func BashTool(options ...BashToolOption) *api.ProviderDefinedTool
BashTool creates a new bash tool with the specified configuration. BashTool is a built-in tool that can be used to run shell commands. See the [computer use guide](https://docs.anthropic.com/en/docs/agents-and-tools/computer-use) for more details.
func ComputerTool ¶ added in v0.2.0
func ComputerTool(displayWidth, displayHeight int, options ...ComputerToolOption) *api.ProviderDefinedTool
ComputerTool creates a new computer use tool with the specified configuration. ComputerTool is a built-in tool that can be used to control a computer. It allows the model to use a mouse and keyboard and to take screenshots. See the [computer use guide](https://docs.anthropic.com/en/docs/agents-and-tools/computer-use) for more details.
func DecodeResponse ¶
func DecodeResponse(msg *anthropic.BetaMessage) (*api.Response, error)
DecodeResponse converts an Anthropic Message to the AI SDK Response type
func EncodeAssistantMessage ¶
func EncodeAssistantMessage(msg *api.AssistantMessage) (anthropic.BetaMessageParam, error)
func EncodeFileBlock ¶
func EncodeFileBlock(block *api.FileBlock) (anthropic.BetaRequestDocumentBlockParam, []anthropic.AnthropicBeta, error)
func EncodeFunctionTool ¶
func EncodeFunctionTool(tool *api.FunctionTool) (anthropic.BetaToolUnionParam, error)
EncodeFunctionTool converts an API FunctionTool to Anthropic's tool format
func EncodeImageBlock ¶
func EncodeImageBlock(block *api.ImageBlock) (anthropic.BetaImageBlockParam, error)
func EncodeParams ¶
func EncodeParams( modelID string, prompt []api.Message, opts api.CallOptions, ) (anthropic.BetaMessageNewParams, []api.CallWarning, error)
func EncodeProviderDefinedTool ¶
func EncodeProviderDefinedTool( tool *api.ProviderDefinedTool, ) (anthropic.BetaToolUnionParam, []anthropic.AnthropicBeta, []api.CallWarning, error)
EncodeProviderDefinedTool converts provider-defined tools to Anthropic's format Returns the tool, required betas, and any warnings
func EncodeReasoningBlock ¶
func EncodeReasoningBlock(block *api.ReasoningBlock) (anthropic.BetaContentBlockParamUnion, error)
func EncodeSystemMessage ¶
func EncodeSystemMessage(msg *api.SystemMessage) (anthropic.BetaTextBlockParam, error)
func EncodeTextBlock ¶
func EncodeTextBlock(block *api.TextBlock) (anthropic.BetaTextBlockParam, error)
func EncodeToolCallBlock ¶
func EncodeToolCallBlock(block *api.ToolCallBlock) (anthropic.BetaToolUseBlockParam, error)
func EncodeToolChoice ¶
func EncodeToolChoice( toolChoice *api.ToolChoice, ) (anthropic.BetaToolChoiceUnionParam, error)
EncodeToolChoice converts API ToolChoice to Anthropic's format
func EncodeToolMessage ¶
func EncodeToolMessage(msg *api.ToolMessage) (anthropic.BetaMessageParam, error)
func EncodeUserContentBlock ¶
func EncodeUserContentBlock(block api.ContentBlock) (anthropic.BetaContentBlockParamUnion, []anthropic.AnthropicBeta, error)
func EncodeUserMessage ¶
func EncodeUserMessage(msg *api.UserMessage) (anthropic.BetaMessageParam, []anthropic.AnthropicBeta, error)
func NewAssistantMessage ¶
func NewAssistantMessage(blocks ...anthropic.BetaContentBlockParamUnion) anthropic.BetaMessageParam
func NewImageBlockBase64 ¶
func NewImageBlockBase64(mediaType, encodedData string) anthropic.BetaImageBlockParam
func NewTextBlock ¶
func NewTextBlock(text string) anthropic.BetaTextBlockParam
func NewToolResultBlock ¶
func NewToolResultBlock(toolUseID, content string, isError bool) anthropic.BetaToolResultBlockParam
func NewToolUseBlockParam ¶
func NewToolUseBlockParam(id, name string, input interface{}) anthropic.BetaToolUseBlockParam
func NewUserMessage ¶
func NewUserMessage(blocks ...anthropic.BetaContentBlockParamUnion) anthropic.BetaMessageParam
func TextEditorTool ¶
func TextEditorTool(options ...TextEditorToolOption) *api.ProviderDefinedTool
TextEditorTool creates a new text editor tool with the specified configuration. TextEditorTool is a built-in tool that can be used to view, create and edit text files. See the [text editor guide](https://docs.anthropic.com/en/docs/build-with-claude/tool-use/text-editor-tool) for more details.
Types ¶
type AnthropicPrompt ¶
type AnthropicPrompt struct {
System []anthropic.BetaTextBlockParam `json:"system,omitempty"`
Messages []anthropic.BetaMessageParam `json:"messages"`
Betas []anthropic.AnthropicBeta `json:"betas,omitempty"`
}
func EncodePrompt ¶
func EncodePrompt(prompt []api.Message) (*AnthropicPrompt, error)
EncodePrompt converts an AI SDK prompt into Anthropic's message format
type AnthropicTools ¶
type AnthropicTools struct {
Tools []anthropic.BetaToolUnionParam
ToolChoice anthropic.BetaToolChoiceUnionParam
Betas []anthropic.AnthropicBeta
Warnings []api.CallWarning
}
func EncodeTools ¶
func EncodeTools(tools []api.ToolDefinition, toolChoice *api.ToolChoice) (AnthropicTools, error)
EncodeTools processes the top-level Tools and ToolChoice fields from CallOptions and returns all the anthropic-specific tool configuration
type BashToolArgs ¶ added in v0.2.0
type BashToolArgs struct {
// The version of the bash tool to use.
// Optional field, defaults to the latest version. Possible values are: "20250124", "20241022".
Version string `json:"version"`
}
BashToolArgs contains the configuration arguments for the bash tool. See the [computer use guide](https://docs.anthropic.com/en/docs/agents-and-tools/computer-use) for more details.
type BashToolOption ¶ added in v0.2.0
type BashToolOption func(*BashToolArgs)
BashToolOption allows customizing bash tool configuration.
func WithBashVersion ¶ added in v0.2.0
func WithBashVersion(version string) BashToolOption
WithBashVersion sets the bash tool version.
type ComputerAction ¶
type ComputerAction string
ComputerAction is a ComputerToolCall action.
const ( // ActionKey presses the key or key-combination specfied in // [ComputerToolCall.Text]. It supports xdotool's key syntax. ActionKey ComputerAction = "key" // ActionHoldKey holds down the key or key-combination in // [ComputerToolCall.Text] for a duration of // [ComputerToolCall.Duration]. It supports the same syntax as // [ActionKey]. ActionHoldKey ComputerAction = "hold_key" // ActionType types the string specified by [ComputerToolCall.Text] on // the keyboard. ActionType ComputerAction = "type" // ActionCursorPosition reports the current (x, y) pixel coordinates of // the cursor on the screen. ActionCursorPosition ComputerAction = "cursor_position" // ActionMouseMove moves the cursor to the pixel specified by // [ComputerToolCall.Coordinate]. ActionMouseMove ComputerAction = "mouse_move" // ActionLeftMouseDown presses down the left mouse button without // releasing it. ActionLeftMouseDown ComputerAction = "left_mouse_down" // ActionLeftMouseUp releases the left mouse button. ActionLeftMouseUp ComputerAction = "left_mouse_up" // ActionLeftClick clicks the left mouse button at // [ComputerToolCall.Coordinate] while optionally holding down the keys // in [ComputerToolCall.Text]. ActionLeftClick ComputerAction = "left_click" // ActionLeftClickDrag clicks and drags the cursor from // [ComputerToolCall.StartCoordinate] to [ComputerToolCall.Coordinate]. ActionLeftClickDrag ComputerAction = "left_click_drag" // ActionRightClick clicks the right mouse button at // [ComputerToolCall.Coordinate]. ActionRightClick ComputerAction = "right_click" // ActionMiddleClick clicks the middle mouse button at // [ComputerToolCall.Coordinate]. ActionMiddleClick ComputerAction = "middle_click" // ActionDoubleClick double-clicks the left mouse button at // [ComputerToolCall.Coordinate]. ActionDoubleClick ComputerAction = "double_click" // ActionTripleClick triple-clicks the left mouse button at // [ComputerToolCall.Coordinate]. ActionTripleClick ComputerAction = "triple_click" // ActionScroll turns the mouse scroll wheel by // [ComputerToolCall.ScrollAmount] in the direction of // [ComputerToolCall.ScrollDirection] at [ComputerToolCall.Coordinate]. ActionScroll ComputerAction = "scroll" // ActionWait pauses execution for [ComputerToolCall.Duration]. ActionWait ComputerAction = "wait" // ActionScreenshot takes a screenshot. ActionScreenshot ComputerAction = "screenshot" )
type ComputerToolArgs ¶ added in v0.2.0
type ComputerToolArgs struct {
// The version of the computer tool to use.
// Optional field, defaults to the latest version. Possible values are: "20250124", "20241022".
Version string `json:"version"`
// The width of the display being controlled by the model in pixels.
// Required field. We recommend setting it to 1280.
DisplayWidthPx int `json:"display_width_px"`
// The height of the display being controlled by the model in pixels.
// Required field. We recommend setting it to 800.
DisplayHeightPx int `json:"display_height_px"`
// The display number to control (only relevant for X11 environments).
// Optional field, if specified, the tool will be provided a display number in the tool definition.
DisplayNumber int `json:"display_number,omitzero"`
}
ComputerToolArgs contains the configuration arguments for the computer use tool. See the [computer use guide](https://docs.anthropic.com/en/docs/agents-and-tools/computer-use) for more details.
type ComputerToolCall ¶
type ComputerToolCall struct {
// Action is the action to perform. It is the only mandatory field.
Action ComputerAction `json:"action"`
// Text is a key, key-combination, or string literal to type on the
// keyboard. It specifies individual key presses or key-combinations
// using an xdotool-style syntax. Examples include "a", "Return",
// "alt+Tab", "ctrl+s", "Up", "KP_0" (for numpad 0). The ActionType,
// ActionKey, and ActionHoldKey actions require a non-empty Text value.
// Click or scroll actions may optionally set Text to specify keys to
// hold down keys during the click or scroll.
Text string `json:"text,omitzero"`
// Coordinate is a pair of (x, y) on-screen pixel coordinates for cursor
// actions. (0, 0) is the top-left corner of the screen. The
// ActionMouseMove and ActionLeftClickDrag actions require a coordinate.
Coordinate [2]json.Number `json:"coordinate,omitzero"`
// StartCoordinate is the starting point for mouse drag actions.
StartCoordinate [2]json.Number `json:"start_coordinate,omitzero"`
// Duration is the number of seconds to hold down keys or pause
// execution. The ActionHoldKey and ActionWait actions require a
// non-zero Duration.
Duration json.Number `json:"duration,omitzero"`
// ScrollAmount is the number of mouse wheel "clicks" to scroll.
// ActionScroll requires a non-zero ScrollAmount.
ScrollAmount json.Number `json:"scroll_amount,omitzero"`
// ScrollDirection is the direction to scroll. ActionScroll requires
// a ScrollDirection.
ScrollDirection ScrollDirection `json:"scroll_direction,omitzero"`
}
ComputerToolCall contains the parameters of a call to ComputerTool.
type ComputerToolOption ¶ added in v0.2.0
type ComputerToolOption func(*ComputerToolArgs)
ComputerToolOption allows customizing computer tool configuration.
func WithComputerVersion ¶ added in v0.2.0
func WithComputerVersion(version string) ComputerToolOption
WithComputerVersion sets the computer tool version.
func WithDisplayNumber ¶ added in v0.2.0
func WithDisplayNumber(displayNum int) ComputerToolOption
WithDisplayNumber sets the display number for X11 environments.
type Metadata ¶
type Metadata struct {
// --- Used in requests ---
CacheControl string `json:"cache_control,omitempty"`
Thinking ThinkingConfig `json:"thinking,omitzero"`
Usage Usage `json:"usage,omitempty"`
// RedactedData contains redacted reasoning data when reasoning blocks are redacted
RedactedData string `json:"redacted_data,omitempty"`
}
For now we are using a single type for all metadata. TODO: Decide if we will need different types for different metadata.
func GetMetadata ¶
func GetMetadata(source api.MetadataSource) *Metadata
type ScrollDirection ¶
type ScrollDirection string
ScrollDirection is a direction to scroll the screen.
type TextEditorToolArgs ¶ added in v0.2.0
type TextEditorToolArgs struct {
// The version of the text editor tool to use.
// Optional field, defaults to the latest version. Possible values are: "20250124", "20241022".
Version string `json:"version"`
}
TextEditorToolArgs contains the configuration arguments for the text editor tool. See the [text editor guide](https://docs.anthropic.com/en/docs/build-with-claude/tool-use/text-editor-tool) for more details.
type TextEditorToolOption ¶ added in v0.2.0
type TextEditorToolOption func(*TextEditorToolArgs)
TextEditorToolOption allows customizing text editor tool configuration.
func WithTextEditorVersion ¶ added in v0.2.0
func WithTextEditorVersion(version string) TextEditorToolOption
WithTextEditorVersion sets the text editor tool version.
type ThinkingConfig ¶
type ThinkingConfig struct {
// Whether to enable extended thinking.
//
// See
// [extended thinking](https://docs.anthropic.com/en/docs/build-with-claude/extended-thinking)
// for details.
Enabled bool `json:"enabled,omitzero"`
// Determines how many tokens Claude can use for its internal reasoning process.
// Larger budgets can enable more thorough analysis for complex problems, improving
// response quality.
//
// Must be ≥1024 and less than `max_tokens`.
BudgetTokens int `json:"budgetTokens,omitzero"`
}
ThinkingConfig represents the configuration for thinking behavior