Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion aisdk/ai/api/llm_tool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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{}
Expand All @@ -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
Expand Down
9 changes: 7 additions & 2 deletions aisdk/ai/provider/openai/internal/codec/encode_tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I care too much what the right default is, I think both are sensible, but just FYI, I'm looking at the Vercel code and they seem to now default to false instead: https://github.com/vercel/ai/blob/main/packages/openai/src/responses/openai-responses-language-model.ts#L135

They also seem to have renamed it from StrictSchemas to StrictJSONSchema 🤷

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kept default true for now

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
Expand Down
Loading