diff --git a/aisdk/ai/api/llm_tool.go b/aisdk/ai/api/llm_tool.go index c2252ac3..04fd4929 100644 --- a/aisdk/ai/api/llm_tool.go +++ b/aisdk/ai/api/llm_tool.go @@ -30,7 +30,7 @@ type ToolDefinition interface { } // For the equivalent of ToolDefinition in MCP, see the Tool struct in: -// https://github.com/modelcontextprotocol/go-sdk/blob/main/mcp/protocol.go#L854 +// https://github.com/modelcontextprotocol/go-sdk/blob/main/mcp/protocol.go#L901 // FunctionTool represents a tool that has a name, description, and set of input arguments. // Note: this is not the user-facing tool definition. The AI SDK methods will @@ -47,6 +47,11 @@ type FunctionTool struct { // the tool's input requirements and provide matching suggestions. // InputSchema should be defined using a JSON schema. InputSchema *jsonschema.Schema `json:"input_schema,omitzero"` + + // ProviderMetadata contains additional provider-specific metadata. + // They are passed through to the provider from the AI SDK and enable + // provider-specific functionality that can be fully encapsulated in the provider. + ProviderMetadata *ProviderMetadata `json:"provider_metadata,omitzero"` } var _ ToolDefinition = &FunctionTool{} @@ -57,6 +62,9 @@ func (t *FunctionTool) Type() string { return "function" } // isToolDefinition is a marker method to satisfy the ToolDefinition interface func (t *FunctionTool) isToolDefinition() bool { return true } +// GetProviderMetadata returns the provider-specific metadata for the function tool +func (t FunctionTool) GetProviderMetadata() *ProviderMetadata { return t.ProviderMetadata } + // FunctionTool JSON marshaling - automatically includes "type" field func (t *FunctionTool) MarshalJSON() ([]byte, error) { type Alias FunctionTool diff --git a/aisdk/ai/provider/openai/internal/codec/encode_tools.go b/aisdk/ai/provider/openai/internal/codec/encode_tools.go index 24a7d3e4..5fcf1684 100644 --- a/aisdk/ai/provider/openai/internal/codec/encode_tools.go +++ b/aisdk/ai/provider/openai/internal/codec/encode_tools.go @@ -93,11 +93,16 @@ func encodeFunctionTool(tool api.FunctionTool) (*responses.ToolUnionParam, []api return nil, nil, fmt.Errorf("failed to convert tool parameters: %w", err) } + strict := true // Default to true + md := GetMetadata(tool) + if md != nil && md.StrictSchemas != nil { + strict = *md.StrictSchemas + } + result := responses.ToolParamOfFunction( name, props, - // TODO: allow passing the strict flag to the function - true, // strict mode enabled + strict, ) // Add description if provided