Skip to content

Conversation

@waleedlatif1
Copy link
Collaborator

Summary

add backwards compatibility for agent messages array

* fix(agent): add backwards compat for agent messages array

* add tests
@vercel
Copy link

vercel bot commented Nov 20, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
docs Skipped Skipped Nov 20, 2025 7:18pm

@waleedlatif1 waleedlatif1 merged commit 842ef27 into main Nov 20, 2025
9 checks passed
@greptile-apps
Copy link
Contributor

greptile-apps bot commented Nov 20, 2025

Greptile Overview

Greptile Summary

This PR adds backwards compatibility for legacy agent block fields during workflow serialization. When PR #2023 introduced the new messages array format for agent blocks (replacing systemPrompt, userPrompt, and memories), it included migration logic during deserialization to convert old formats to new. However, when serializing old workflows that still have these legacy fields in their subBlocks, the serializer was filtering them out because they're no longer in the current agent block configuration.

Key Changes:

  • Modified extractParams() in apps/sim/serializer/index.ts:441-442 to preserve legacy agent fields (systemPrompt, userPrompt, memories) during serialization, even when they're not in the current block config
  • Added comprehensive test coverage to validate the backwards compatibility behavior
  • Ensures old exported workflows can be re-imported and re-exported without data loss

Technical Implementation:
The fix adds an isLegacyAgentField check that bypasses the normal subBlockConfig validation for these three specific fields when serializing agent blocks. This allows workflows exported before the messages array migration to maintain their original field structure until they're deserialized (at which point the existing migrateAgentParamsToMessages() function converts them to the new format).

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk - it's a focused backwards compatibility fix with proper test coverage
  • The implementation is minimal, well-tested, and directly addresses a specific backwards compatibility issue. The change is conservative (only adds a bypass for 3 specific legacy fields), doesn't alter existing behavior for new workflows, and includes a comprehensive test case that validates the exact scenario. The logic is clear and the impact is limited to serialization of legacy agent blocks.
  • No files require special attention

Important Files Changed

File Analysis

Filename Score Overview
apps/sim/serializer/index.ts 5/5 Added backwards compatibility check for legacy agent fields (systemPrompt, userPrompt, memories) during serialization to preserve old workflow exports
apps/sim/serializer/index.test.ts 5/5 Added comprehensive test case validating that legacy agent block fields are preserved during serialization for backwards compatibility

Sequence Diagram

sequenceDiagram
    participant User
    participant Serializer
    participant extractParams
    participant BlockConfig
    participant subBlocks

    User->>Serializer: serializeWorkflow(blocks)
    Serializer->>Serializer: serializeBlock(legacyAgentBlock)
    Serializer->>extractParams: extractParams(block)
    
    extractParams->>BlockConfig: getBlock('agent')
    BlockConfig-->>extractParams: blockConfig (with current subBlocks)
    
    Note over extractParams: Check each subBlock in block.subBlocks
    
    extractParams->>extractParams: Check if 'systemPrompt' exists
    alt systemPrompt is in subBlocks
        extractParams->>extractParams: isLegacyAgentField = true
        Note over extractParams: Include systemPrompt even if not in current config
        extractParams->>extractParams: params.systemPrompt = value
    end
    
    extractParams->>extractParams: Check if 'userPrompt' exists
    alt userPrompt is in subBlocks
        extractParams->>extractParams: isLegacyAgentField = true
        extractParams->>extractParams: params.userPrompt = value
    end
    
    extractParams->>extractParams: Check if 'memories' exists
    alt memories is in subBlocks
        extractParams->>extractParams: isLegacyAgentField = true
        extractParams->>extractParams: params.memories = value
    end
    
    extractParams-->>Serializer: params (with legacy fields preserved)
    Serializer-->>User: serialized workflow (legacy fields intact)
Loading

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.

2 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

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