entities.py 1.7 KB

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