entities.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 "answer" in self.action.action_name.lower()
  48. )
  49. class AgentEntity(BaseModel):
  50. """
  51. Agent Entity.
  52. """
  53. class Strategy(Enum):
  54. """
  55. Agent Strategy.
  56. """
  57. CHAIN_OF_THOUGHT = "chain-of-thought"
  58. FUNCTION_CALLING = "function-calling"
  59. provider: str
  60. model: str
  61. strategy: Strategy
  62. prompt: Optional[AgentPromptEntity] = None
  63. tools: Optional[list[AgentToolEntity]] = None
  64. max_iteration: int = 5