您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

plugin_entities.py 3.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import enum
  2. from typing import Any, Optional
  3. from pydantic import BaseModel, ConfigDict, Field, ValidationInfo, field_validator
  4. from core.entities.parameter_entities import CommonParameterType
  5. from core.plugin.entities.parameters import (
  6. PluginParameter,
  7. as_normal_type,
  8. cast_parameter_value,
  9. init_frontend_parameter,
  10. )
  11. from core.tools.entities.common_entities import I18nObject
  12. from core.tools.entities.tool_entities import (
  13. ToolIdentity,
  14. ToolProviderIdentity,
  15. )
  16. class AgentStrategyProviderIdentity(ToolProviderIdentity):
  17. """
  18. Inherits from ToolProviderIdentity, without any additional fields.
  19. """
  20. pass
  21. class AgentStrategyParameter(PluginParameter):
  22. class AgentStrategyParameterType(enum.StrEnum):
  23. """
  24. Keep all the types from PluginParameterType
  25. """
  26. STRING = CommonParameterType.STRING.value
  27. NUMBER = CommonParameterType.NUMBER.value
  28. BOOLEAN = CommonParameterType.BOOLEAN.value
  29. SELECT = CommonParameterType.SELECT.value
  30. SECRET_INPUT = CommonParameterType.SECRET_INPUT.value
  31. FILE = CommonParameterType.FILE.value
  32. FILES = CommonParameterType.FILES.value
  33. APP_SELECTOR = CommonParameterType.APP_SELECTOR.value
  34. MODEL_SELECTOR = CommonParameterType.MODEL_SELECTOR.value
  35. TOOLS_SELECTOR = CommonParameterType.TOOLS_SELECTOR.value
  36. # deprecated, should not use.
  37. SYSTEM_FILES = CommonParameterType.SYSTEM_FILES.value
  38. def as_normal_type(self):
  39. return as_normal_type(self)
  40. def cast_value(self, value: Any):
  41. return cast_parameter_value(self, value)
  42. type: AgentStrategyParameterType = Field(..., description="The type of the parameter")
  43. def init_frontend_parameter(self, value: Any):
  44. return init_frontend_parameter(self, self.type, value)
  45. class AgentStrategyProviderEntity(BaseModel):
  46. identity: AgentStrategyProviderIdentity
  47. plugin_id: Optional[str] = Field(None, description="The id of the plugin")
  48. class AgentStrategyIdentity(ToolIdentity):
  49. """
  50. Inherits from ToolIdentity, without any additional fields.
  51. """
  52. pass
  53. class AgentFeature(enum.StrEnum):
  54. """
  55. Agent Feature, used to describe the features of the agent strategy.
  56. """
  57. HISTORY_MESSAGES = "history-messages"
  58. class AgentStrategyEntity(BaseModel):
  59. identity: AgentStrategyIdentity
  60. parameters: list[AgentStrategyParameter] = Field(default_factory=list)
  61. description: I18nObject = Field(..., description="The description of the agent strategy")
  62. output_schema: Optional[dict] = None
  63. features: Optional[list[AgentFeature]] = None
  64. # pydantic configs
  65. model_config = ConfigDict(protected_namespaces=())
  66. @field_validator("parameters", mode="before")
  67. @classmethod
  68. def set_parameters(cls, v, validation_info: ValidationInfo) -> list[AgentStrategyParameter]:
  69. return v or []
  70. class AgentProviderEntityWithPlugin(AgentStrategyProviderEntity):
  71. strategies: list[AgentStrategyEntity] = Field(default_factory=list)