entities.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. from enum import Enum
  2. from typing import Any, Optional, Union
  3. from pydantic import BaseModel
  4. from core.tools.entities.tool_entities import ToolProviderType
  5. class AgentToolEntity(BaseModel):
  6. """
  7. Agent Tool Entity.
  8. """
  9. provider_type: ToolProviderType
  10. provider_id: str
  11. tool_name: str
  12. tool_parameters: dict[str, Any] = {}
  13. class AgentPromptEntity(BaseModel):
  14. """
  15. Agent Prompt Entity.
  16. """
  17. first_prompt: str
  18. next_iteration: str
  19. class AgentScratchpadUnit(BaseModel):
  20. """
  21. Agent First Prompt Entity.
  22. """
  23. class Action(BaseModel):
  24. """
  25. Action Entity.
  26. """
  27. action_name: str
  28. action_input: Union[dict, str]
  29. def to_dict(self) -> dict:
  30. """
  31. Convert to dictionary.
  32. """
  33. return {
  34. 'action': self.action_name,
  35. 'action_input': self.action_input,
  36. }
  37. agent_response: Optional[str] = None
  38. thought: Optional[str] = None
  39. action_str: Optional[str] = None
  40. observation: Optional[str] = None
  41. action: Optional[Action] = None
  42. def is_final(self) -> bool:
  43. """
  44. Check if the scratchpad unit is final.
  45. """
  46. return self.action is None or (
  47. 'final' in self.action.action_name.lower() and
  48. 'answer' in self.action.action_name.lower()
  49. )
  50. class AgentEntity(BaseModel):
  51. """
  52. Agent Entity.
  53. """
  54. class Strategy(Enum):
  55. """
  56. Agent Strategy.
  57. """
  58. CHAIN_OF_THOUGHT = 'chain-of-thought'
  59. FUNCTION_CALLING = 'function-calling'
  60. provider: str
  61. model: str
  62. strategy: Strategy
  63. prompt: Optional[AgentPromptEntity] = None
  64. tools: list[AgentToolEntity] = None
  65. max_iteration: int = 5