Coverage for fastagency/runtimes/ag2/agents/whatsapp.py: 100%
6 statements
« prev ^ index » next coverage.py v7.8.0, created at 2025-04-19 12:16 +0000
« prev ^ index » next coverage.py v7.8.0, created at 2025-04-19 12:16 +0000
1from typing import Any, Union 1bcdaefghi
3from autogen import AssistantAgent, ConversableAgent, LLMConfig 1bcdaefghi
5from ..tools import WhatsAppTool 1bcdaefghi
7WHATSAPP_SYSTEM_MESSAGE = """You are an agent in charge of communication with the WhatsAPP API. 1bcdaefghi
9When sending the message, the Body must use the following format:
11{{
12 "from": "{sender}",
13 "to": "receiverNumber",
14 "messageId": "test-message-randomInt",
15 "content": {{
16 "text": "message"
17 }},
18 "callbackData": "Callback data"
19}}
21"from" number is always the same.
22"""
25class WhatsAppAgent(AssistantAgent): # type: ignore[misc] 1bcdaefghi
26 def __init__( 1bcdaefghi
27 self,
28 *args: Any,
29 name: str,
30 llm_config: LLMConfig,
31 executor: Union[ConversableAgent, list[ConversableAgent]],
32 sender: str,
33 whatsapp_api_key: str,
34 **kwargs: Any,
35 ):
36 """Initialize the WhatsAppAgent.
38 Args:
39 *args (Any): The positional arguments.
40 name (str): The name of the agent.
41 llm_config (dict[str, Any]): The LLM configuration.
42 executor (Union[ConversableAgent, list[ConversableAgent]]): The executor agent(s).
43 sender (str): Number of the sender for WhatsApp API.
44 whatsapp_api_key (str): The WhatsApp API key
45 **kwargs (Any): The keyword arguments.
46 """
47 super().__init__( 1a
48 *args,
49 name=name,
50 system_message=WHATSAPP_SYSTEM_MESSAGE.format(sender=sender),
51 llm_config=llm_config,
52 **kwargs,
53 )
54 self.whatsapp_tool = WhatsAppTool( 1a
55 whatsapp_api_key=whatsapp_api_key,
56 )
58 self.whatsapp_tool.register(caller=self, executor=executor) 1a