Skip to content

fix: workflow with separate steps example#6583

Merged
abhiaiyer91 merged 2 commits intomastra-ai:mainfrom
shubhamV123:fix/workflow-with-separate-steps-example
Aug 5, 2025
Merged

fix: workflow with separate steps example#6583
abhiaiyer91 merged 2 commits intomastra-ai:mainfrom
shubhamV123:fix/workflow-with-separate-steps-example

Conversation

@shubhamV123
Copy link
Copy Markdown
Contributor

Description

🎯 Problem

  • The workflow example was using the old Mastra API (new Step, new Workflow)

✅ Solution

  • API Migration: Updated from legacy API to current Mastra workflow API
  • Logic Fix: Modified the workflow to support both even and odd results in step manner (previous one directly uses initial input in third step, make first and second step of no use)

🔄 API Changes

Before (Legacy API):

const stepOne = new Step({...})
const myWorkflow = new Workflow({...})

After (Current API):

const stepOne = createStep({...})
const myWorkflow = createWorkflow({...})

📊 Results

  • API Compatibility: Uses current Mastra workflow API
  • Type Safety: Proper TypeScript schemas and validation
  • Flexible Logic: Supports both even and odd inputs
  • Better UX: Users can now test both scenarios

🧪 Testing

  • Tested with even inputs (2, 4, 6) → isEven: true
  • Tested with odd inputs (1, 3, 5) → isEven: false
  • Verified API compatibility with current Mastra version

📝 Files Changed

  • examples/workflow-with-separate-steps/src/mastra/workflows/index.ts
  • examples/workflow-with-separate-steps/src/index.ts

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Code refactoring
  • Performance improvement
  • Test update

Checklist

  • I have made corresponding changes to the documentation (if applicable)
  • I have added tests that prove my fix is effective or that my feature works

- Modified stepTwo to remove +1 increment, allowing both even and odd inputs to produce different results
- Updated stepOne to track original input parity with isOriginalOdd boolean
- Changed stepTwo logic to conditionally increment based on original input parity
- Now workflow can return both even and odd results based on user input:
  - Even inputs → isEven: true
  - Odd inputs → isEven: false
- Fixed mathematical formula from 6x+3 (always odd) to 6x (even when x is even)
@codesandbox
Copy link
Copy Markdown

codesandbox Bot commented Aug 5, 2025

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Aug 5, 2025

⚠️ No Changeset found

Latest commit: 4ba7997

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

Copy link
Copy Markdown
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.

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@vercel
Copy link
Copy Markdown

vercel Bot commented Aug 5, 2025

@shubhamV123 is attempting to deploy a commit to the Mastra Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Copy Markdown
Member

@abhiaiyer91 abhiaiyer91 left a comment

Choose a reason for hiding this comment

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

Thank you!

@abhiaiyer91 abhiaiyer91 merged commit c18c0aa into mastra-ai:main Aug 5, 2025
10 of 20 checks passed
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.

2 participants