Skip to main content
Gravix Layer integrates with CrewAI to enable multi-agent workflows backed by our inference endpoints. This page shows how to connect agents and orchestrate agent interactions using Gravix Layer’s OpenAI-compatible API.

What You’ll Learn

  • Connect CrewAI agents to Gravix Layer’s API
  • Use OpenAI-compatible endpoints for agent communication
  • Example: Multi-agent workflow for summarization and analysis

1. Install Required Packages

pip install crewai openai python-dotenv

2. Configure Your API Key

Add your API key to a .env file:
GRAVIXLAYER_API_KEY=your_api_key_here

3. Example: Multi-Agent Workflow

from openai import OpenAI
import os
from dotenv import load_dotenv

load_dotenv()
api_key = os.environ.get("GRAVIXLAYER_API_KEY")

llm = OpenAI(
	api_key=api_key,
	base_url="https://api.gravixlayer.com/v1/inference"
)

agents = [
	{"role": "Summarizer", "task": "Summarize this: AI is transforming industries..."},
	{"role": "Industry Analyst", "task": "List three industries most impacted by AI."},
	{"role": "Healthcare Researcher", "task": "Suggest a research question about AI in healthcare."}
]

responses = []

for agent in agents:
	response = llm.chat.completions.create(
		model="meta-llama/llama-3.1-8b-instruct",
		messages=[
			{"role": "system", "content": f"You are a helpful assistant with the role: {agent['role']}"},
			{"role": "user", "content": agent["task"]}
		]
	)
	responses.append((agent["role"], response.choices[0].message.content))

for i, (role, r) in enumerate(responses):
	print(f"Agent {i+1} ({role}) response: {r}\n")
Expected Output:
Agent 1 (Summarizer) response: ...
Agent 2 (Industry Analyst) response: ...
Agent 3 (Healthcare Researcher) response: ...

Tips:
  • Assign clear roles and tasks to each agent for best results.
  • Use the system prompt to guide agent behavior.
For more details, see the CrewAI documentation.
I