Refactor TextGateway and related classes to support SingleTurnResponse for LLM interactions#1
Open
vinitkadam03 wants to merge 14 commits into0.xfrom
Open
Refactor TextGateway and related classes to support SingleTurnResponse for LLM interactions#1vinitkadam03 wants to merge 14 commits into0.xfrom
vinitkadam03 wants to merge 14 commits into0.xfrom
Conversation
Owner
vinitkadam03
commented
Apr 3, 2026
- Updated TextGateway interface to replace TextResponse with SingleTurnResponse for generateText and streamText methods.
- Implemented SingleTurnResponse in FakeTextGateway and OpenAiGateway, ensuring proper handling of tool calls and responses.
- Introduced TextOrchestrator to manage multi-step tool loops and streamline response generation.
- Removed deprecated onToolInvocation methods and adjusted tool invocation handling.
- Enhanced parsing logic in OpenAi and Prism gateways to accommodate new response structure.
- Added tests to validate new functionality and ensure backward compatibility.
46b1fc1 to
c6cb2d6
Compare
724e6d8 to
2eb0604
Compare
…e for LLM interactions - Updated TextGateway interface to replace TextResponse with SingleTurnResponse for generateText and streamText methods. - Implemented SingleTurnResponse in FakeTextGateway and OpenAiGateway, ensuring proper handling of tool calls and responses. - Introduced TextOrchestrator to manage multi-step tool loops and streamline response generation. - Removed deprecated onToolInvocation methods and adjusted tool invocation handling. - Enhanced parsing logic in OpenAi and Prism gateways to accommodate new response structure. - Added tests to validate new functionality and ensure backward compatibility.
…port - Added `previousResponseId` parameter to `generateText` and `streamText` methods in TextGateway and its implementations. - Introduced `buildContinuationBody` method in BuildsTextRequests to create lightweight continuation requests. - Updated TextOrchestrator to manage `previousResponseId` for multi-step interactions. - Enhanced response handling in OpenAiGateway and other classes to accommodate new stateful continuation logic. - Added serialization for tool result outputs to streamline API requests. - Updated SingleTurnResponse and StreamEnd to include response ID for better tracking of interactions.
- Simplified the tool name comparison by removing the method_exists check for 'name', directly using class_basename for matching. - This change enhances code readability and maintains functionality.
… stateful continuation support - Updated variable usage to enhance clarity and maintainability by replacing direct calls with a single variable for last results. - Adjusted the buildFinalResponse method to utilize the last result for structured data handling. - Removed the raw data parameter from SingleTurnResponse to simplify the response structure.
…d streamline response handling - Updated generateText and streamText methods to include previousResponseId parameter for stateful interactions. - Replaced TextResponse with SingleTurnResponse in response parsing and handling across relevant classes. - Simplified response processing logic by removing unnecessary parameters and enhancing clarity. - Adjusted tool invocation handling to improve maintainability and performance in streaming responses.
- Introduced handling for server tool blocks to improve event emission during text streaming. - Updated tool call filtering to exclude synthetic structured output, ensuring accurate tool call tracking. - Adjusted finish reason logic to correctly identify stop conditions based on real tool calls. - Enhanced response parsing to accommodate structured data extraction when applicable.
- Removed unused parameters `tools` and `schema` from `streamText` and `processTextStream` methods to simplify method signatures and improve clarity. - Updated relevant gateway implementations to reflect these changes, enhancing maintainability.
- Introduced handling for reasoning text and signatures in text streaming and response parsing. - Updated `processTextStream` to capture and emit reasoning details during tool calls. - Enhanced `mapAssistantMessage` to include reasoning text and signature in assistant messages. - Added methods to extract and attach reasoning data to tool calls for improved replay accuracy.
…nse and streamline response handling - Updated generateText and streamText methods to include previousResponseId parameter for stateful interactions. - Replaced TextResponse with SingleTurnResponse in response parsing and handling across relevant classes. - Simplified method signatures by removing unused parameters and enhancing clarity. - Enhanced text streaming processes to improve event emission and tool call tracking. - Adjusted response processing logic to accommodate new stateful continuation support.
…d continuation support - Introduced `buildContinuationBody` method to streamline the creation of continuation requests using `previous_response_id`. - Enhanced `mergeSharedResponsesRequestOptions` to consolidate shared options for both initial and continuation requests. - Updated `generateText` and `streamText` methods to utilize continuation logic, ensuring consistent request structure. - Added tests to validate the correct handling of tool choices and options in follow-up requests.
…o support provider execution status
StepLoop pairs with the existing Step DTO it produces and reads more concretely than "Orchestrator". SingleTurnResponse is an internal contract between gateways and the step loop, so it belongs under `Laravel\Ai\Gateway` alongside its consumer rather than under `Laravel\Ai\Responses` where user-facing response types live. No behavior change.
…tract These gateways landed on 0.x with the pre-refactor shape (per-gateway tool loop, recursive continueWithToolResults, TextResponse return type). Convert them to implement the new TextGateway contract: one LLM call per invocation, returning SingleTurnResponse; the multi-step loop is handled by StepLoop in the provider trait. Behavioral quirks preserved: - Ollama: force FinishReason::ToolCalls when tool_calls are populated regardless of done_reason, since real Ollama responses can report "stop" alongside tool calls. - OpenRouter: treat finish_reason "error" with inline error payload as a stream Error event.
2eb0604 to
78ec5d3
Compare
… and tool call behavior
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.