You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
from langchain_community.agent_toolkits import GmailToolkit
from langchain_community.tools.gmail.create_draft import GmailCreateDraft
from langchain_community.tools.gmail.get_thread import GmailGetThread
from pydantic import BaseModel, Field
from crewai.tools import BaseTool
from typing import Type
class GetThreadSchema(BaseModel):
"""Input for GetMessageTool."""
# From https://support.google.com/mail/answer/7190?hl=en
thread_id: str = Field(
...,
description="The thread ID.",
)
class CreateDraftSchema(BaseModel):
"""Input for CreateDraftTool."""
email: str = Field(
...,
description="The recipient email address.",
)
subject: str = Field(
...,
description="The subject of the email.",
)
message: str = Field(
...,
description="The body of the email.",
)
class CreateDraftTool(BaseTool):
"""Tool that creates an email draft."""
name: str = "create_draft"
description: str = (
"Useful to create an email draft."
" The input should be a JSON object with 'email', 'subject', and 'message' fields."
)
args_schema: Type[CreateDraftSchema] = CreateDraftSchema
draft_creator: GmailCreateDraft = Field(default_factory=GmailCreateDraft(api_resource=GmailToolkit().api_resource))
def _run(self, query)-> str:
"""Execute the draft creation and return results"""
try:
result = self.draft_creator.run(query)
return f"Draft created: {result}"
except Exception as e:
return f"Error creating draft: {str(e)}"
class GetGmailThreadTool(BaseTool):
"""Tool that gets a thread by ID from Gmail."""
name: str = "get_gmail_thread"
description: str = (
"Use this tool to search for email messages."
" The input must be a valid Gmail query."
" The output is a JSON list of messages."
)
args_schema: Type[GetThreadSchema] = GetThreadSchema
thread_getter: GmailGetThread = Field(default_factory=GmailGetThread(api_resource=GmailToolkit().api_resource))
def _run(self, tool_input: GetThreadSchema) -> str:
"""Execute the thread getter query and return results"""
try:
return self.thread_getter.run(tool_input)
except Exception as e:
return f"Error performing search: {str(e)}"
Whenever I try to run the agent I get this error:
Traceback (most recent call last):
File "/Users/zaffau/Documents/github/email_auto_responder_flow/main.py", line 3, in <module>
app = Workflow().app
^^^^^^^^^^
File "/Users/zaffau/Documents/github/email_auto_responder_flow/src/graph.py", line 17, in __init__
workflow.add_node("draft_response", EmailFilterCrew().kickoff)
^^^^^^^^^^^^^^^^^
File "/Users/zaffau/Documents/github/email_auto_responder_flow/src/crew/crew.py", line 10, in __init__
self.action_agent = agents.email_action_agent()
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/zaffau/Documents/github/email_auto_responder_flow/src/crew/agents.py", line 36, in email_action_agent
GetGmailThreadTool(),
^^^^^^^^^^^^^^^^^^^^
File "/Users/zaffau/Library/Caches/pypoetry/virtualenvs/email-auto-responder-flow-I_mk_BaB-py3.11/lib/python3.11/site-packages/pydantic/main.py", line 214, in __init__
validated_self = self.__pydantic_validator__.validate_python(data, self_instance=self)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/zaffau/Library/Caches/pypoetry/virtualenvs/email-auto-responder-flow-I_mk_BaB-py3.11/lib/python3.11/site-packages/langchain_core/_api/deprecation.py", line 181, in warning_emitting_wrapper
return wrapped(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: BaseTool.__call__() missing 1 required positional argument: 'tool_input'
I cant figure out or find other issues like this.
The text was updated successfully, but these errors were encountered:
umaidmz
changed the title
Creating new custom tool from langchain gives "tool_input" missing error
Creating custom tool from langchain gives "tool_input" missing error
Jan 30, 2025
I created tools like this:
Whenever I try to run the agent I get this error:
I cant figure out or find other issues like this.
The text was updated successfully, but these errors were encountered: