feat: migrate to AI SDK v5.0.0-beta Agent abstraction#579
Merged
Conversation
- Update researcher and generateRelatedQuestions to use new Agent class - Implement sequential agent execution pattern - Fix message array handling in API route - Update related questions component to handle both array and object formats - Improve related questions prompts to generate unique follow-up questions - Add proper message merging for saving complete responses BREAKING CHANGE: Requires AI SDK v5.0.0-beta or higher 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR migrates the chat system from the traditional streamText API to the new Agent abstraction introduced in AI SDK v5.0.0-beta.8, implementing a sequential execution pattern for research and related questions generation.
- Migration from streamText API to Agent-based architecture with proper tool configuration
- Implementation of sequential agent execution where research runs first, followed by related questions generation
- Enhanced message handling to support AI SDK v5 message formats and improved error handling
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| lib/streaming/create-chat-stream-response.ts | Implements sequential agent execution pattern with proper message merging and error handling |
| lib/agents/researcher.ts | Converts researcher function to return Agent instance with updated tool configuration |
| lib/agents/generate-related-questions.ts | Migrates to Agent pattern with improved prompt to avoid question repetition |
| components/related-questions.tsx | Adds backward compatibility for both array and object data formats |
| app/api/chat/route.ts | Updates API route to handle AI SDK v5 messages array format |
Comments suppressed due to low confidence (1)
lib/agents/researcher.ts:60
- The tool name has been changed from 'ask_question' to 'askQuestion'. Ensure this naming change is consistent with tool usage elsewhere in the codebase, as the snake_case to camelCase change could break existing references.
askQuestion: askQuestionTool
|
|
||
| return streamText(config) | ||
| : undefined, | ||
| stopWhen: searchMode ? stepCountIs(10) : stepCountIs(1) |
There was a problem hiding this comment.
[nitpick] The magic number 10 for maximum steps should be extracted to a constant for better maintainability. Consider defining MAX_SEARCH_STEPS = 10 to make this configurable and self-documenting.
Suggested change
| stopWhen: searchMode ? stepCountIs(10) : stepCountIs(1) | |
| stopWhen: searchMode ? stepCountIs(MAX_SEARCH_STEPS) : stepCountIs(1) |
- Add await keyword to ensure proper error handling and completion tracking - Prevents potential race conditions when saving messages on error 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
- Capture research message during initial stream merge - Remove duplicate researchResult.toUIMessageStream() call - Prevents potential stream consumption errors 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
byte-rose
pushed a commit
to Bastsec/morphic
that referenced
this pull request
Sep 23, 2025
…ction feat: migrate to AI SDK v5.0.0-beta Agent abstraction
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.
Summary
Changes
Agent Migration:
Sequential Execution:
Bug Fixes:
Improvements:
Test Plan
Breaking Changes
🤖 Generated with Claude Code