Run an Agent using CrewAI and Nebius¶
This example shows running an agent using CrewAI agent framework and running LLM on Nebius Token Factory
References and Acknoledgements¶
- CrewAI documentation
- CrewAI + Nebius
- Nebius Token Factory documentation
- This example is contributed from Arindam200/awesome-ai-apps
Pre requisites¶
- Nebius API key. Sign up for free at Token Factory
2 - Install Dependencies¶
In [1]:
import os
if os.getenv("COLAB_RELEASE_TAG"):
print("Running on Colab")
RUNNING_ON_COLAB = True
else:
print("NOT running on Colab")
RUNNING_ON_COLAB = False
NOT running on Colab
In [2]:
if RUNNING_ON_COLAB:
!pip install -q crewai python-dotenv
3 - Load Configuration¶
In [3]:
import os
## Recommended way of getting configuration
if RUNNING_ON_COLAB:
from google.colab import userdata
NEBIUS_API_KEY = userdata.get('NEBIUS_API_KEY')
else:
from dotenv import load_dotenv
load_dotenv()
NEBIUS_API_KEY = os.getenv('NEBIUS_API_KEY')
## quick hack (not recommended) - you can hardcode the config key here
# NEBIUS_API_KEY = "your_key_here"
if NEBIUS_API_KEY:
print ('✅ NEBIUS_API_KEY found')
os.environ['NEBIUS_API_KEY'] = NEBIUS_API_KEY
else:
raise RuntimeError ('❌ NEBIUS_API_KEY NOT found')
✅ NEBIUS_API_KEY found
In [4]:
from crewai import Agent, Task,LLM
import os
from crewai import Crew, Process
llm=LLM(
model="nebius/openai/gpt-oss-20b",
# model="nebius/deepseek-ai/DeepSeek-R1-0528",
api_key=os.getenv("NEBIUS_API_KEY")
)
# Create a researcher agent
## see documentation : https://docs.crewai.com/en/concepts/agents#direct-code-definition
researcher = Agent(
role='Senior Researcher',
goal='Discover groundbreaking technologies',
verbose=True,
llm=llm,
backstory='A curious mind fascinated by cutting-edge innovation and the potential to change the world, you know everything about tech.'
)
# Task for the researcher
research_task = Task(
description='Identify the next big trend in AI',
expected_output='5 paragraphs on the next big AI trend',
agent=researcher # Assigning the task to the researcher
)
# Instantiate your crew
tech_crew = Crew(
agents=[researcher],
tasks=[research_task],
process=Process.sequential # Tasks will be executed one after the other
)
# Begin the task execution
result = tech_crew.kickoff()
╭─────────────────────────────────────────────── 🤖 Agent Started ────────────────────────────────────────────────╮ │ │ │ Agent: Senior Researcher │ │ │ │ Task: Identify the next big trend in AI │ │ │ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
╭───────────────────────────────────────────── ✅ Agent Final Answer ─────────────────────────────────────────────╮ │ │ │ Agent: Senior Researcher │ │ │ │ Final Answer: │ │ The next big trend in AI is the rise of **AI-driven sustainability and climate action**, where artificial │ │ intelligence becomes a foundational tool for addressing global environmental challenges. This trend is fueled │ │ by the urgent need to mitigate climate change, optimize resource use, and create systems that balance │ │ technological progress with ecological preservation. AI is no longer just a niche tool for efficiency; it is │ │ becoming a critical driver for decarbonization, biodiversity conservation, and sustainable development. This │ │ shift reflects a broader societal demand for technologies that align with planetary boundaries, making │ │ sustainability a core component of AI innovation. │ │ │ │ AI’s role in sustainability spans multiple domains, from optimizing energy grids to revolutionizing │ │ agriculture. For instance, machine learning algorithms are being used to predict energy demand patterns, │ │ enabling smarter distribution of renewable energy and reducing waste. In the energy sector, AI-powered │ │ systems can identify inefficiencies in power plants, improve battery storage solutions, and enhance the │ │ integration of solar and wind energy into existing infrastructure. These applications not only cut costs but │ │ also significantly lower carbon footprints, demonstrating how AI can directly contribute to achieving │ │ net-zero goals. The trend is further accelerated by the increasing availability of environmental data, which │ │ AI systems can process and analyze at unprecedented scales. │ │ │ │ Another pivotal aspect of this trend is AI’s capacity to monitor and protect ecosystems. Satellite imagery, │ │ sensor networks, and drone data are being analyzed by AI to track deforestation, ocean acidification, and │ │ wildlife migration patterns in real time. For example, AI models can detect illegal logging or poaching │ │ activities by analyzing behavioral patterns, enabling faster interventions. Additionally, generative AI is │ │ being used to simulate climate scenarios, helping policymakers and scientists understand the long-term │ │ impacts of different mitigation strategies. These capabilities highlight how AI is transforming from a tool │ │ of convenience into a guardian of ecological stability. │ │ │ │ The trend also extends to sustainable manufacturing and supply chains, where AI enables circular economy │ │ practices. By analyzing material flows and optimizing production processes, AI reduces waste and promotes the │ │ reuse of resources. For instance, AI-driven platforms can identify recyclable materials in waste streams or │ │ predict equipment failures to minimize downtime and resource loss. Furthermore, AI is being integrated into │ │ product design to create more energy-efficient and biodegradable solutions. This shift underscores a │ │ fundamental transformation in how industries operate, with sustainability no longer a peripheral concern but │ │ a central design principle. │ │ │ │ Finally, the ethical and collaborative frameworks surrounding AI for sustainability will define its success. │ │ As AI systems become more embedded in environmental decision-making, ensuring transparency, fairness, and │ │ accountability is critical. This includes mitigating biases in climate models, protecting data privacy in │ │ environmental monitoring, and fostering global cooperation to share AI tools and knowledge. The next big │ │ trend in AI is not merely technological but also deeply societal, requiring interdisciplinary collaboration │ │ between technologists, policymakers, and communities to ensure that AI-driven sustainability solutions are │ │ equitable and scalable. This trend signals a paradigm shift in AI’s purpose: from enhancing human │ │ productivity to safeguarding the planet’s future. │ │ │ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
In [5]:
## see raw response
## Look at `token_usage` output
print("=== CREW OUTPUT ===")
print(result.raw)
print("\n=== TOKEN USAGE ===")
print(f"Total tokens: {result.token_usage.total_tokens}")
print(f"Prompt tokens: {result.token_usage.prompt_tokens}")
print(f"Completion tokens: {result.token_usage.completion_tokens}")
print(f"Successful requests: {result.token_usage.successful_requests}")
# result
=== CREW OUTPUT === The next big trend in AI is the rise of **AI-driven sustainability and climate action**, where artificial intelligence becomes a foundational tool for addressing global environmental challenges. This trend is fueled by the urgent need to mitigate climate change, optimize resource use, and create systems that balance technological progress with ecological preservation. AI is no longer just a niche tool for efficiency; it is becoming a critical driver for decarbonization, biodiversity conservation, and sustainable development. This shift reflects a broader societal demand for technologies that align with planetary boundaries, making sustainability a core component of AI innovation. AI’s role in sustainability spans multiple domains, from optimizing energy grids to revolutionizing agriculture. For instance, machine learning algorithms are being used to predict energy demand patterns, enabling smarter distribution of renewable energy and reducing waste. In the energy sector, AI-powered systems can identify inefficiencies in power plants, improve battery storage solutions, and enhance the integration of solar and wind energy into existing infrastructure. These applications not only cut costs but also significantly lower carbon footprints, demonstrating how AI can directly contribute to achieving net-zero goals. The trend is further accelerated by the increasing availability of environmental data, which AI systems can process and analyze at unprecedented scales. Another pivotal aspect of this trend is AI’s capacity to monitor and protect ecosystems. Satellite imagery, sensor networks, and drone data are being analyzed by AI to track deforestation, ocean acidification, and wildlife migration patterns in real time. For example, AI models can detect illegal logging or poaching activities by analyzing behavioral patterns, enabling faster interventions. Additionally, generative AI is being used to simulate climate scenarios, helping policymakers and scientists understand the long-term impacts of different mitigation strategies. These capabilities highlight how AI is transforming from a tool of convenience into a guardian of ecological stability. The trend also extends to sustainable manufacturing and supply chains, where AI enables circular economy practices. By analyzing material flows and optimizing production processes, AI reduces waste and promotes the reuse of resources. For instance, AI-driven platforms can identify recyclable materials in waste streams or predict equipment failures to minimize downtime and resource loss. Furthermore, AI is being integrated into product design to create more energy-efficient and biodegradable solutions. This shift underscores a fundamental transformation in how industries operate, with sustainability no longer a peripheral concern but a central design principle. Finally, the ethical and collaborative frameworks surrounding AI for sustainability will define its success. As AI systems become more embedded in environmental decision-making, ensuring transparency, fairness, and accountability is critical. This includes mitigating biases in climate models, protecting data privacy in environmental monitoring, and fostering global cooperation to share AI tools and knowledge. The next big trend in AI is not merely technological but also deeply societal, requiring interdisciplinary collaboration between technologists, policymakers, and communities to ensure that AI-driven sustainability solutions are equitable and scalable. This trend signals a paradigm shift in AI’s purpose: from enhancing human productivity to safeguarding the planet’s future. === TOKEN USAGE === Total tokens: 1826 Prompt tokens: 187 Completion tokens: 1639 Successful requests: 1
