Skip to content

refactor(ai): rename agent response interfaces#1466

Merged
hwbrzzl merged 1 commit into
masterfrom
bowen/#918-3
May 8, 2026
Merged

refactor(ai): rename agent response interfaces#1466
hwbrzzl merged 1 commit into
masterfrom
bowen/#918-3

Conversation

@hwbrzzl

@hwbrzzl hwbrzzl commented May 7, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Rename the AI response contracts to AgentResponse and StreamableAgentResponse so custom AI integrations no longer rely on ambiguous generic type names.
  • Update AI provider, conversation, middleware, and stream interfaces to use the explicit response types consistently.
  • Regenerate the AI mocks so extension and package tests use the renamed contracts.

Closes goravel/goravel#918

Why

The AI package exposed generic Response and StreamableResponse interfaces even though the framework already has several unrelated Response contracts for HTTP, testing, and auth. Renaming the AI contracts makes custom providers and middleware easier to read and implement because the type names now describe the AI domain directly.

func (r *WeatherProvider) Prompt(ctx context.Context, prompt ai.AgentPrompt) (ai.AgentResponse, error) {
	return frameworkai.NewTextResponse("sunny", nil, nil), nil
}

func (r *WeatherProvider) Stream(ctx context.Context, prompt ai.AgentPrompt) (ai.StreamableAgentResponse, error) {
	return frameworkai.NewStreamableResponse(ctx, func(streamCtx context.Context, emit func(ai.StreamEvent) error) (ai.AgentResponse, error) {
		if err := emit(ai.StreamEvent{Type: ai.StreamEventTypeTextDelta, Delta: "sun"}); err != nil {
			return nil, err
		}

		return frameworkai.NewTextResponse("sunny", nil, nil), nil
	}), nil
}

This keeps the public AI API aligned across the framework, custom providers, and generated mocks, while removing the need to mentally disambiguate which Response interface a provider or middleware hook is expected to return.

// Before: generic response names overlapped with other framework contracts.
func (r *WeatherProvider) Prompt(ctx context.Context, prompt ai.AgentPrompt) (ai.Response, error) {
	return frameworkai.NewTextResponse("sunny", nil, nil), nil
}

// After: the AI contract names are explicit at each extension point.
func (r *WeatherProvider) Prompt(ctx context.Context, prompt ai.AgentPrompt) (ai.AgentResponse, error) {
	return frameworkai.NewTextResponse("sunny", nil, nil), nil
}

Disambiguate the AI contracts from the framework's other Response interfaces so custom providers, middleware, and stream handlers use explicit type names.
Copilot AI review requested due to automatic review settings May 7, 2026 09:33
@hwbrzzl
hwbrzzl requested a review from a team as a code owner May 7, 2026 09:33
@codecov

codecov Bot commented May 7, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.10345% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 69.19%. Comparing base (9b628f1) to head (b4a09b3).

Files with missing lines Patch % Lines
ai/response.go 0.00% 2 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1466   +/-   ##
=======================================
  Coverage   69.19%   69.19%           
=======================================
  Files         370      370           
  Lines       29338    29338           
=======================================
  Hits        20300    20300           
  Misses       8106     8106           
  Partials      932      932           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR renames the AI response contracts from the generic Response / StreamableResponse to the more explicit AgentResponse / StreamableAgentResponse, and updates the framework AI implementation plus generated mocks to use the new contract names consistently.

Changes:

  • Renamed AI response contracts to AgentResponse and StreamableAgentResponse and updated provider/conversation/middleware signatures accordingly.
  • Updated core AI implementations (text response + streamable response + middleware wrapper) to implement the renamed contracts.
  • Regenerated AI-related mocks and updated AI/OpenAI/unit tests to use the new mock types and contract names.

Reviewed changes

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

Show a summary per file
File Description
mocks/ai/StreamableResponse.go Removed old generated mock for deprecated StreamableResponse.
mocks/ai/StreamableAgentResponse.go Added regenerated mock for StreamableAgentResponse.
mocks/ai/Response.go Removed old generated mock for deprecated Response.
mocks/ai/AgentResponse.go Added regenerated mock for AgentResponse.
mocks/ai/Provider.go Updated provider mock to return AgentResponse / StreamableAgentResponse.
mocks/ai/Next.go Updated Next mock to return AgentResponse.
mocks/ai/Middleware.go Updated middleware mock to return AgentResponse.
mocks/ai/Conversation.go Updated conversation mock to return AgentResponse / StreamableAgentResponse.
contracts/ai/stream.go Removed the old StreamableResponse contract from the streaming contract file.
contracts/ai/response.go Renamed ResponseAgentResponse and introduced StreamableAgentResponse contract.
contracts/ai/provider.go Updated provider interface to use renamed response contracts.
contracts/ai/middleware.go Updated middleware Next and Handle signatures to use AgentResponse.
contracts/ai/image.go Moved ImageStorer contract here (still within contracts/ai).
contracts/ai/ai.go Updated conversation interface to use renamed response contracts.
ai/streamable_response.go Updated stream implementation to implement StreamableAgentResponse and use AgentResponse in callbacks/runner.
ai/streamable_response_test.go Updated stream tests to use AgentResponse / StreamableAgentResponse types.
ai/response.go Updated NewTextResponse and Then to use AgentResponse.
ai/provider_test.go Updated provider test stub signatures to the renamed contracts.
ai/option_test.go Updated option middleware test stubs to return AgentResponse.
ai/openai/provider.go Updated OpenAI provider to return renamed response contracts (prompt + streaming).
ai/openai/provider_test.go Updated OpenAI stream test callback type to AgentResponse.
ai/middleware_response.go Updated middleware response wrapper to implement AgentResponse.
ai/conversation.go Updated conversation prompt/stream and middleware pipeline to use renamed response contracts.
ai/conversation_test.go Updated conversation tests/stubs/mocks to AgentResponse / StreamableAgentResponse.
ai/application_test.go Updated application tests and stubs to use AgentResponse / StreamableAgentResponse.

@hwbrzzl
hwbrzzl merged commit 950dc14 into master May 8, 2026
26 of 27 checks passed
@hwbrzzl
hwbrzzl deleted the bowen/#918-3 branch May 8, 2026 00:10
LinboLen added a commit to LinboLen/framework that referenced this pull request May 11, 2026
* origin/master:
  feat(ai): add audio generation support (goravel#1467)
  chore: Update non-major dependencies (goravel#1468)
  refactor(ai): rename agent response interfaces (goravel#1466)
  feat(ai): add image storage helpers (goravel#1465)
  chore: Update non-major dependencies (goravel#1464)
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.

[Feature] AI SDK Phase 4: Multi-Modal (Attachments, Image, and Audio)

2 participants