CrewAI
Installation
Section titled “Installation”pip install crewai requestsBasic tool definition
Section titled “Basic tool definition”import osimport requestsfrom crewai.tools import BaseToolfrom pydantic import BaseModel, Field
class EmailVerifyInput(BaseModel): email: str = Field(description="The email address to verify")
class VerifyEmailTool(BaseTool): name: str = "verify_email" description: str = ( "Verify if an email address is real and deliverable. " "Returns valid status, confidence score, and whether " "the address is disposable or a role address." ) args_schema: type[BaseModel] = EmailVerifyInput
def _run(self, email: str) -> dict: response = requests.post( "https://api.truval.dev/v1/email/verify", headers={ "Authorization": f"Bearer {os.environ['TRUVAL_API_KEY']}", "Content-Type": "application/json", }, json={"email": email}, ) return response.json()Using with a CrewAI agent
Section titled “Using with a CrewAI agent”from crewai import Agent, Task, Crew
verify_tool = VerifyEmailTool()
email_validator = Agent( role="Email Validator", goal="Verify email addresses are real and deliverable", backstory="You validate email addresses before they are used in outreach campaigns.", tools=[verify_tool], verbose=True,)
task = Task( description="Verify whether user@example.com is a valid deliverable email address.", expected_output="A summary of the verification result including valid status and confidence score.", agent=email_validator,)
crew = Crew(agents=[email_validator], tasks=[task])result = crew.kickoff()Environment variables
Section titled “Environment variables”export TRUVAL_API_KEY=sk_live_...Get your API key at dash.truval.dev.