Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 6 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 Down
14 changes: 12 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,21 @@ 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

if tool.ProviderMetadata != nil {
fmt.Println("provider metadata: ", tool.ProviderMetadata)
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove debugging statement

if metadata, ok := tool.ProviderMetadata.Get(ProviderName); ok {
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe there's a GetMetadata helper that you should use here. You should be able to find examples of it being used elsewhere in the codebase.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

metadata := metadata.(Metadata)
if metadata.StrictSchemas != nil {
strict = *metadata.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