The agent engineering platform.
Python agentsaiai-agentsanthropicchatgptdeepagentsenterpriseframeworkgeminigenerative-ailangchainlanggraphllmmultiagentopen-sourceopenaipydanticpythonragtypescript
Fix issue with non-list `To` header in GmailSendMessage Tool (#6242)
Jakub Misiło5d149e4d5032
diff --git a/langchain/tools/gmail/send_message.py b/langchain/tools/gmail/send_message.pyindex c8b769794d..6a805b1a25 100644--- a/langchain/tools/gmail/send_message.py+++ b/langchain/tools/gmail/send_message.py@@ -2,7 +2,7 @@import base64from email.mime.multipart import MIMEMultipartfrom email.mime.text import MIMEText-from typing import Any, Dict, List, Optional+from typing import Any, Dict, List, Optional, Unionfrom pydantic import BaseModel, Field@@ -18,7 +18,7 @@ class SendMessageSchema(BaseModel):...,description="The message to send.",)- to: List[str] = Field(+ to: Union[str, List[str]] = Field(...,description="The list of recipients.",)@@ -26,11 +26,11 @@ class SendMessageSchema(BaseModel):...,description="The subject of the message.",)- cc: Optional[List[str]] = Field(+ cc: Optional[Union[str, List[str]]] = Field(None,description="The list of CC recipients.",)- bcc: Optional[List[str]] = Field(+ bcc: Optional[Union[str, List[str]]] = Field(None,description="The list of BCC recipients.",)@@ -45,22 +45,22 @@ class GmailSendMessage(GmailBaseTool):def _prepare_message(self,message: str,- to: List[str],+ to: Union[str, List[str]],subject: str,- cc: Optional[List[str]] = None,- bcc: Optional[List[str]] = None,+ cc: Optional[Union[str, List[str]]] = None,+ bcc: Optional[Union[str, List[str]]] = None,) -> Dict[str, Any]:"""Create a message for an email."""mime_message = MIMEMultipart()mime_message.attach(MIMEText(message, "html"))- mime_message["To"] = ", ".join(to)+ mime_message["To"] = ", ".join(to if isinstance(to, list) else [to])mime_message["Subject"] = subjectif cc is not None:- mime_message["Cc"] = ", ".join(cc)+ mime_message["Cc"] = ", ".join(cc if isinstance(cc, list) else [cc])if bcc is not None:- mime_message["Bcc"] = ", ".join(bcc)+ mime_message["Bcc"] = ", ".join(bcc if isinstance(bcc, list) else [bcc])encoded_message = base64.urlsafe_b64encode(mime_message.as_bytes()).decode()return {"raw": encoded_message}@@ -68,10 +68,10 @@ class GmailSendMessage(GmailBaseTool):def _run(self,message: str,- to: List[str],+ to: Union[str, List[str]],subject: str,- cc: Optional[List[str]] = None,- bcc: Optional[List[str]] = None,+ cc: Optional[Union[str, List[str]]] = None,+ bcc: Optional[Union[str, List[str]]] = None,run_manager: Optional[CallbackManagerForToolRun] = None,) -> str:"""Run the tool."""@@ -90,10 +90,10 @@ class GmailSendMessage(GmailBaseTool):async def _arun(self,message: str,- to: List[str],+ to: Union[str, List[str]],subject: str,- cc: Optional[List[str]] = None,- bcc: Optional[List[str]] = None,+ cc: Optional[Union[str, List[str]]] = None,+ bcc: Optional[Union[str, List[str]]] = None,run_manager: Optional[AsyncCallbackManagerForToolRun] = None,) -> str:"""Run the tool asynchronously."""