{ "cells": [ { "cell_type": "code", "execution_count": null, "id": "c8aef04b", "metadata": {}, "outputs": [], "source": [ "!pip install -U deepeval crewai" ] }, { "cell_type": "code", "execution_count": null, "id": "e5d5faaf", "metadata": {}, "outputs": [], "source": [ "import os\n", "\n", "os.environ[\"OPENAI_API_KEY\"] = \"\"\n", "os.environ[\"CONFIDENT_API_KEY\"] = \"\"" ] }, { "cell_type": "code", "execution_count": null, "id": "f25915e1", "metadata": {}, "outputs": [], "source": [ "from deepeval.integrations.crewai import instrument_crewai\n", "\n", "instrument_crewai()" ] }, { "cell_type": "code", "execution_count": null, "id": "495b42cc", "metadata": {}, "outputs": [], "source": [ "from crewai import Task, Crew, Agent\n", "from crewai.tools import tool" ] }, { "cell_type": "code", "execution_count": null, "id": "32814c27", "metadata": {}, "outputs": [], "source": [ "@tool\n", "def get_weather(city: str) -> str:\n", " \"\"\"Fetch weather data for a given city. Returns temperature and conditions.\"\"\"\n", " weather_data = {\n", " \"New York\": {\n", " \"temperature\": \"72°F\",\n", " \"condition\": \"Partly Cloudy\",\n", " \"humidity\": \"65%\",\n", " },\n", " \"London\": {\n", " \"temperature\": \"60°F\",\n", " \"condition\": \"Rainy\",\n", " \"humidity\": \"80%\",\n", " },\n", " \"Tokyo\": {\n", " \"temperature\": \"75°F\",\n", " \"condition\": \"Sunny\",\n", " \"humidity\": \"55%\",\n", " },\n", " \"Paris\": {\n", " \"temperature\": \"68°F\",\n", " \"condition\": \"Cloudy\",\n", " \"humidity\": \"70%\",\n", " },\n", " \"Sydney\": {\n", " \"temperature\": \"82°F\",\n", " \"condition\": \"Clear\",\n", " \"humidity\": \"50%\",\n", " },\n", " }\n", "\n", " if city in weather_data:\n", " weather = weather_data[city]\n", " return f\"Weather in {city}: {weather['temperature']}, {weather['condition']}, Humidity: {weather['humidity']}\"\n", " else:\n", " return f\"Weather in {city}: 70°F, Clear, Humidity: 60% (default data)\"\n", "\n", "\n", "agent = Agent(\n", " role=\"Weather Reporter\",\n", " goal=\"Provide accurate and helpful weather information to users.\",\n", " backstory=\"An experienced meteorologist who loves helping people plan their day with accurate weather reports.\",\n", " tools=[get_weather],\n", " verbose=True,\n", ")\n", "\n", "task = Task(\n", " description=\"Get the current weather for {city} and provide a helpful summary.\",\n", " expected_output=\"A clear weather report including temperature, conditions, and humidity.\",\n", " agent=agent,\n", ")\n", "\n", "crew = Crew(\n", " agents=[agent],\n", " tasks=[task],\n", ")" ] }, { "cell_type": "code", "execution_count": null, "id": "0bd21c50", "metadata": {}, "outputs": [], "source": [ "result = crew.kickoff({\"city\": \"London\"})" ] }, { "cell_type": "code", "execution_count": null, "id": "51a207f6", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": ".venv", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.12.10" } }, "nbformat": 4, "nbformat_minor": 5 }