2024-12-09 23:02:11 +08:00
|
|
|
from abc import ABC, abstractmethod
|
2024-12-24 18:38:34 +08:00
|
|
|
from collections.abc import Generator, Sequence
|
|
|
|
from typing import Any, Optional
|
2024-12-09 23:02:11 +08:00
|
|
|
|
|
|
|
from core.agent.entities import AgentInvokeMessage
|
2024-12-12 18:27:31 +08:00
|
|
|
from core.agent.plugin_entities import AgentStrategyParameter
|
2024-12-09 23:02:11 +08:00
|
|
|
|
|
|
|
|
|
|
|
class BaseAgentStrategy(ABC):
|
|
|
|
"""
|
|
|
|
Agent Strategy
|
|
|
|
"""
|
|
|
|
|
|
|
|
def invoke(
|
|
|
|
self,
|
|
|
|
params: dict[str, Any],
|
|
|
|
user_id: str,
|
|
|
|
conversation_id: Optional[str] = None,
|
|
|
|
app_id: Optional[str] = None,
|
|
|
|
message_id: Optional[str] = None,
|
|
|
|
) -> Generator[AgentInvokeMessage, None, None]:
|
|
|
|
"""
|
|
|
|
Invoke the agent strategy.
|
|
|
|
"""
|
|
|
|
yield from self._invoke(params, user_id, conversation_id, app_id, message_id)
|
|
|
|
|
2024-12-12 18:27:31 +08:00
|
|
|
def get_parameters(self) -> Sequence[AgentStrategyParameter]:
|
2024-12-09 23:02:11 +08:00
|
|
|
"""
|
|
|
|
Get the parameters for the agent strategy.
|
|
|
|
"""
|
|
|
|
return []
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def _invoke(
|
|
|
|
self,
|
|
|
|
params: dict[str, Any],
|
|
|
|
user_id: str,
|
|
|
|
conversation_id: Optional[str] = None,
|
|
|
|
app_id: Optional[str] = None,
|
|
|
|
message_id: Optional[str] = None,
|
|
|
|
) -> Generator[AgentInvokeMessage, None, None]:
|
|
|
|
pass
|