{"id":8029,"library":"composio-crewai","title":"Composio CrewAI Integration","description":"Composio-crewai is a Python library that integrates Composio's extensive array of tools with CrewAI agents. It allows AI agents to connect to over 250 external services and applications, providing enterprise-grade authentication, full observability, and a streamlined way to empower AI workflows with real-world actions. The current version is 0.11.5, and the project demonstrates a rapid release cadence with frequent updates across the core Composio ecosystem.","status":"active","version":"0.11.5","language":"en","source_language":"en","source_url":"https://github.com/ComposioHQ/composio","tags":["AI","LLM","CrewAI","tools","agents","automation","integrations","MCP"],"install":[{"cmd":"pip install composio composio-crewai crewai crewai-tools[mcp] python-dotenv","lang":"bash","label":"Full Installation"}],"dependencies":[{"reason":"Core Composio SDK for tool management and API interaction.","package":"composio"},{"reason":"The multi-agent framework to which Composio tools are integrated.","package":"crewai","version":">=0.51.0"},{"reason":"Provides MCP (Model Context Protocol) helpers for CrewAI, often used with Composio's MCP server.","package":"crewai-tools","optional":true},{"reason":"Utility for loading environment variables from .env files, commonly used for API keys.","package":"python-dotenv","optional":true}],"imports":[{"symbol":"Composio","correct":"from composio import Composio"},{"note":"This provider adapts Composio tools for CrewAI's native tool format.","symbol":"CrewAIProvider","correct":"from composio_crewai import CrewAIProvider"},{"symbol":"Agent","correct":"from crewai import Agent"},{"symbol":"Task","correct":"from crewai import Task"},{"symbol":"Crew","correct":"from crewai import Crew"},{"note":"Used for Model Context Protocol integration, common in Composio-CrewAI examples.","symbol":"MCPServerHTTP","correct":"from crewai.mcp import MCPServerHTTP"}],"quickstart":{"code":"import os\nfrom crewai import Agent, Task, Crew\nfrom crewai.mcp import MCPServerHTTP\nfrom composio import Composio\nfrom dotenv import load_dotenv\n\nload_dotenv() # Load environment variables from .env file\n\nCOMPOSIO_API_KEY = os.environ.get('COMPOSIO_API_KEY', '')\nCOMPOSIO_USER_ID = os.environ.get('COMPOSIO_USER_ID', '')\nOPENAI_API_KEY = os.environ.get('OPENAI_API_KEY', '')\n\nif not COMPOSIO_API_KEY:\n    raise ValueError(\"COMPOSIO_API_KEY environment variable not set.\")\nif not COMPOSIO_USER_ID:\n    raise ValueError(\"COMPOSIO_USER_ID environment variable not set.\")\nif not OPENAI_API_KEY:\n    raise ValueError(\"OPENAI_API_KEY environment variable not set.\")\n\n# Initialize Composio client and create a session\ncomposio_client = Composio(api_key=COMPOSIO_API_KEY)\n# Specify the toolkits your agent needs access to (e.g., 'gmail', 'github', 'composio')\n# Ensure these toolkits are authenticated in your Composio dashboard.\nsession = composio_client.create(user_id=COMPOSIO_USER_ID, toolkits=['composio'])\n\n# Create an MCPServerHTTP instance from the Composio session\nmcp_server = MCPServerHTTP(\n    url=session.mcp.url,\n    headers=session.mcp.headers,\n)\n\n# Define the agent with Composio MCP tools\nresearcher = Agent(\n    role=\"Research Analyst\",\n    goal=\"Gather and summarize information using available tools.\",\n    backstory=\"An expert at finding and synthesizing information from various sources.\",\n    verbose=True,\n    allow_delegation=False,\n    llm=os.environ.get('OPENAI_MODEL_NAME', 'gpt-4o-mini'), # Use an LLM, e.g., OpenAI's\n    mcps=[mcp_server]\n)\n\n# Define a task that leverages Composio tools (e.g., 'composio' toolkit offers general Composio actions)\ntask = Task(\n    description=\"List all available toolkits connected to Composio and summarize their purpose.\",\n    expected_output=\"A concise list of all connected Composio toolkits and a one-sentence summary for each.\",\n    agent=researcher\n)\n\n# Create and run the Crew\ncrew = Crew(agents=[researcher], tasks=[task], verbose=True)\nresult = crew.kickoff()\n\nprint(\"\\n\\n------------------------\")\nprint(\"Crew Work Results:\")\nprint(result)\n","lang":"python","description":"This quickstart demonstrates how to set up a CrewAI agent with Composio tools using the Model Context Protocol (MCP). It initializes Composio, creates a session for a user, and then exposes Composio's tools to a CrewAI agent via an `MCPServerHTTP` instance. The agent is then given a task to use these tools. Ensure `COMPOSIO_API_KEY`, `COMPOSIO_USER_ID`, and `OPENAI_API_KEY` are set as environment variables. You must also authorize the desired toolkits (e.g., 'gmail', 'github') within your Composio dashboard or via the CLI for them to be available to the agent."},"warnings":[{"fix":"Migrate to the MCP-based integration using `crewai.mcp.MCPServerHTTP` as shown in current quickstart examples. Ensure `crewai-tools[mcp]` is installed.","message":"Composio utilizes the Model Context Protocol (MCP) for tool integration. Older, non-MCP based integration patterns might be deprecated or require a different setup. Always refer to the latest Composio and CrewAI documentation for the recommended integration method.","severity":"breaking","affected_versions":"<0.11.0 (earlier versions may use different patterns)"},{"fix":"After setting `COMPOSIO_API_KEY`, log into your Composio dashboard and connect the specific third-party accounts (e.g., Gmail, GitHub) your agents will use. Alternatively, use `composio add <toolkit>` via the Composio CLI.","message":"Authentication to individual service providers (e.g., Gmail, GitHub, Neon) connected via Composio is separate from authenticating to the Composio platform itself. You need to link your accounts within the Composio dashboard or via the `composio add <toolkit>` CLI command.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure `COMPOSIO_USER_ID` is consistently set and passed to `composio_client.create(user_id=...)`. This ID should ideally be a stable identifier for your user.","message":"The `COMPOSIO_USER_ID` environment variable is crucial for scoping the Composio session and correctly identifying the user for whom tools are being provided. Without it, Composio might not be able to retrieve or manage tools for the session.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always provide an `llm` argument to your `Agent` instances, typically by importing and configuring an LLM from `langchain_openai` (e.g., `ChatOpenAI`) or passing the model name if using OpenAI directly. Ensure the relevant API key (e.g., `OPENAI_API_KEY`) is set.","message":"CrewAI's `Agent` class requires an `llm` parameter. If not explicitly provided, it might default to a non-existent or unsupported LLM, leading to errors. Additionally, using `gpt-4o-mini` or similar models requires `OPENAI_API_KEY` to be set.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Set the `COMPOSIO_API_KEY` environment variable with your Composio API key. For development, create a `.env` file with `COMPOSIO_API_KEY=your_key_here` and use `dotenv.load_dotenv()` in your script.","cause":"The `COMPOSIO_API_KEY` environment variable is missing, which is required for authenticating with the Composio platform.","error":"ValueError: COMPOSIO_API_KEY environment variable not set."},{"fix":"Set the `COMPOSIO_USER_ID` environment variable to a unique identifier for your user in the `.env` file (e.g., `COMPOSIO_USER_ID=my_unique_user_id`).","cause":"The `COMPOSIO_USER_ID` environment variable is missing, which is necessary for creating a user-scoped session with Composio to access tools.","error":"ValueError: COMPOSIO_USER_ID environment variable not set."},{"fix":"Verify that the `toolkits` list passed to `composio_client.create()` corresponds to tools you have authenticated within the Composio platform. Ensure `COMPOSIO_USER_ID` is correctly set and matches the user ID used during toolkit authentication.","cause":"This can happen if: 1) The specified toolkits in `composio_client.create()` are not authenticated in your Composio dashboard, or 2) `COMPOSIO_USER_ID` is incorrect, preventing Composio from associating tools with the session.","error":"No tools found for the agent / Agent cannot use tools."},{"fix":"Install the necessary package: `pip install crewai-tools[mcp]`.","cause":"The `crewai-tools` library, specifically the `mcp` extra, is not installed.","error":"ModuleNotFoundError: No module named 'crewai_tools'"}]}