from composio import Composiofrom composio_langchain import LangchainProvider# Initialize Composio with LangChain providercomposio = Composio(provider=LangchainProvider())# Get tools from specific toolkits# You can specify one or more toolkitstools = composio.tools.get( user_id="default", toolkits=["GITHUB"])print(f"Loaded {len(tools)} tools from GitHub toolkit")
# Get tools for a specific user# This user must have authenticated their accounts firsttools = composio.tools.get( user_id="user_123", toolkits=["GITHUB"])
from composio import Composiocomposio = Composio(api_key="your_api_key")# Subscribe to trigger eventssubscription = composio.triggers.subscribe()# Define event handler@subscription.handle(trigger_id="your_trigger_id")def handle_github_commit(data): print(f"New commit detected: {data}") # Process the event with your agent # ... invoke your agent with the task# Note: For production, use webhooks instead
from fastapi import FastAPI, Requestimport jsonapp = FastAPI()@app.post("/webhook")async def webhook_handler(request: Request): # Get the webhook payload payload = await request.json() print("Received trigger event:") print(json.dumps(payload, indent=2)) # Process the event with your agent if payload.get("triggerSlug") == "GITHUB_COMMIT_EVENT": commit_data = payload.get("payload") # ... invoke your agent with commit_data return {"status": "success"}
from composio import Composiocomposio = Composio()# Get authentication URL for a userauth_connection = composio.integrations.create( user_id="user_123", integration="github")print(f"Authenticate at: {auth_connection.redirect_url}")# After authentication, the user's connected account will be available# and tools will work with their credentials
# Each user authenticates their own accountstools_user_1 = composio.tools.get(user_id="user_1", toolkits=["GITHUB"])tools_user_2 = composio.tools.get(user_id="user_2", toolkits=["GITHUB"])# Tools will use the respective user's credentials# User 1's agent will act on User 1's GitHub accountagent_1 = create_agent(llm, tools_user_1)# User 2's agent will act on User 2's GitHub accountagent_2 = create_agent(llm, tools_user_2)
from pydantic import BaseModel, Fieldfrom composio import Composiocomposio = Composio()class AddTwoNumbersInput(BaseModel): a: int = Field(description="The first number to add") b: int = Field(description="The second number to add")# Function name will be used as the tool slug@composio.tools.custom_tooldef add_two_numbers(request: AddTwoNumbersInput) -> int: """Add two numbers.""" return request.a + request.b# Use with your agenttools = composio.tools.get(user_id="default", toolkits=["GITHUB"])tools.append(add_two_numbers)
# Get tools with specific permissionstools = composio.tools.get( user_id="default", toolkits=["GITHUB"], # Limit to read-only operations permissions=["read"])