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

plugin_entities.py 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. ANY = CommonParameterType.ANY.value
  37. # deprecated, should not use.
  38. SYSTEM_FILES = CommonParameterType.SYSTEM_FILES.value
  39. def as_normal_type(self):
  40. return as_normal_type(self)
  41. def cast_value(self, value: Any):
  42. return cast_parameter_value(self, value)
  43. type: AgentStrategyParameterType = Field(..., description="The type of the parameter")
  44. help: Optional[I18nObject] = None
  45. def init_frontend_parameter(self, value: Any):
  46. return init_frontend_parameter(self, self.type, value)
  47. class AgentStrategyProviderEntity(BaseModel):
  48. identity: AgentStrategyProviderIdentity
  49. plugin_id: Optional[str] = Field(None, description="The id of the plugin")
  50. class AgentStrategyIdentity(ToolIdentity):
  51. """
  52. Inherits from ToolIdentity, without any additional fields.
  53. """
  54. pass
  55. class AgentFeature(enum.StrEnum):
  56. """
  57. Agent Feature, used to describe the features of the agent strategy.
  58. """
  59. HISTORY_MESSAGES = "history-messages"
  60. class AgentStrategyEntity(BaseModel):
  61. identity: AgentStrategyIdentity
  62. parameters: list[AgentStrategyParameter] = Field(default_factory=list)
  63. description: I18nObject = Field(..., description="The description of the agent strategy")
  64. output_schema: Optional[dict] = None
  65. features: Optional[list[AgentFeature]] = None
  66. meta_version: Optional[str] = None
  67. # pydantic configs
  68. model_config = ConfigDict(protected_namespaces=())
  69. @field_validator("parameters", mode="before")
  70. @classmethod
  71. def set_parameters(cls, v, validation_info: ValidationInfo) -> list[AgentStrategyParameter]:
  72. return v or []
  73. class AgentProviderEntityWithPlugin(AgentStrategyProviderEntity):
  74. strategies: list[AgentStrategyEntity] = Field(default_factory=list)