Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

next
py 37 lines 1.04 KB
Raw
1 import os
2
3 from crewai import Agent, Crew, Task
4 from crewai.mcp import MCPServerHTTP
5
6 from composio import Composio
7
8 composio = Composio()
9 session = composio.create(
10 # A user with a connected Gmail account (raises KeyError when unset)
11 user_id=os.environ["COMPOSIO_EXAMPLES_USER_ID"],
12 # mcp=True surfaces session.mcp on the returned type
13 mcp=True,
14 )
15
16 agent = Agent(
17 role="Gmail agent",
18 goal="helps with gmail related queries",
19 backstory="You are a helpful assistant that can use the tools provided to you.",
20 mcps=[
21 MCPServerHTTP(
22 url=session.mcp.url,
23 headers=session.mcp.headers, # type: ignore[arg-type] # headers is typed Dict[str, Optional[str]]; the SDK always populates it with str values
24 )
25 ],
26 )
27
28 # Define task
29 task = Task(
30 description=("Find the last email and summarize it."),
31 expected_output="A summary of the last email including sender, subject, and key points.",
32 agent=agent,
33 )
34
35 my_crew = Crew(agents=[agent], tasks=[task])
36 result = my_crew.kickoff()
37 print(result)