base.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. from abc import ABC, abstractmethod
  2. from typing import Any, Generator, Optional, Sequence
  3. from core.agent.entities import AgentInvokeMessage
  4. from core.agent.plugin_entities import AgentParameter
  5. class BaseAgentStrategy(ABC):
  6. """
  7. Agent Strategy
  8. """
  9. def invoke(
  10. self,
  11. params: dict[str, Any],
  12. user_id: str,
  13. conversation_id: Optional[str] = None,
  14. app_id: Optional[str] = None,
  15. message_id: Optional[str] = None,
  16. ) -> Generator[AgentInvokeMessage, None, None]:
  17. """
  18. Invoke the agent strategy.
  19. """
  20. yield from self._invoke(params, user_id, conversation_id, app_id, message_id)
  21. def get_parameters(self) -> Sequence[AgentParameter]:
  22. """
  23. Get the parameters for the agent strategy.
  24. """
  25. return []
  26. @abstractmethod
  27. def _invoke(
  28. self,
  29. params: dict[str, Any],
  30. user_id: str,
  31. conversation_id: Optional[str] = None,
  32. app_id: Optional[str] = None,
  33. message_id: Optional[str] = None,
  34. ) -> Generator[AgentInvokeMessage, None, None]:
  35. pass