crewAIInc / crewAI-examples

2.6k stars 965 forks source link

CrewAI + LangGraph : Does not work #144

Closed rahul-proximity closed 1 month ago

rahul-proximity commented 1 month ago

Hey, I tried running this example. It doesn't seem to work. No emails are fetched despite setting up the gmail client correctly.

Even the sample code from the Gmail client works fine:

https://developers.google.com/gmail/api/quickstart/python#configure_the_sample

the seach here comes out to be an empty list every time:

    def check_email(self, state):
        print("# Checking for new emails")
        search = GmailSearch(api_resource=self.gmail.api_resource)
        emails = search('after:newer_than:1d')
        checked_emails = state['checked_emails_ids'] if state['checked_emails_ids'] else []
        thread = []
        new_emails = []
        for email in emails:
            if (email['id'] not in checked_emails) and (email['threadId'] not in thread) and ( os.environ['MY_EMAIL'] not in email['sender']):
                thread.append(email['threadId'])
                new_emails.append(
                    {
                        "id": email['id'],
                        "threadId": email['threadId'],
                        "snippet": email['snippet'],
                        "sender": email["sender"]
                    }
                )
        checked_emails.extend([email['id'] for email in emails])
        return {
            **state,
            "emails": new_emails,
            "checked_emails_ids": checked_emails
        }

@joaomdmoura

chinmayajha commented 1 month ago

It is basic debugging, try printing emails on line 4. Try replacing the search arguement with search("in:inbox") to widen the search and see if it's really the program causing the problem.

rahul-proximity commented 1 month ago

@chinmayajha This did not work out. Used the email client directly. Here's what I did for your reference.

import os
import time

from google.auth.transport.requests import Request
from google.oauth2.credentials import Credentials
from google_auth_oauthlib.flow import InstalledAppFlow
from googleapiclient.discovery import build
from googleapiclient.errors import HttpError

SCOPES = ["https://www.googleapis.com/auth/gmail.readonly"]

class Nodes():
    def __init__(self):
        self.creds = self.authenticate()
        self.service = build("gmail", "v1", credentials=self.creds)

    def authenticate(self):
        creds = None
        if os.path.exists("token.json"):
            creds = Credentials.from_authorized_user_file("token.json", SCOPES)
        if not creds or not creds.valid:
            if creds and creds.expired and creds.refresh_token:
                creds.refresh(Request())
            else:
                flow = InstalledAppFlow.from_client_secrets_file("credentials.json", SCOPES)
                creds = flow.run_local_server(port=0)
            with open("token.json", "w") as token:
                token.write(creds.to_json())
        return creds

Changed the check_email then to use the same.

hoangle-opti commented 3 days ago

Hi @rahul-proximity , could you provide more detail how to fix it? I cannot run this example too