CrewAI is an open-source framework designed to coordinate autonomous AI agents and construct advanced, multi-step workflows.
1.1 Usage
Method 1: LLM Class Configuration (Recommended)
from crewai import Agent, LLM
llm = LLM(
model="your-model-name",
api_key="your-rygen-api-key",
base_url="https://api.rygen.io/v1",
temperature=0.6,
max_tokens=4000
)
agent = Agent(
role='AI Specialist',
goal='Assist with user queries effectively',
backstory="An intelligent assistant powered by a custom LLM setup.",
llm=llm
)Method 2: Environment Variables
import os
os.environ["OPENAI_API_KEY"] = "your-rygen-api-key"
os.environ["OPENAI_API_BASE"] = "https://api.rygen.io/v1"
os.environ["OPENAI_MODEL_NAME"] = "your-model-name"
from crewai import Agent
# Uses default LLM configuration from environment
agent = Agent(
role='AI Specialist',
goal='Provide helpful responses',
backstory="An assistant configured via environment variables."
)Method 3: Portkey Integration
Refer to the official documentation for setting up Portkey with your provider.
1.2 Multiple Agents with Different LLMs
from crewai import Agent, LLM, Task, Crew
# First LLM instance
llm1 = LLM(
model="your-model-name",
api_key="key-1",
base_url="https://api.rygen.io/v1"
)
# Second LLM instance
llm2 = LLM(
model="your-model-name",
api_key="key-2",
base_url="https://api.rygen.io/v1"
)
# Agents using different LLM configurations
agent1 = Agent(role='Expert A', goal='Handle task A', llm=llm1)
agent2 = Agent(role='Expert B', goal='Handle task B', llm=llm2)
