Skip to content

[dotnet-code] Consolidate OpenAI tool schema conversion#535

Open
michelle-clayton-work wants to merge 2 commits into
mainfrom
dotnet-code-openai-tool-schema-helper-20260714224108-151da8cb1496cb3c
Open

[dotnet-code] Consolidate OpenAI tool schema conversion#535
michelle-clayton-work wants to merge 2 commits into
mainfrom
dotnet-code-openai-tool-schema-helper-20260714224108-151da8cb1496cb3c

Conversation

@michelle-clayton-work

Copy link
Copy Markdown
Contributor

Summary

Consolidated the duplicated function-tool schema conversion in the OpenAI chat completions and responses request builders through the existing unexported schemaToMap helper. This keeps the Go provider internals closer to the .NET provider's central FunctionDefinition shape while preserving the generated request payloads.

.NET Reference

  • dotnet/src/Microsoft.Agents.AI.Hosting.OpenAI/ChatCompletions/Models/Tool.cs - central tool/function definition model used when constructing OpenAI tool payloads.

Public API and Behavior

No public Go API changed. No intentional behavior change was made.

Tests

  • gofmt -w provider/openaiprovider/chat.go provider/openaiprovider/responses.go
  • go test ./provider/openaiprovider

Notes

Rejected candidates:

  • dotnet/src/Microsoft.Agents.AI/Skills/Decorators/FilteringAgentSkillsSource.cs - Go already exposes skill filtering through ContextProviderOptions.SkillFilter; adding a .NET-style source decorator would add new public API, so it was rejected.
  • dotnet/src/Microsoft.Agents.AI.Workflows/Checkpointing/JsonConverterDictionarySupportBase.cs - Go checkpoint JSON uses explicit entry structs rather than dictionary-key converters, so there was no narrow structural cleanup that would improve parity without churn.
  • dotnet/src/Microsoft.Agents.AI.Workflows/Specialized/Magentic/MagenticConstants.cs - no corresponding Go Magentic internals exist in the current sampled surface, so adding constants would be placeholder feature shape rather than portability cleanup.

Open [dotnet-code] PR #484 already covers workflow edge construction, so adjacent workflow-edge work was avoided.

Generated by .NET-to-Go Code Portability Refactoring Agent · 521.9 AIC · ⌖ 54.5 AIC · ⊞ 20.8K ·

Closes #498

Share the internal schema conversion helper between chat completions and responses tool request construction so the Go provider shape stays closer to the central .NET FunctionDefinition model without changing API or request behavior.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Consolidates duplicated OpenAI function-tool schema conversion logic in the Chat Completions and Responses request builders by reusing the existing internal schemaToMap helper, aiming to keep the Go OpenAI provider’s internal shape closer to the .NET FunctionDefinition model without changing the generated payloads.

Changes:

  • Replaced inlined JSON marshal/unmarshal schema conversion in chat.go with a call to schemaToMap.
  • Replaced inlined JSON marshal/unmarshal schema conversion in responses.go with a call to schemaToMap.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
provider/openaiprovider/chat.go Switches function-tool schema conversion to use schemaToMap when building chat completion tool payloads.
provider/openaiprovider/responses.go Switches function-tool schema conversion to use schemaToMap when building responses tool payloads.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +311 to 315
schema := tl.Schema()
funcParams, err := schemaToMap(schema)
if err != nil {
return openai.ChatCompletionNewParams{}, fmt.Errorf("failed to convert function tool schema to JSON format: %w", err)
}
Comment on lines +330 to 334
schema := tl.Schema()
funcParams, err := schemaToMap(schema)
if err != nil {
return responses.ResponseNewParams{}, fmt.Errorf("failed to convert schema for function tool %q (type %T) to JSON format: %w", name, schema, err)
}
@github-actions

This comment has been minimized.

@michelle-clayton-work

Copy link
Copy Markdown
Contributor Author

@copilot respond to PR comments

Co-authored-by: michelle-clayton-work <262183035+michelle-clayton-work@users.noreply.github.com>

Copilot AI commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

@copilot respond to PR comments

Fixed in commit Guard schemaToMap against nil schema to preserve original behavior. Added a nil guard at the top of schemaToMap so a nil Schema() return immediately yields (nil, nil) — matching the original break-on-nil behavior in both chat.go and responses.go.

@github-actions

Copy link
Copy Markdown
Contributor

Cross-Repo Consistency Review

Scope: This PR modifies only unexported provider internals (schemaToMap consolidation in openaiprovider). No exported Go types, functions, methods, options, or observable runtime behavior were changed.

Verdict: ✅ No parity issues. This is a Go-internal refactor with no user-visible API or behavioral change, so cross-repo alignment with .NET and Python implementations is unaffected.

Generated by Go API Consistency Review Agent for issue #535 · 29 AIC · ⌖ 11.8 AIC · ⊞ 28.4K ·

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[dotnet-code] Consolidate OpenAI tool schema conversion

3 participants