Build multi-agent AI crews with Composio and CrewAI using MCP
This example demonstrates how to use Composio with CrewAI to create collaborative AI agent teams that can execute complex tasks using MCP (Model Context Protocol).
from crewai import Agent, Crew, Taskfrom crewai.mcp import MCPServerHTTPfrom composio import Composio# Initialize Composio and create a sessioncomposio = Composio()session = composio.create( user_id="user_123",)# Create an agent with Composio MCP serveragent = Agent( role="Gmail agent", goal="helps with gmail related queries", backstory="You are a helpful assistant that can use the tools provided to you.", mcps=[ MCPServerHTTP( url=session.mcp.url, headers=session.mcp.headers, ) ],)# Define tasktask = Task( description=("Find the last email and summarize it."), expected_output="A summary of the last email including sender, subject, and key points.", agent=agent,)# Create and run the crewmy_crew = Crew(agents=[agent], tasks=[task])result = my_crew.kickoff()print(result)
research_task = Task( description="Research the latest AI trends in email automation", expected_output="A detailed report on AI email automation trends", agent=researcher_agent,)write_task = Task( description="Write an email summary based on the research", expected_output="A professional email summarizing the findings", agent=writer_agent, context=[research_task], # Uses output from research_task)send_task = Task( description="Send the email to the team", expected_output="Confirmation that email was sent", agent=email_agent, context=[write_task], # Uses output from write_task)crew = Crew( agents=[researcher_agent, writer_agent, email_agent], tasks=[research_task, write_task, send_task], process=Process.sequential,)