Skip to content

refactor: clean up LLM generate methods and improve type safety #5865

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

wardpeet
Copy link
Contributor

Summary

  • Refactored Agent class to consolidate LLM generate and stream methods
  • Improved type safety across LLM interfaces and agent methods
  • Fixed type annotations in tests and removed console.log statements
  • Moved LLM-specific types to proper modules for better organization

Changes Made

  • Agent class refactoring: Consolidated duplicate code between generate() and stream() methods by extracting common logic into prepareLLMOptions()
  • Type improvements: Enhanced type safety for LLM operations with proper generic constraints and cleaner type definitions
  • Code organization: Moved LLM callback types to base.types.ts for better modularity
  • Test fixes: Added proper type annotations to test variables
  • Cleanup: Removed debugging console.log statements

Test plan

  • All existing tests continue to pass
  • Type checking passes without errors
  • Agent generate and stream methods work correctly
  • LLM interfaces maintain backward compatibility

🤖 Generated with Claude Code

Copy link

codesandbox bot commented Jul 11, 2025

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

Copy link

changeset-bot bot commented Jul 11, 2025

🦋 Changeset detected

Latest commit: 2af1f3a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 11 packages
Name Type
@mastra/server Patch
@mastra/core Patch
@mastra/deployer Patch
@mastra/client-js Patch
@mastra/dane Patch
@mastra/longmemeval Patch
mastra Patch
@mastra/deployer-cloudflare Patch
@mastra/deployer-netlify Patch
@mastra/deployer-vercel Patch
@mastra/playground-ui Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

vercel bot commented Jul 11, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
assistant-ui ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 17, 2025 9:29am
mastra-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 17, 2025 9:29am
openapi-spec-writer ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 17, 2025 9:29am

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

Major refactoring of LLM-related code to improve type safety and reduce duplication, focusing on code organization and type definitions.

  • Created new packages/core/src/llm/model/base.types.ts to centralize LLM-related type definitions and improve type organization
  • Consolidated duplicate code in Agent class by extracting prepareLLMOptions() from generate() and stream() methods
  • Enhanced type safety by adding proper generic constraints and improving callback type definitions in packages/core/src/llm/model/base.ts
  • Warning: Found potentially unintended console.log statement in packages/core/src/agent/index.ts that should be removed
  • Fixed type annotations in test files to properly handle MockLanguageModelV1 instances

13 files reviewed, 6 comments
Edit PR Review Bot Settings | Greptile

@wardpeet
Copy link
Contributor Author

@greptile-apps

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

Comprehensive implementation of agent working memory and UI improvements across the platform.

  • Added working memory management UI with new agent-working-memory-context.tsx context provider and hook-based state management
  • Implemented working memory API endpoints in server and deployer packages with proper validation and error handling
  • Replaced legacy Cohere client with direct API calls in CohereRelevanceScorer, improving error handling and reducing dependencies
  • Enhanced model settings UI with new provider-specific configuration options and JSON editor in agent-advanced-settings.tsx
  • Added comprehensive icon set for different LLM providers including Anthropic, Azure, OpenAI, Groq and others with consistent styling

145 files reviewed, 6 comments
Edit PR Review Bot Settings | Greptile

Copy link
Contributor

github-actions bot commented Jul 14, 2025

Braintrust eval report

No experiments to report

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.

1 participant