---
title: "Calendar Agent"
sidebarTitle: "Calendar Agent"
icon: "calendar"
description: "This project is an example which uses Composio to seamlessly convert your to-do lists into Google Calendar events. It automatically schedules tasks with specified labels and times, ensuring your calendar is always up-to-date and organized."
---



<Tab title="Python">
<Card color="#7bee0c" title="Calendar Agent GitHub Repository" icon="github" href="https://www.github.com/ComposioHQ/composio/blob/master/python/examples/quickstarters/calendar_agent/">
  Explore the complete source code for the Calendar Agent project. This repository contains all the necessary files and scripts to set up and run the Calendar Agent using CrewAI and Composio.
</Card>
<Steps>

    <Step title="Install the required packages">
    <CodeGroup>
    ```python Install the required packages
    pip install composio-crewai langchain-openai
    ```
    </CodeGroup>
    Create a .env file and add your OpenAI API Key.

    </Step>

    <Step title="Import base packages">
    Next, we'll import the essential libraries for our project.
    <CodeGroup>
        ```python Python - Import statements
        import os
        from datetime import datetime

        from composio_crewai import App, ComposioToolSet
        from crewai import Agent, Task, Crew
        from dotenv import load_dotenv
        from langchain_openai import ChatOpenAI        
        ```
    </CodeGroup>
    </Step>


    <Step title="Initialise Language Model and Define tools">
    We'll initialize our language model and set up the necessary tools for our agents.
    <CodeGroup>
        ```python Models and Tools
        load_dotenv()

        # Initialize the language model
        llm = ChatOpenAI(model="gpt-4o")

        # Define tools for the agents
        # We are using Google calendar tool from composio to connect to our calendar account.
        composio_toolset = ComposioToolSet()
        tools = composio_toolset.get_tools(apps=[App.GOOGLECALENDAR])

        # Retreive the current date and time
        date = datetime.today().strftime("%Y-%m-%d")
        timezone = datetime.now().astimezone().tzinfo        
        ```
    </CodeGroup>
    </Step>

    <Step title="Setup Todo">
    Define the todo list that we want to convert into calendar events.
    <CodeGroup>
        ```python Python - Todo Setup
        # Setup Todo
        todo = """
            1PM - 3PM -> Code,
            5PM - 7PM -> Meeting,
            9AM - 12AM -> Learn something,
            8PM - 10PM -> Game
        """        
        ```
    </CodeGroup>
    </Step>

    <Step title="Create and Execute Agent">
    Finally, we'll define and execute the agent responsible for creating Google Calendar events based on the todo list.
    <CodeGroup>
        ```python Run agent
        # Create and Execute Agent.
        def run_crew():
        calendar_agent = Agent(
            role="Google Calendar Agent",
            goal="""You take action on Google Calendar using Google Calendar APIs""",
            backstory="""You are an AI agent responsible for taking actions on Google Calendar on users' behalf. 
            You need to take action on Calendar using Google Calendar APIs. Use correct tools to run APIs from the given tool-set.""",
            verbose=True,
            tools=tools,
            llm=llm,
        )
        task = Task(
            description=f"Book slots according to {todo}. Label them with the work provided to be done in that time period. Schedule it for today. Today's date is {date} (it's in YYYY-MM-DD format) and make the timezone be {timezone}.",
            agent=calendar_agent,
            expected_output="if free slot is found",
        )
        crew = Crew(agents=[calendar_agent], tasks=[task])
        result = crew.kickoff()
        print(result) 
        ```
    </CodeGroup>
    </Step>

</Steps>
</Tab>


## Complete Code 
    <CodeGroup>
    ```python Python Final Code
    # Import base packages
    import os
    from datetime import datetime

    from composio_crewai import App, ComposioToolSet
    from crewai import Agent, Task
    from dotenv import load_dotenv
    from langchain_openai import ChatOpenAI

    # Load environment variables
    load_dotenv()

    # Initialize the language model
    llm = ChatOpenAI(model="gpt-4o")

    # Define tools for the agents
    # We are using Google calendar tool from composio to connect to our calendar account.
    composio_toolset = ComposioToolSet()
    tools = composio_toolset.get_tools(apps=[App.GOOGLECALENDAR])

    # Retreive the current date and time
    date = datetime.today().strftime("%Y-%m-%d")
    timezone = datetime.now().astimezone().tzinfo

    # Setup Todo
    todo = """
        1PM - 3PM -> Code,
        5PM - 7PM -> Meeting,
        9AM - 12AM -> Learn something,
        8PM - 10PM -> Game
    """

    # Create and Execute Agent.
    def run_crew():
        calendar_agent = Agent(
            role="Google Calendar Agent",
            goal="""You take action on Google Calendar using Google Calendar APIs""",
            backstory="""You are an AI agent responsible for taking actions on Google Calendar on users' behalf.
            You need to take action on Calendar using Google Calendar APIs. Use correct tools to run APIs from the given tool-set.""",
            verbose=True,
            tools=tools,
            llm=llm,
        )
        task = Task(
            description=f"Book slots according to {todo}. Label them with the work provided to be done in that time period. Schedule it for today. Today's date is {date} (it's in YYYY-MM-DD format) and make the timezone be {timezone}.",
            agent=calendar_agent,
            expected_output="if free slot is found",
        )
        crew = Crew(agents=[calendar_agent], tasks=[task])
        result = crew.kickoff()
        print(result)
        return result

    run_crew()    
    ```

    </CodeGroup>




