You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

plugin_entities.py 3.1KB

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