swarmauri / swarmauri-sdk

https://swarmauri.com
Apache License 2.0
10 stars 23 forks source link

[Refactoring Request]: In Support of Plugins and Deserialization of Polymorphisms #330

Open cobycloud opened 1 week ago

cobycloud commented 1 week ago

Affected Component

This will impact all components

Motivation

Requirements

  1. Modularity
  2. Extendibility
  3. Scalability
  4. Enable third party plugins
  5. Serialization and deserialization of objects with nested objects

Potential Refactoring Approach

Suggestions

  1. To explore a shift from a Mixin architecture to a Delegate Architecture
  2. To shift from dynamic SubclassUnion typing to Static Typing - leveraging __all__ in __init__.py
  3. Plugin Registry
  4. Serialization and Deserialization methods
  5. Using Delegate Factories for Deserialization

Additional Context (optional)

No response

Affected Areas

Priority

Critical

cobycloud commented 1 week ago

Logs from v0.4.1.x/tools build

SubclassUnion is failing because the tools are called within the function, meaning the tools are local instead of global.

Additionally, I'm unsure why we are seeing tools.<tool-name>.[ToolBase | AdditionTool] appearing, I'm not certain how AdditionTool is becoming included as such.

In general, this represents a failure to the current approach and a difficulty to overcome.

 FAILED tests/toolkits/AccessibilityToolkit_test.py::test_serialization - pydantic_core._pydantic_core.ValidationError: 10 validation errors for AccessibilityToolkit
tools.AutomatedReadabilityIndexTool.ToolBase.type
  Input should be 'ToolBase' [type=literal_error, input_value='AutomatedReadabilityIndexTool', input_type=str]
    For further information visit https://errors.pydantic.dev/2.8/v/literal_error
tools.AutomatedReadabilityIndexTool.AdditionTool.type
  Input should be 'AdditionTool' [type=literal_error, input_value='AutomatedReadabilityIndexTool', input_type=str]
    For further information visit https://errors.pydantic.dev/2.8/v/literal_error
tools.ColemanLiauIndexTool.ToolBase.type
  Input should be 'ToolBase' [type=literal_error, input_value='ColemanLiauIndexTool', input_type=str]
    For further information visit https://errors.pydantic.dev/2.8/v/literal_error
tools.ColemanLiauIndexTool.AdditionTool.type
  Input should be 'AdditionTool' [type=literal_error, input_value='ColemanLiauIndexTool', input_type=str]
    For further information visit https://errors.pydantic.dev/2.8/v/literal_error
tools.FleschKincaidTool.ToolBase.type
  Input should be 'ToolBase' [type=literal_error, input_value='FleschKincaidTool', input_type=str]
    For further information visit https://errors.pydantic.dev/2.8/v/literal_error
tools.FleschKincaidTool.AdditionTool.type
  Input should be 'AdditionTool' [type=literal_error, input_value='FleschKincaidTool', input_type=str]
    For further information visit https://errors.pydantic.dev/2.8/v/literal_error
tools.FleschReadingEaseTool.ToolBase.type
  Input should be 'ToolBase' [type=literal_error, input_value='FleschReadingEaseTool', input_type=str]
    For further information visit https://errors.pydantic.dev/2.8/v/literal_error
tools.FleschReadingEaseTool.AdditionTool.type
  Input should be 'AdditionTool' [type=literal_error, input_value='FleschReadingEaseTool', input_type=str]
    For further information visit https://errors.pydantic.dev/2.8/v/literal_error
tools.GunningFogTool.ToolBase.type
  Input should be 'ToolBase' [type=literal_error, input_value='GunningFogTool', input_type=str]
    For further information visit https://errors.pydantic.dev/2.8/v/literal_error
tools.GunningFogTool.AdditionTool.type
  Input should be 'AdditionTool' [type=literal_error, input_value='GunningFogTool', input_type=str]
    For further information visit https://errors.pydantic.dev/2.8/v/literal_error
cobycloud commented 1 week ago

Also see the issue below, where deserialization fails as the AdditionTool was not added to the list of

image

cobycloud commented 1 week ago

let's state our requirements here: