Add stopAfterToolCalls option for OpenAI-compatible workflows#107
Closed
ajason wants to merge 9 commits intomattt:mainfrom
Closed
Add stopAfterToolCalls option for OpenAI-compatible workflows#107ajason wants to merge 9 commits intomattt:mainfrom
ajason wants to merge 9 commits intomattt:mainfrom
Conversation
DeepSeek API expects tool message content to be a string, not an array. Changed from .blocks() to .text() for tool messages in: - respondWithChatCompletions method - respondWithResponses method - toOpenAIMessages method (for transcript injection)
DeepSeek API expects tool message content to be a string, not an array. Changed from .blocks() to .text() for tool messages. Also ensures structured tool outputs (JSON) are correctly serialized to JSON strings instead of using debug descriptions.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
stopAfterToolCallstoggle inOpenAILanguageModel.CustomGenerationOptions.Motivation
In production environments, tool execution is often managed by an "external orchestrator" (e.g., dispatching calls to independent workers, invoking internal services, or implementing permission and auditing logic). The current default behavior automatically executes tools immediately after the model generates tool calls. This is unsuitable for systems that require:
The
stopAfterToolCallsflag allows the client to receive the tool calls without triggering automatic execution, handing control over the execution timing to the upper-level orchestrator.Use Cases / Scenarios
Behavior
stopAfterToolCalls == trueand the model generates tool calls: the generation process halts, returning the tool calls to the caller without execution.Testing
swift test --filter OpenAICustomOptionsTests