1

Install packages and Connect tools

You need to connect your GitHub and Trello accounts so agents can use them. Run the following commands on your terminal:

pip install composio-crewai crewai flask

# Connect your Github and Trello so agents can use it.

composio add github

composio add trello
2

Add and Configure Triggers

Set up a server using ngrok and configure triggers for GitHub commit events.

# Add triggers and set a callback url
# Create a server using ngrok

ngrok http 2000

# Set the callback URL (replace the example URL with your actual ngrok URL):
# Replace your ngrok url

composio triggers callbacks set "https://<ngrok-url>/webhook"

# Enable the GitHub commit event trigger

composio triggers enable github_commit_event
3

Import base packages

Import the necessary libraries in your Python script

from flask import Flask, request
from crewai import Agent, Task
from composio_crewai import ComposioToolSet, App, Action
from langchain_openai import ChatOpenAI
4

Initialise Agents using CrewAI

Initialize the agents and tools:

llm = ChatOpenAI(openai_api_key=openai_api_key, model="gpt-4")
composio_toolset = ComposioToolSet()
tools = composio_toolset.get_actions(actions=[Action.TRELLO_CARD_CREATE_AND_UPDATE])
crewai_agent = Agent(
        role="Github-Trello TODO Agent",
        goal="""Take 'trello_create_trello_card' action on TRELLO via TRELLO APIs based on the Github patch.""",
        backstory="""You are an AI Agent with access to Github and Trello and wants to keep the Github Code TODOs, commit messages and TRELLO Board in Sync. Action to be performed: trello_create_trello_card""",
        verbose=True,
        tools=tools,
        llm=llm,
    )
5

Start a web server

Create a Flask web server to handle incoming webhooks: Please replace the your_trello_list_id_for_todos and your_trello_list_id_for_done with your actual Trello list IDs. To get the Trello list ID:

  • Go to your Trello Board in your browser.
  • Add β€œ.json” at the end of the URL in the address bar and press Enter.
  • In the JSON output, find the list with the name you are looking for and extract its β€œlist.id” property.
app = Flask(__name__)

@app.route('/webhook', methods=['POST'])
def webhook():
    t_id = "your_trello_list_id_for_todos"  # Replace with your Trello list ID for TODOs
    d_id = "your_trello_list_id_for_done"   # Replace with your Trello list ID for done tasks

    task1 = Task(
        description=f"""Given the following Github patch: {request.json}, create a TRELLO card (trello_create_trello_card) for the TODOs from code comments in the patch. TRELLO list (id:{t_id}).
        Please read the patch carefully and create cards for the new TODOs only, avoid removed/old TODOs. Card name should reflect the todo comment present in code""",
        expected_output="A TRELLO card created for the commit",
        agent=crewai_agent,
    )
    task1.execute()

    task2 = Task(
        description=f"""Given the following Github patch: {request.json}, create a TRELLO card (trello_create_trello_card) for the Commit Message in the patch. TRELLO list (id:{d_id})
        to add card. Create only if the commit message indicates that a task is completed.""",
        expected_output="A TRELLO card created for the commit",
        agent=crewai_agent,
    )
    task2.execute()

    return 'Payload received and processed', 200

if __name__ == '__main__':
    app.run(port=2000, debug=True)

Putting it All Together

# Import necessary libraries
from flask import Flask, request
from crewai import Agent, Task
from composio_crewai import ComposioToolSet, App, Action
from langchain_openai import ChatOpenAI

# Initialize agents using CrewAI
openai_api_key = "your_openai_api_key"  # Replace with your actual OpenAI API key
llm = ChatOpenAI(openai_api_key=openai_api_key, model="gpt-4")
composio_toolset = ComposioToolSet()
tools = composio_toolset.get_actions(actions=[Action.TRELLO_CARD_CREATE_AND_UPDATE])
crewai_agent = Agent(
    role="Github-Trello TODO Agent",
    goal="""Take 'trello_create_trello_card' action on TRELLO via TRELLO APIs based on the Github patch.""",
    backstory="""You are an AI Agent with access to Github and Trello and want to keep the Github Code TODOs, commit messages, and TRELLO Board in Sync. Action to be performed: trello_create_trello_card""",
    verbose=True,
    tools=tools,
    llm=llm,
)

# Start a web server
app = Flask(__name__)

@app.route('/webhook', methods=['POST'])
def webhook():
    t_id = "your_trello_list_id_for_todos"  # Replace with your Trello list ID for TODOs
    d_id = "your_trello_list_id_for_done"   # Replace with your Trello list ID for done tasks

    task1 = Task(
        description=f"""Given the following Github patch: {request.json}, create a TRELLO card (trello_create_trello_card) for the TODOs from code comments in the patch. TRELLO list (id:{t_id}).
        Please read the patch carefully and create cards for the new TODOs only, avoid removed/old TODOs. Card name should reflect the todo comment present in code""",
        expected_output="A TRELLO card created for the commit",
        agent=crewai_agent,
    )
    task1.execute()

    task2 = Task(
        description=f"""Given the following Github patch: {request.json}, create a TRELLO card (trello_create_trello_card) for the Commit Message in the patch. TRELLO list (id:{d_id})
        to add card. Create only if the commit message indicates that a task is completed.""",
        expected_output="A TRELLO card created for the commit",
        agent=crewai_agent,
    )
    task2.execute()

    return 'Payload received and processed', 200

if __name__ == '__main__':
    app.run(port=2000, debug=True)

Information

Was this page helpful?