From 9e3f8319a655c0d9cae9d93fd8c33be51a467c68 Mon Sep 17 00:00:00 2001 From: Lance Martin Date: Wed, 11 Dec 2024 11:09:53 -0800 Subject: [PATCH] Add report example --- cookbook/report_maistro.ipynb | 252 +++++++++++++++------------------- 1 file changed, 109 insertions(+), 143 deletions(-) diff --git a/cookbook/report_maistro.ipynb b/cookbook/report_maistro.ipynb index 43a0131..6a2d836 100644 --- a/cookbook/report_maistro.ipynb +++ b/cookbook/report_maistro.ipynb @@ -25,7 +25,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 1, "metadata": {}, "outputs": [ { @@ -33,8 +33,18 @@ "output_type": "stream", "text": [ "NVDA tool models:\n", - "[Model(id='meta/llama-3.1-8b-instruct', model_type='chat', client='ChatNVIDIA', endpoint=None, aliases=None, supports_tools=True, supports_structured_output=True, base_model=None), Model(id='meta/llama-3.1-70b-instruct', model_type='chat', client='ChatNVIDIA', endpoint=None, aliases=None, supports_tools=True, supports_structured_output=True, base_model=None), Model(id='meta/llama-3.1-405b-instruct', model_type='chat', client='ChatNVIDIA', endpoint=None, aliases=None, supports_tools=True, supports_structured_output=True, base_model=None), Model(id='mistralai/mistral-large-2-instruct', model_type='chat', client='ChatNVIDIA', endpoint=None, aliases=None, supports_tools=True, supports_structured_output=True, base_model=None), Model(id='nv-mistralai/mistral-nemo-12b-instruct', model_type='chat', client='ChatNVIDIA', endpoint=None, aliases=None, supports_tools=True, supports_structured_output=True, base_model=None), Model(id='meta/llama-3.2-3b-instruct', model_type='chat', client='ChatNVIDIA', endpoint=None, aliases=None, supports_tools=True, supports_structured_output=True, base_model=None)]\n" + "[Model(id='mistralai/mistral-large-2-instruct', model_type='chat', client='ChatNVIDIA', endpoint=None, aliases=None, supports_tools=True, supports_structured_output=True, base_model=None), Model(id='meta/llama-3.1-8b-instruct', model_type='chat', client='ChatNVIDIA', endpoint=None, aliases=None, supports_tools=True, supports_structured_output=True, base_model=None), Model(id='meta/llama-3.1-70b-instruct', model_type='chat', client='ChatNVIDIA', endpoint=None, aliases=None, supports_tools=True, supports_structured_output=True, base_model=None), Model(id='nv-mistralai/mistral-nemo-12b-instruct', model_type='chat', client='ChatNVIDIA', endpoint=None, aliases=None, supports_tools=True, supports_structured_output=True, base_model=None), Model(id='meta/llama-3.2-3b-instruct', model_type='chat', client='ChatNVIDIA', endpoint=None, aliases=None, supports_tools=True, supports_structured_output=True, base_model=None), Model(id='meta/llama-3.1-405b-instruct', model_type='chat', client='ChatNVIDIA', endpoint=None, aliases=None, supports_tools=True, supports_structured_output=True, base_model=None)]\n" ] + }, + { + "data": { + "text/plain": [ + "[Model(id='meta/llama-3.1-70b-instruct', model_type='chat', client='ChatNVIDIA', endpoint=None, aliases=None, supports_tools=True, supports_structured_output=True, base_model='meta/llama-3.1-70b-instruct')]" + ] + }, + "execution_count": 1, + "metadata": {}, + "output_type": "execute_result" } ], "source": [ @@ -52,7 +62,9 @@ "print(tool_models)\n", "model_id = \"meta/llama-3.1-8b-instruct\"\n", "model_id = \"meta/llama-3.1-70b-instruct\"\n", - "llm = ChatNVIDIA(model=model_id, temperature=0)" + "llm = ChatNVIDIA(model=model_id, temperature=0)\n", + "llm = ChatNVIDIA(base_url=\"https://nim-pc8kmx5ae.brevlab.com/v1\", model=\"meta/llama-3.1-70b-instruct\", temperature=0)\n", + "llm.available_models" ] }, { @@ -73,7 +85,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ @@ -95,10 +107,16 @@ }, { "cell_type": "code", - "execution_count": 473, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ + "import os, getpass\n", + "\n", + "def _set_env(var: str):\n", + " if not os.environ.get(var):\n", + " os.environ[var] = getpass.getpass(f\"{var}: \")\n", + " \n", "_set_env(\"LANGCHAIN_API_KEY\")\n", "os.environ[\"LANGCHAIN_TRACING_V2\"] = \"true\"\n", "os.environ[\"LANGCHAIN_PROJECT\"] = \"report-mAIstro\"" @@ -115,12 +133,27 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "import asyncio\n", "from langsmith import traceable\n", + "from pydantic import BaseModel, Field\n", + "\n", + "class Section(BaseModel):\n", + " name: str = Field(\n", + " description=\"Name for this section of the report.\",\n", + " )\n", + " description: str = Field(\n", + " description=\"Brief overview of the main topics and concepts to be covered in this section.\",\n", + " )\n", + " research: bool = Field(\n", + " description=\"Whether to perform web research for this section of the report.\"\n", + " )\n", + " content: str = Field(\n", + " description=\"The content of the section.\"\n", + " ) \n", "\n", "def deduplicate_and_format_sources(search_response, max_tokens_per_source, include_raw_content=True):\n", " \"\"\"\n", @@ -284,27 +317,13 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "from typing_extensions import TypedDict\n", "from typing import Annotated, List, Optional, Literal\n", - "from pydantic import BaseModel, Field\n", - "\n", - "class Section(BaseModel):\n", - " name: str = Field(\n", - " description=\"Name for this section of the report.\",\n", - " )\n", - " description: str = Field(\n", - " description=\"Brief overview of the main topics and concepts to be covered in this section.\",\n", - " )\n", - " research: bool = Field(\n", - " description=\"Whether to perform web research for this section of the report.\"\n", - " )\n", - " content: str = Field(\n", - " description=\"The content of the section.\"\n", - " ) \n", + " \n", "class Sections(BaseModel):\n", " sections: List[Section] = Field(\n", " description=\"Sections of the report.\",\n", @@ -328,7 +347,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 8, "metadata": {}, "outputs": [], "source": [ @@ -355,7 +374,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 9, "metadata": {}, "outputs": [], "source": [ @@ -448,7 +467,7 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 10, "metadata": {}, "outputs": [], "source": [ @@ -536,7 +555,7 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 11, "metadata": {}, "outputs": [], "source": [ @@ -563,7 +582,7 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 12, "metadata": {}, "outputs": [ { @@ -773,7 +792,7 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 13, "metadata": {}, "outputs": [], "source": [ @@ -783,7 +802,7 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 14, "metadata": {}, "outputs": [ { @@ -936,7 +955,7 @@ }, { "cell_type": "code", - "execution_count": 24, + "execution_count": 15, "metadata": {}, "outputs": [], "source": [ @@ -973,47 +992,14 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 16, "metadata": {}, "outputs": [ { - "ename": "Exception", - "evalue": "[500] Internal Server Error\nInternal error while making inference request", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mException\u001b[0m Traceback (most recent call last)", - "Cell \u001b[0;32mIn[25], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m report \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mawait\u001b[39;00m graph\u001b[38;5;241m.\u001b[39mainvoke({\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mtopic\u001b[39m\u001b[38;5;124m\"\u001b[39m: report_topic, \n\u001b[1;32m 2\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mreport_structure\u001b[39m\u001b[38;5;124m\"\u001b[39m: report_structure, \n\u001b[1;32m 3\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mnumber_of_queries\u001b[39m\u001b[38;5;124m\"\u001b[39m: \u001b[38;5;241m2\u001b[39m, \n\u001b[1;32m 4\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mtavily_topic\u001b[39m\u001b[38;5;124m\"\u001b[39m: tavily_topic, \n\u001b[1;32m 5\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mtavily_days\u001b[39m\u001b[38;5;124m\"\u001b[39m: tavily_days})\n", - "File \u001b[0;32m~/Desktop/Code/report_mAIstro/report_maistro/lib/python3.13/site-packages/langgraph/pregel/__init__.py:1982\u001b[0m, in \u001b[0;36mPregel.ainvoke\u001b[0;34m(self, input, config, stream_mode, output_keys, interrupt_before, interrupt_after, debug, **kwargs)\u001b[0m\n\u001b[1;32m 1980\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[1;32m 1981\u001b[0m chunks \u001b[38;5;241m=\u001b[39m []\n\u001b[0;32m-> 1982\u001b[0m \u001b[38;5;28;01masync\u001b[39;00m \u001b[38;5;28;01mfor\u001b[39;00m chunk \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mastream(\n\u001b[1;32m 1983\u001b[0m \u001b[38;5;28minput\u001b[39m,\n\u001b[1;32m 1984\u001b[0m config,\n\u001b[1;32m 1985\u001b[0m stream_mode\u001b[38;5;241m=\u001b[39mstream_mode,\n\u001b[1;32m 1986\u001b[0m output_keys\u001b[38;5;241m=\u001b[39moutput_keys,\n\u001b[1;32m 1987\u001b[0m interrupt_before\u001b[38;5;241m=\u001b[39minterrupt_before,\n\u001b[1;32m 1988\u001b[0m interrupt_after\u001b[38;5;241m=\u001b[39minterrupt_after,\n\u001b[1;32m 1989\u001b[0m debug\u001b[38;5;241m=\u001b[39mdebug,\n\u001b[1;32m 1990\u001b[0m \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs,\n\u001b[1;32m 1991\u001b[0m ):\n\u001b[1;32m 1992\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m stream_mode \u001b[38;5;241m==\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mvalues\u001b[39m\u001b[38;5;124m\"\u001b[39m:\n\u001b[1;32m 1993\u001b[0m latest \u001b[38;5;241m=\u001b[39m chunk\n", - "File \u001b[0;32m~/Desktop/Code/report_mAIstro/report_maistro/lib/python3.13/site-packages/langgraph/pregel/__init__.py:1867\u001b[0m, in \u001b[0;36mPregel.astream\u001b[0;34m(self, input, config, stream_mode, output_keys, interrupt_before, interrupt_after, debug, subgraphs)\u001b[0m\n\u001b[1;32m 1861\u001b[0m \u001b[38;5;66;03m# Similarly to Bulk Synchronous Parallel / Pregel model\u001b[39;00m\n\u001b[1;32m 1862\u001b[0m \u001b[38;5;66;03m# computation proceeds in steps, while there are channel updates\u001b[39;00m\n\u001b[1;32m 1863\u001b[0m \u001b[38;5;66;03m# channel updates from step N are only visible in step N+1\u001b[39;00m\n\u001b[1;32m 1864\u001b[0m \u001b[38;5;66;03m# channels are guaranteed to be immutable for the duration of the step,\u001b[39;00m\n\u001b[1;32m 1865\u001b[0m \u001b[38;5;66;03m# with channel updates applied only at the transition between steps\u001b[39;00m\n\u001b[1;32m 1866\u001b[0m \u001b[38;5;28;01mwhile\u001b[39;00m loop\u001b[38;5;241m.\u001b[39mtick(input_keys\u001b[38;5;241m=\u001b[39m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39minput_channels):\n\u001b[0;32m-> 1867\u001b[0m \u001b[38;5;28;01masync\u001b[39;00m \u001b[38;5;28;01mfor\u001b[39;00m _ \u001b[38;5;129;01min\u001b[39;00m runner\u001b[38;5;241m.\u001b[39matick(\n\u001b[1;32m 1868\u001b[0m loop\u001b[38;5;241m.\u001b[39mtasks\u001b[38;5;241m.\u001b[39mvalues(),\n\u001b[1;32m 1869\u001b[0m timeout\u001b[38;5;241m=\u001b[39m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mstep_timeout,\n\u001b[1;32m 1870\u001b[0m retry_policy\u001b[38;5;241m=\u001b[39m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mretry_policy,\n\u001b[1;32m 1871\u001b[0m get_waiter\u001b[38;5;241m=\u001b[39mget_waiter,\n\u001b[1;32m 1872\u001b[0m ):\n\u001b[1;32m 1873\u001b[0m \u001b[38;5;66;03m# emit output\u001b[39;00m\n\u001b[1;32m 1874\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m o \u001b[38;5;129;01min\u001b[39;00m output():\n\u001b[1;32m 1875\u001b[0m \u001b[38;5;28;01myield\u001b[39;00m o\n", - "File \u001b[0;32m~/Desktop/Code/report_mAIstro/report_maistro/lib/python3.13/site-packages/langgraph/pregel/runner.py:288\u001b[0m, in \u001b[0;36mPregelRunner.atick\u001b[0;34m(self, tasks, reraise, timeout, retry_policy, get_waiter)\u001b[0m\n\u001b[1;32m 286\u001b[0m fut\u001b[38;5;241m.\u001b[39mcancel()\n\u001b[1;32m 287\u001b[0m \u001b[38;5;66;03m# panic on failure or timeout\u001b[39;00m\n\u001b[0;32m--> 288\u001b[0m \u001b[43m_panic_or_proceed\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 289\u001b[0m \u001b[43m \u001b[49m\u001b[43mdone_futures\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43munion\u001b[49m\u001b[43m(\u001b[49m\u001b[43mf\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mfor\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43mf\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mt\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;129;43;01min\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43mfutures\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mitems\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mif\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43mt\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;129;43;01mis\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[38;5;129;43;01mnot\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mNone\u001b[39;49;00m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 290\u001b[0m \u001b[43m \u001b[49m\u001b[43mtimeout_exc_cls\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43masyncio\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mTimeoutError\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 291\u001b[0m \u001b[43m \u001b[49m\u001b[43mpanic\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mreraise\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 292\u001b[0m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n", - "File \u001b[0;32m~/Desktop/Code/report_mAIstro/report_maistro/lib/python3.13/site-packages/langgraph/pregel/runner.py:370\u001b[0m, in \u001b[0;36m_panic_or_proceed\u001b[0;34m(futs, timeout_exc_cls, panic)\u001b[0m\n\u001b[1;32m 368\u001b[0m \u001b[38;5;66;03m# raise the exception\u001b[39;00m\n\u001b[1;32m 369\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m panic:\n\u001b[0;32m--> 370\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m exc\n\u001b[1;32m 371\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[1;32m 372\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m\n", - "File \u001b[0;32m~/Desktop/Code/report_mAIstro/report_maistro/lib/python3.13/site-packages/langgraph/pregel/retry.py:138\u001b[0m, in \u001b[0;36marun_with_retry\u001b[0;34m(task, retry_policy, stream, writer)\u001b[0m\n\u001b[1;32m 136\u001b[0m \u001b[38;5;28;01mpass\u001b[39;00m\n\u001b[1;32m 137\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m--> 138\u001b[0m \u001b[38;5;28;01mawait\u001b[39;00m task\u001b[38;5;241m.\u001b[39mproc\u001b[38;5;241m.\u001b[39mainvoke(task\u001b[38;5;241m.\u001b[39minput, config)\n\u001b[1;32m 139\u001b[0m \u001b[38;5;66;03m# if successful, end\u001b[39;00m\n\u001b[1;32m 140\u001b[0m \u001b[38;5;28;01mbreak\u001b[39;00m\n", - "File \u001b[0;32m~/Desktop/Code/report_mAIstro/report_maistro/lib/python3.13/site-packages/langgraph/utils/runnable.py:453\u001b[0m, in \u001b[0;36mRunnableSeq.ainvoke\u001b[0;34m(self, input, config, **kwargs)\u001b[0m\n\u001b[1;32m 451\u001b[0m coro \u001b[38;5;241m=\u001b[39m step\u001b[38;5;241m.\u001b[39mainvoke(\u001b[38;5;28minput\u001b[39m, config)\n\u001b[1;32m 452\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m ASYNCIO_ACCEPTS_CONTEXT:\n\u001b[0;32m--> 453\u001b[0m \u001b[38;5;28minput\u001b[39m \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mawait\u001b[39;00m asyncio\u001b[38;5;241m.\u001b[39mcreate_task(coro, context\u001b[38;5;241m=\u001b[39mcontext)\n\u001b[1;32m 454\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[1;32m 455\u001b[0m \u001b[38;5;28minput\u001b[39m \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mawait\u001b[39;00m asyncio\u001b[38;5;241m.\u001b[39mcreate_task(coro)\n", - "File \u001b[0;32m~/Desktop/Code/report_mAIstro/report_maistro/lib/python3.13/site-packages/langgraph/pregel/__init__.py:1982\u001b[0m, in \u001b[0;36mPregel.ainvoke\u001b[0;34m(self, input, config, stream_mode, output_keys, interrupt_before, interrupt_after, debug, **kwargs)\u001b[0m\n\u001b[1;32m 1980\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[1;32m 1981\u001b[0m chunks \u001b[38;5;241m=\u001b[39m []\n\u001b[0;32m-> 1982\u001b[0m \u001b[38;5;28;01masync\u001b[39;00m \u001b[38;5;28;01mfor\u001b[39;00m chunk \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mastream(\n\u001b[1;32m 1983\u001b[0m \u001b[38;5;28minput\u001b[39m,\n\u001b[1;32m 1984\u001b[0m config,\n\u001b[1;32m 1985\u001b[0m stream_mode\u001b[38;5;241m=\u001b[39mstream_mode,\n\u001b[1;32m 1986\u001b[0m output_keys\u001b[38;5;241m=\u001b[39moutput_keys,\n\u001b[1;32m 1987\u001b[0m interrupt_before\u001b[38;5;241m=\u001b[39minterrupt_before,\n\u001b[1;32m 1988\u001b[0m interrupt_after\u001b[38;5;241m=\u001b[39minterrupt_after,\n\u001b[1;32m 1989\u001b[0m debug\u001b[38;5;241m=\u001b[39mdebug,\n\u001b[1;32m 1990\u001b[0m \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs,\n\u001b[1;32m 1991\u001b[0m ):\n\u001b[1;32m 1992\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m stream_mode \u001b[38;5;241m==\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mvalues\u001b[39m\u001b[38;5;124m\"\u001b[39m:\n\u001b[1;32m 1993\u001b[0m latest \u001b[38;5;241m=\u001b[39m chunk\n", - "File \u001b[0;32m~/Desktop/Code/report_mAIstro/report_maistro/lib/python3.13/site-packages/langgraph/pregel/__init__.py:1867\u001b[0m, in \u001b[0;36mPregel.astream\u001b[0;34m(self, input, config, stream_mode, output_keys, interrupt_before, interrupt_after, debug, subgraphs)\u001b[0m\n\u001b[1;32m 1861\u001b[0m \u001b[38;5;66;03m# Similarly to Bulk Synchronous Parallel / Pregel model\u001b[39;00m\n\u001b[1;32m 1862\u001b[0m \u001b[38;5;66;03m# computation proceeds in steps, while there are channel updates\u001b[39;00m\n\u001b[1;32m 1863\u001b[0m \u001b[38;5;66;03m# channel updates from step N are only visible in step N+1\u001b[39;00m\n\u001b[1;32m 1864\u001b[0m \u001b[38;5;66;03m# channels are guaranteed to be immutable for the duration of the step,\u001b[39;00m\n\u001b[1;32m 1865\u001b[0m \u001b[38;5;66;03m# with channel updates applied only at the transition between steps\u001b[39;00m\n\u001b[1;32m 1866\u001b[0m \u001b[38;5;28;01mwhile\u001b[39;00m loop\u001b[38;5;241m.\u001b[39mtick(input_keys\u001b[38;5;241m=\u001b[39m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39minput_channels):\n\u001b[0;32m-> 1867\u001b[0m \u001b[38;5;28;01masync\u001b[39;00m \u001b[38;5;28;01mfor\u001b[39;00m _ \u001b[38;5;129;01min\u001b[39;00m runner\u001b[38;5;241m.\u001b[39matick(\n\u001b[1;32m 1868\u001b[0m loop\u001b[38;5;241m.\u001b[39mtasks\u001b[38;5;241m.\u001b[39mvalues(),\n\u001b[1;32m 1869\u001b[0m timeout\u001b[38;5;241m=\u001b[39m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mstep_timeout,\n\u001b[1;32m 1870\u001b[0m retry_policy\u001b[38;5;241m=\u001b[39m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mretry_policy,\n\u001b[1;32m 1871\u001b[0m get_waiter\u001b[38;5;241m=\u001b[39mget_waiter,\n\u001b[1;32m 1872\u001b[0m ):\n\u001b[1;32m 1873\u001b[0m \u001b[38;5;66;03m# emit output\u001b[39;00m\n\u001b[1;32m 1874\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m o \u001b[38;5;129;01min\u001b[39;00m output():\n\u001b[1;32m 1875\u001b[0m \u001b[38;5;28;01myield\u001b[39;00m o\n", - "File \u001b[0;32m~/Desktop/Code/report_mAIstro/report_maistro/lib/python3.13/site-packages/langgraph/pregel/runner.py:222\u001b[0m, in \u001b[0;36mPregelRunner.atick\u001b[0;34m(self, tasks, reraise, timeout, retry_policy, get_waiter)\u001b[0m\n\u001b[1;32m 220\u001b[0m t \u001b[38;5;241m=\u001b[39m tasks[\u001b[38;5;241m0\u001b[39m]\n\u001b[1;32m 221\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[0;32m--> 222\u001b[0m \u001b[38;5;28;01mawait\u001b[39;00m arun_with_retry(\n\u001b[1;32m 223\u001b[0m t, retry_policy, stream\u001b[38;5;241m=\u001b[39m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39muse_astream, writer\u001b[38;5;241m=\u001b[39mwriter\n\u001b[1;32m 224\u001b[0m )\n\u001b[1;32m 225\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mcommit(t, \u001b[38;5;28;01mNone\u001b[39;00m)\n\u001b[1;32m 226\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mException\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m exc:\n", - "File \u001b[0;32m~/Desktop/Code/report_mAIstro/report_maistro/lib/python3.13/site-packages/langgraph/pregel/retry.py:138\u001b[0m, in \u001b[0;36marun_with_retry\u001b[0;34m(task, retry_policy, stream, writer)\u001b[0m\n\u001b[1;32m 136\u001b[0m \u001b[38;5;28;01mpass\u001b[39;00m\n\u001b[1;32m 137\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m--> 138\u001b[0m \u001b[38;5;28;01mawait\u001b[39;00m task\u001b[38;5;241m.\u001b[39mproc\u001b[38;5;241m.\u001b[39mainvoke(task\u001b[38;5;241m.\u001b[39minput, config)\n\u001b[1;32m 139\u001b[0m \u001b[38;5;66;03m# if successful, end\u001b[39;00m\n\u001b[1;32m 140\u001b[0m \u001b[38;5;28;01mbreak\u001b[39;00m\n", - "File \u001b[0;32m~/Desktop/Code/report_mAIstro/report_maistro/lib/python3.13/site-packages/langgraph/utils/runnable.py:453\u001b[0m, in \u001b[0;36mRunnableSeq.ainvoke\u001b[0;34m(self, input, config, **kwargs)\u001b[0m\n\u001b[1;32m 451\u001b[0m coro \u001b[38;5;241m=\u001b[39m step\u001b[38;5;241m.\u001b[39mainvoke(\u001b[38;5;28minput\u001b[39m, config)\n\u001b[1;32m 452\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m ASYNCIO_ACCEPTS_CONTEXT:\n\u001b[0;32m--> 453\u001b[0m \u001b[38;5;28minput\u001b[39m \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mawait\u001b[39;00m asyncio\u001b[38;5;241m.\u001b[39mcreate_task(coro, context\u001b[38;5;241m=\u001b[39mcontext)\n\u001b[1;32m 454\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[1;32m 455\u001b[0m \u001b[38;5;28minput\u001b[39m \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mawait\u001b[39;00m asyncio\u001b[38;5;241m.\u001b[39mcreate_task(coro)\n", - "File \u001b[0;32m~/Desktop/Code/report_mAIstro/report_maistro/lib/python3.13/site-packages/langgraph/utils/runnable.py:236\u001b[0m, in \u001b[0;36mRunnableCallable.ainvoke\u001b[0;34m(self, input, config, **kwargs)\u001b[0m\n\u001b[1;32m 234\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m ASYNCIO_ACCEPTS_CONTEXT:\n\u001b[1;32m 235\u001b[0m coro \u001b[38;5;241m=\u001b[39m cast(Coroutine[\u001b[38;5;28;01mNone\u001b[39;00m, \u001b[38;5;28;01mNone\u001b[39;00m, Any], \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mafunc(\u001b[38;5;28minput\u001b[39m, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs))\n\u001b[0;32m--> 236\u001b[0m ret \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mawait\u001b[39;00m asyncio\u001b[38;5;241m.\u001b[39mcreate_task(coro, context\u001b[38;5;241m=\u001b[39mcontext)\n\u001b[1;32m 237\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[1;32m 238\u001b[0m ret \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mawait\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mafunc(\u001b[38;5;28minput\u001b[39m, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs)\n", - "File \u001b[0;32m~/Desktop/Code/report_mAIstro/report_maistro/lib/python3.13/site-packages/langchain_core/runnables/config.py:588\u001b[0m, in \u001b[0;36mrun_in_executor\u001b[0;34m(executor_or_config, func, *args, **kwargs)\u001b[0m\n\u001b[1;32m 584\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mRuntimeError\u001b[39;00m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mexc\u001b[39;00m\n\u001b[1;32m 586\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m executor_or_config \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;129;01mor\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(executor_or_config, \u001b[38;5;28mdict\u001b[39m):\n\u001b[1;32m 587\u001b[0m \u001b[38;5;66;03m# Use default executor with context copied from current context\u001b[39;00m\n\u001b[0;32m--> 588\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;01mawait\u001b[39;00m asyncio\u001b[38;5;241m.\u001b[39mget_running_loop()\u001b[38;5;241m.\u001b[39mrun_in_executor(\n\u001b[1;32m 589\u001b[0m \u001b[38;5;28;01mNone\u001b[39;00m,\n\u001b[1;32m 590\u001b[0m cast(Callable[\u001b[38;5;241m.\u001b[39m\u001b[38;5;241m.\u001b[39m\u001b[38;5;241m.\u001b[39m, T], partial(copy_context()\u001b[38;5;241m.\u001b[39mrun, wrapper)),\n\u001b[1;32m 591\u001b[0m )\n\u001b[1;32m 593\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;01mawait\u001b[39;00m asyncio\u001b[38;5;241m.\u001b[39mget_running_loop()\u001b[38;5;241m.\u001b[39mrun_in_executor(executor_or_config, wrapper)\n", - "File \u001b[0;32m/opt/homebrew/Cellar/python@3.13/3.13.0_1/Frameworks/Python.framework/Versions/3.13/lib/python3.13/concurrent/futures/thread.py:58\u001b[0m, in \u001b[0;36m_WorkItem.run\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 55\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m\n\u001b[1;32m 57\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[0;32m---> 58\u001b[0m result \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mfn\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 59\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mBaseException\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m exc:\n\u001b[1;32m 60\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mfuture\u001b[38;5;241m.\u001b[39mset_exception(exc)\n", - "File \u001b[0;32m~/Desktop/Code/report_mAIstro/report_maistro/lib/python3.13/site-packages/langchain_core/runnables/config.py:579\u001b[0m, in \u001b[0;36mrun_in_executor..wrapper\u001b[0;34m()\u001b[0m\n\u001b[1;32m 577\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mwrapper\u001b[39m() \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m T:\n\u001b[1;32m 578\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[0;32m--> 579\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mfunc\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 580\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mStopIteration\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m exc:\n\u001b[1;32m 581\u001b[0m \u001b[38;5;66;03m# StopIteration can't be set on an asyncio.Future\u001b[39;00m\n\u001b[1;32m 582\u001b[0m \u001b[38;5;66;03m# it raises a TypeError and leaves the Future pending forever\u001b[39;00m\n\u001b[1;32m 583\u001b[0m \u001b[38;5;66;03m# so we need to convert it to a RuntimeError\u001b[39;00m\n\u001b[1;32m 584\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mRuntimeError\u001b[39;00m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mexc\u001b[39;00m\n", - "Cell \u001b[0;32mIn[19], line 89\u001b[0m, in \u001b[0;36mgenerate_queries\u001b[0;34m(state)\u001b[0m\n\u001b[1;32m 86\u001b[0m system_instructions \u001b[38;5;241m=\u001b[39m query_writer_instructions\u001b[38;5;241m.\u001b[39mformat(section_topic\u001b[38;5;241m=\u001b[39msection\u001b[38;5;241m.\u001b[39mdescription, number_of_queries\u001b[38;5;241m=\u001b[39mnumber_of_queries)\n\u001b[1;32m 88\u001b[0m \u001b[38;5;66;03m# Generate queries \u001b[39;00m\n\u001b[0;32m---> 89\u001b[0m queries \u001b[38;5;241m=\u001b[39m \u001b[43mstructured_llm\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43minvoke\u001b[49m\u001b[43m(\u001b[49m\u001b[43m[\u001b[49m\u001b[43mSystemMessage\u001b[49m\u001b[43m(\u001b[49m\u001b[43mcontent\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43msystem_instructions\u001b[49m\u001b[43m)\u001b[49m\u001b[43m]\u001b[49m\u001b[38;5;241;43m+\u001b[39;49m\u001b[43m[\u001b[49m\u001b[43mHumanMessage\u001b[49m\u001b[43m(\u001b[49m\u001b[43mcontent\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mGenerate search queries on the provided topic.\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\u001b[43m]\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 91\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m {\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124msearch_queries\u001b[39m\u001b[38;5;124m\"\u001b[39m: queries\u001b[38;5;241m.\u001b[39mqueries}\n", - "File \u001b[0;32m~/Desktop/Code/report_mAIstro/report_maistro/lib/python3.13/site-packages/langchain_core/runnables/base.py:3022\u001b[0m, in \u001b[0;36mRunnableSequence.invoke\u001b[0;34m(self, input, config, **kwargs)\u001b[0m\n\u001b[1;32m 3020\u001b[0m context\u001b[38;5;241m.\u001b[39mrun(_set_config_context, config)\n\u001b[1;32m 3021\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m i \u001b[38;5;241m==\u001b[39m \u001b[38;5;241m0\u001b[39m:\n\u001b[0;32m-> 3022\u001b[0m \u001b[38;5;28minput\u001b[39m \u001b[38;5;241m=\u001b[39m \u001b[43mcontext\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mrun\u001b[49m\u001b[43m(\u001b[49m\u001b[43mstep\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43minvoke\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43minput\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mconfig\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 3023\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[1;32m 3024\u001b[0m \u001b[38;5;28minput\u001b[39m \u001b[38;5;241m=\u001b[39m context\u001b[38;5;241m.\u001b[39mrun(step\u001b[38;5;241m.\u001b[39minvoke, \u001b[38;5;28minput\u001b[39m, config)\n", - "File \u001b[0;32m~/Desktop/Code/report_mAIstro/report_maistro/lib/python3.13/site-packages/langchain_core/runnables/base.py:5354\u001b[0m, in \u001b[0;36mRunnableBindingBase.invoke\u001b[0;34m(self, input, config, **kwargs)\u001b[0m\n\u001b[1;32m 5348\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21minvoke\u001b[39m(\n\u001b[1;32m 5349\u001b[0m \u001b[38;5;28mself\u001b[39m,\n\u001b[1;32m 5350\u001b[0m \u001b[38;5;28minput\u001b[39m: Input,\n\u001b[1;32m 5351\u001b[0m config: Optional[RunnableConfig] \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m,\n\u001b[1;32m 5352\u001b[0m \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs: Optional[Any],\n\u001b[1;32m 5353\u001b[0m ) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m Output:\n\u001b[0;32m-> 5354\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mbound\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43minvoke\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 5355\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;28;43minput\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[1;32m 5356\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_merge_configs\u001b[49m\u001b[43m(\u001b[49m\u001b[43mconfig\u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 5357\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43m{\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m}\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 5358\u001b[0m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n", - "File \u001b[0;32m~/Desktop/Code/report_mAIstro/report_maistro/lib/python3.13/site-packages/langchain_core/language_models/chat_models.py:286\u001b[0m, in \u001b[0;36mBaseChatModel.invoke\u001b[0;34m(self, input, config, stop, **kwargs)\u001b[0m\n\u001b[1;32m 275\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21minvoke\u001b[39m(\n\u001b[1;32m 276\u001b[0m \u001b[38;5;28mself\u001b[39m,\n\u001b[1;32m 277\u001b[0m \u001b[38;5;28minput\u001b[39m: LanguageModelInput,\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 281\u001b[0m \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs: Any,\n\u001b[1;32m 282\u001b[0m ) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m BaseMessage:\n\u001b[1;32m 283\u001b[0m config \u001b[38;5;241m=\u001b[39m ensure_config(config)\n\u001b[1;32m 284\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m cast(\n\u001b[1;32m 285\u001b[0m ChatGeneration,\n\u001b[0;32m--> 286\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mgenerate_prompt\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 287\u001b[0m \u001b[43m \u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_convert_input\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;28;43minput\u001b[39;49m\u001b[43m)\u001b[49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 288\u001b[0m \u001b[43m \u001b[49m\u001b[43mstop\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mstop\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 289\u001b[0m \u001b[43m \u001b[49m\u001b[43mcallbacks\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mconfig\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mget\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mcallbacks\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 290\u001b[0m \u001b[43m \u001b[49m\u001b[43mtags\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mconfig\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mget\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mtags\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 291\u001b[0m \u001b[43m \u001b[49m\u001b[43mmetadata\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mconfig\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mget\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mmetadata\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 292\u001b[0m \u001b[43m \u001b[49m\u001b[43mrun_name\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mconfig\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mget\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mrun_name\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 293\u001b[0m \u001b[43m \u001b[49m\u001b[43mrun_id\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mconfig\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mpop\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mrun_id\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mNone\u001b[39;49;00m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 294\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 295\u001b[0m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\u001b[38;5;241m.\u001b[39mgenerations[\u001b[38;5;241m0\u001b[39m][\u001b[38;5;241m0\u001b[39m],\n\u001b[1;32m 296\u001b[0m )\u001b[38;5;241m.\u001b[39mmessage\n", - "File \u001b[0;32m~/Desktop/Code/report_mAIstro/report_maistro/lib/python3.13/site-packages/langchain_core/language_models/chat_models.py:786\u001b[0m, in \u001b[0;36mBaseChatModel.generate_prompt\u001b[0;34m(self, prompts, stop, callbacks, **kwargs)\u001b[0m\n\u001b[1;32m 778\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mgenerate_prompt\u001b[39m(\n\u001b[1;32m 779\u001b[0m \u001b[38;5;28mself\u001b[39m,\n\u001b[1;32m 780\u001b[0m prompts: \u001b[38;5;28mlist\u001b[39m[PromptValue],\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 783\u001b[0m \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs: Any,\n\u001b[1;32m 784\u001b[0m ) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m LLMResult:\n\u001b[1;32m 785\u001b[0m prompt_messages \u001b[38;5;241m=\u001b[39m [p\u001b[38;5;241m.\u001b[39mto_messages() \u001b[38;5;28;01mfor\u001b[39;00m p \u001b[38;5;129;01min\u001b[39;00m prompts]\n\u001b[0;32m--> 786\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mgenerate\u001b[49m\u001b[43m(\u001b[49m\u001b[43mprompt_messages\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mstop\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mstop\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mcallbacks\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mcallbacks\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n", - "File \u001b[0;32m~/Desktop/Code/report_mAIstro/report_maistro/lib/python3.13/site-packages/langchain_core/language_models/chat_models.py:643\u001b[0m, in \u001b[0;36mBaseChatModel.generate\u001b[0;34m(self, messages, stop, callbacks, tags, metadata, run_name, run_id, **kwargs)\u001b[0m\n\u001b[1;32m 641\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m run_managers:\n\u001b[1;32m 642\u001b[0m run_managers[i]\u001b[38;5;241m.\u001b[39mon_llm_error(e, response\u001b[38;5;241m=\u001b[39mLLMResult(generations\u001b[38;5;241m=\u001b[39m[]))\n\u001b[0;32m--> 643\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m e\n\u001b[1;32m 644\u001b[0m flattened_outputs \u001b[38;5;241m=\u001b[39m [\n\u001b[1;32m 645\u001b[0m LLMResult(generations\u001b[38;5;241m=\u001b[39m[res\u001b[38;5;241m.\u001b[39mgenerations], llm_output\u001b[38;5;241m=\u001b[39mres\u001b[38;5;241m.\u001b[39mllm_output) \u001b[38;5;66;03m# type: ignore[list-item]\u001b[39;00m\n\u001b[1;32m 646\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m res \u001b[38;5;129;01min\u001b[39;00m results\n\u001b[1;32m 647\u001b[0m ]\n\u001b[1;32m 648\u001b[0m llm_output \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_combine_llm_outputs([res\u001b[38;5;241m.\u001b[39mllm_output \u001b[38;5;28;01mfor\u001b[39;00m res \u001b[38;5;129;01min\u001b[39;00m results])\n", - "File \u001b[0;32m~/Desktop/Code/report_mAIstro/report_maistro/lib/python3.13/site-packages/langchain_core/language_models/chat_models.py:633\u001b[0m, in \u001b[0;36mBaseChatModel.generate\u001b[0;34m(self, messages, stop, callbacks, tags, metadata, run_name, run_id, **kwargs)\u001b[0m\n\u001b[1;32m 630\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m i, m \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28menumerate\u001b[39m(messages):\n\u001b[1;32m 631\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[1;32m 632\u001b[0m results\u001b[38;5;241m.\u001b[39mappend(\n\u001b[0;32m--> 633\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_generate_with_cache\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 634\u001b[0m \u001b[43m \u001b[49m\u001b[43mm\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 635\u001b[0m \u001b[43m \u001b[49m\u001b[43mstop\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mstop\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 636\u001b[0m \u001b[43m \u001b[49m\u001b[43mrun_manager\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrun_managers\u001b[49m\u001b[43m[\u001b[49m\u001b[43mi\u001b[49m\u001b[43m]\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mif\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43mrun_managers\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01melse\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mNone\u001b[39;49;00m\u001b[43m,\u001b[49m\n\u001b[1;32m 637\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 638\u001b[0m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 639\u001b[0m )\n\u001b[1;32m 640\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mBaseException\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[1;32m 641\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m run_managers:\n", - "File \u001b[0;32m~/Desktop/Code/report_mAIstro/report_maistro/lib/python3.13/site-packages/langchain_core/language_models/chat_models.py:851\u001b[0m, in \u001b[0;36mBaseChatModel._generate_with_cache\u001b[0;34m(self, messages, stop, run_manager, **kwargs)\u001b[0m\n\u001b[1;32m 849\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[1;32m 850\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m inspect\u001b[38;5;241m.\u001b[39msignature(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_generate)\u001b[38;5;241m.\u001b[39mparameters\u001b[38;5;241m.\u001b[39mget(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mrun_manager\u001b[39m\u001b[38;5;124m\"\u001b[39m):\n\u001b[0;32m--> 851\u001b[0m result \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_generate\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 852\u001b[0m \u001b[43m \u001b[49m\u001b[43mmessages\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mstop\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mstop\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mrun_manager\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrun_manager\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\n\u001b[1;32m 853\u001b[0m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 854\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[1;32m 855\u001b[0m result \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_generate(messages, stop\u001b[38;5;241m=\u001b[39mstop, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs)\n", - "File \u001b[0;32m~/Desktop/Code/report_mAIstro/report_maistro/lib/python3.13/site-packages/langchain_nvidia_ai_endpoints/chat_models.py:382\u001b[0m, in \u001b[0;36mChatNVIDIA._generate\u001b[0;34m(self, messages, stop, run_manager, **kwargs)\u001b[0m\n\u001b[1;32m 380\u001b[0m inputs, extra_headers \u001b[38;5;241m=\u001b[39m _process_for_vlm(inputs, \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_client\u001b[38;5;241m.\u001b[39mmodel)\n\u001b[1;32m 381\u001b[0m payload \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_get_payload(inputs\u001b[38;5;241m=\u001b[39minputs, stop\u001b[38;5;241m=\u001b[39mstop, stream\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mFalse\u001b[39;00m, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs)\n\u001b[0;32m--> 382\u001b[0m response \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_client\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mget_req\u001b[49m\u001b[43m(\u001b[49m\u001b[43mpayload\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mpayload\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mextra_headers\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mextra_headers\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 383\u001b[0m responses, _ \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_client\u001b[38;5;241m.\u001b[39mpostprocess(response)\n\u001b[1;32m 384\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_set_callback_out(responses, run_manager)\n", - "File \u001b[0;32m~/Desktop/Code/report_mAIstro/report_maistro/lib/python3.13/site-packages/langchain_nvidia_ai_endpoints/_common.py:473\u001b[0m, in \u001b[0;36m_NVIDIAClient.get_req\u001b[0;34m(self, payload, extra_headers)\u001b[0m\n\u001b[1;32m 467\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mget_req\u001b[39m(\n\u001b[1;32m 468\u001b[0m \u001b[38;5;28mself\u001b[39m,\n\u001b[1;32m 469\u001b[0m payload: \u001b[38;5;28mdict\u001b[39m \u001b[38;5;241m=\u001b[39m {},\n\u001b[1;32m 470\u001b[0m extra_headers: \u001b[38;5;28mdict\u001b[39m \u001b[38;5;241m=\u001b[39m {},\n\u001b[1;32m 471\u001b[0m ) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m Response:\n\u001b[1;32m 472\u001b[0m \u001b[38;5;250m \u001b[39m\u001b[38;5;124;03m\"\"\"Post to the API.\"\"\"\u001b[39;00m\n\u001b[0;32m--> 473\u001b[0m response, session \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_post\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 474\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43minfer_url\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mpayload\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mextra_headers\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mextra_headers\u001b[49m\n\u001b[1;32m 475\u001b[0m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 476\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_wait(response, session)\n", - "File \u001b[0;32m~/Desktop/Code/report_mAIstro/report_maistro/lib/python3.13/site-packages/langchain_nvidia_ai_endpoints/_common.py:369\u001b[0m, in \u001b[0;36m_NVIDIAClient._post\u001b[0;34m(self, invoke_url, payload, extra_headers)\u001b[0m\n\u001b[1;32m 365\u001b[0m session \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mget_session_fn()\n\u001b[1;32m 366\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mlast_response \u001b[38;5;241m=\u001b[39m response \u001b[38;5;241m=\u001b[39m session\u001b[38;5;241m.\u001b[39mpost(\n\u001b[1;32m 367\u001b[0m \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m__add_authorization(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mlast_inputs)\n\u001b[1;32m 368\u001b[0m )\n\u001b[0;32m--> 369\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_try_raise\u001b[49m\u001b[43m(\u001b[49m\u001b[43mresponse\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 370\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m response, session\n", - "File \u001b[0;32m~/Desktop/Code/report_mAIstro/report_maistro/lib/python3.13/site-packages/langchain_nvidia_ai_endpoints/_common.py:462\u001b[0m, in \u001b[0;36m_NVIDIAClient._try_raise\u001b[0;34m(self, response)\u001b[0m\n\u001b[1;32m 460\u001b[0m body \u001b[38;5;241m+\u001b[39m\u001b[38;5;241m=\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124mPlease check or regenerate your API key.\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 461\u001b[0m \u001b[38;5;66;03m# todo: raise as an HTTPError\u001b[39;00m\n\u001b[0;32m--> 462\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mException\u001b[39;00m(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mheader\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;132;01m{\u001b[39;00mbody\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m) \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m\n", - "\u001b[0;31mException\u001b[0m: [500] Internal Server Error\nInternal error while making inference request", - "\u001b[0mDuring task with name 'generate_queries' and id '8e2cab54-f602-ac4c-d0d3-5ebdb431ab72'", - "\u001b[0mDuring task with name 'build_section_with_web_research' and id '3d4a8728-5ad0-c39a-2078-6e5199f9994c'" + "name": "stdout", + "output_type": "stream", + "text": [ + "Warning: No raw_content found for source https://www.reddit.com/r/LangChain/comments/1ashzgp/whats_your_take_on_langgraph/\n" ] } ], @@ -1027,111 +1013,89 @@ }, { "cell_type": "code", - "execution_count": 39, + "execution_count": 17, "metadata": {}, "outputs": [ { "data": { "text/markdown": [ - "# AI Agent Frameworks: Enabling Complex Workflows and Collaboration\n", - "\n", - "AI agent frameworks are revolutionizing the development of advanced artificial intelligence applications. These frameworks provide structured approaches for creating multi-agent systems, enabling AI components to work together on complex tasks. By offering different paradigms for agent interaction and workflow management, frameworks like LangGraph, CrewAI, OpenAI Swarm, and LlamaIndex Workflows are empowering developers to build more sophisticated, flexible, and efficient AI solutions. These tools are critical in addressing the growing demand for AI systems capable of handling intricate, multi-step processes and collaborative problem-solving scenarios in various domains.\n", + "# Overview of LangGraph and CrewAI: A Comparative Context\n", "\n", - "## LangGraph: Enabling Complex AI Workflows\n", + "The development of complex AI applications requires sophisticated tools that can manage intricate task interdependencies and agent relationships. Two such tools, LangGraph and CrewAI, have emerged as prominent solutions in the AI landscape. LangGraph is a powerful graph-structured programming tool that excels at building complex applications with highly domain-specific cognitive architecture. In contrast, CrewAI is an open-source tool for orchestrating multiple AI agents to accomplish complex tasks through a collaborative approach. This report provides a comparative analysis of LangGraph and CrewAI, highlighting their core features, architecture, and implementation, as well as their respective strengths and weaknesses. By examining these two tools, we aim to provide a comprehensive understanding of their capabilities and limitations, ultimately informing the development of complex AI applications.\n", "\n", - "**LangGraph's graph-based architecture enables more flexible and controllable AI agent workflows compared to linear frameworks.** Unlike LangChain's sequential chains, LangGraph represents tasks as interconnected nodes in a graph, allowing for non-linear execution paths, cycles, and complex branching logic. This structure is ideal for building multi-agent systems where different AI agents collaborate on tasks.\n", + "## Core Features, Architecture, and Implementation of LangGraph\n", "\n", - "LangGraph's key components include:\n", - "- Nodes: Represent individual tasks or agents\n", - "- Edges: Define information flow between nodes\n", - "- State: Tracks the current status as data moves through the graph\n", - "- Conditional logic: Controls workflow progression\n", + "**LangGraph's flexibility and visual workflow design make it an attractive choice for users who prioritize task orchestration and dependency management in complex pipelines.**\n", "\n", - "A notable use case is GPT-Newspaper, which leverages LangGraph to coordinate six specialized AI agents in creating personalized news content. The graph structure enables a writer-critique feedback loop, improving output quality.\n", + "LangGraph is a powerful graph-structured programming tool that offers many advanced features to support the development of complex AI applications. Its core features include a persistence layer that enables human-in-the-loop interactions, and it excels at building complex applications that require highly domain-specific cognitive architecture.\n", "\n", - "LangGraph also excels at error handling, allowing failed tasks to be retried or rerouted without restarting the entire workflow. This granular control makes LangGraph well-suited for complex enterprise applications requiring sophisticated decision-making, parallel processing, and human-in-the-loop interactions.\n", - "\n", - "### Sources\n", - "- LangGraph: Multi-Agent Workflows - LangChain Blog : https://blog.langchain.dev/langgraph-multi-agent-workflows/\n", - "- LangGraph - LangChain : https://www.langchain.com/langgraph\n", - "- LangGraph and Research Agents | Pinecone : https://www.pinecone.io/learn/langgraph/\n", + "LangGraph's architecture is based on a graph structure, which allows users to visualize and interact with agent graphs, even if development still primarily happens in code. This approach facilitates an iterative process, enabling users to modify an agent result or the logic underlying a specific node and then continue with that new response.\n", "\n", - "## CrewAI: Orchestrating AI Agent Collaboration\n", + "One example of LangGraph's implementation is the deployment of a LangGraph agent application with an open-source model, such as Mistral 7B. This involves serving the LangGraph agent as a REST API and another service that serves the open-source LLM as OpenAI-compatible APIs. LangGraph's flexibility allows users to customize and extend agent functionalities as needed, making it a valuable tool for AI development.\n", "\n", - "**CrewAI enables structured teamwork between AI agents, enhancing efficiency in complex tasks.** This open-source framework assigns specialized roles to agents, allowing them to work together like a well-coordinated crew. CrewAI's design emphasizes production-readiness and reliability over flexibility, making it ideal for real-world applications.\n", + "### Key Features of LangGraph\n", "\n", - "Key features include:\n", - "\n", - "- Role-based agents with defined expertise\n", - "- Sequential task orchestration (with plans for consensual and hierarchical strategies)\n", - "- Seamless integration with LangChain for expanded tooling\n", - "\n", - "A practical example demonstrates CrewAI's capabilities in stock analysis:\n", - "\n", - "1. Researcher agent gathers market data\n", - "2. Writer agent crafts analysis report\n", - "\n", - "This approach streamlines complex workflows by breaking them into manageable pieces, with each agent contributing its unique skills.\n", - "\n", - "CrewAI's focus on structured collaboration sets it apart from frameworks like AutoGen, which offer more flexibility but potentially less predictability. For developers already familiar with LangChain, CrewAI provides an accessible entry point into multi-agent systems.\n", - "\n", - "While powerful, CrewAI can be resource-intensive. In testing, a simple two-agent interaction consumed $0.18 in API costs, highlighting the need for efficient design in production environments.\n", + "* Persistence layer for human-in-the-loop interactions\n", + "* Graph-based architecture for visualizing and interacting with agent graphs\n", + "* Support for complex task interdependencies and agent relationships\n", + "* Flexibility and customization options for agent functionalities\n", "\n", "### Sources\n", - "- Understanding CrewAI: A Deep Dive into Multi-Agent AI Systems : https://medium.com/accredian/understanding-crewai-a-deep-dive-into-multi-agent-ai-systems-110d04703454\n", - "- CrewAI: Unlocking Collaborative Intelligence in AI Systems : https://insights.codegpt.co/crewai-guide\n", - "- Introduction - CrewAI : https://docs.crewai.com/introduction\n", - "- AutoGen Vs CrewAI: A Comprehensive Comparison Of Multi-Agent AI Frameworks : https://dataguy.in/autogen-vs-crewai-multi-agent-ai-framework-comparison/\n", - "- I Tested AI Agents Team Using the CrewAI Framework : https://medium.com/timurai/i-tested-ai-agents-team-using-the-crewai-framework-cf02912b84b1\n", - "\n", - "## OpenAI Swarm: A Framework for Multi-Agent Collaboration\n", "\n", - "**OpenAI Swarm introduces a lightweight, experimental approach to building multi-agent AI systems.** The framework enables developers to create specialized agents that can seamlessly coordinate and hand off tasks. At its core, Swarm utilizes two key concepts: routines, which define an agent's instructions and capabilities, and handoffs, allowing agents to transfer control to others as needed.\n", + "- Advanced Features of LangGraph: Summary and Considerations: https://dev.to/jamesli/advanced-features-of-langgraph-summary-and-considerations-3m1e\n", + "- LangGraph Studio: The first agent IDE: https://blog.langchain.dev/langgraph-studio-the-first-agent-ide/\n", + "- Deploying A LangGraph Agent Application with An Open-Source Model: https://bentoml.com/blog/deploying-a-langgraph-agent-application-with-an-open-source-model\n", "\n", - "A practical example of Swarm in action is an airline customer support system. Multiple agents, including a Triage Agent, Flight Modification Agent, and Lost Baggage Agent, work together to handle diverse customer inquiries. The system routes requests through the Triage Agent, which then transfers control to specialized agents based on the nature of the query.\n", + "## Examine the Core Features, Architecture, and Implementation of CrewAI\n", "\n", - "Swarm's design emphasizes simplicity and transparency, with stateless architecture and direct Python function calls for tool implementation. This approach offers developers fine-grained control over agent behaviors without the overhead of maintaining persistent states. While Swarm is primarily intended for educational purposes, it provides valuable insights into the fundamentals of multi-agent systems and points towards future developments in collaborative AI architectures.\n", + "**CrewAI is a game-changer in the AI landscape, enabling the creation of collaborative, autonomous AI agents that work together to achieve complex goals.**\n", "\n", - "### Sources\n", - "- OpenAI Releases Swarm: An Experimental AI Framework for Multi-Agent Systems : https://medium.com/cool-devs/openai-releases-swarm-an-experimental-ai-framework-for-multi-agent-systems-2e2d9372f839\n", - "- Swarm: OpenAI's Experimental Approach to Multi-Agent Systems - Arize AI : https://arize.com/blog/swarm-openai-experimental-approach-to-multi-agent-systems/\n", + "CrewAI is an open-source tool for orchestrating multiple AI agents to accomplish complex tasks. It provides a collaborative approach where agents can assume roles, delegate tasks, and share goals, akin to a real-world crew. The core features of CrewAI include:\n", "\n", - "## LlamaIndex Workflows: Streamlining Complex AI Processes\n", + "* **Role-Based Agent Design**: Customize agents with specific roles, goals, and tools.\n", + "* **Autonomous Inter-Agent Delegation**: Agents can autonomously delegate tasks and inquire amongst themselves, enhancing problem-solving efficiency.\n", + "* **Flexible Task Management**: Define tasks with customizable tools and assign them to agents dynamically.\n", "\n", - "**LlamaIndex Workflows provide an event-driven abstraction for chaining together multiple AI processes, offering greater flexibility than traditional DAG-based approaches.** This framework allows developers to create sophisticated AI applications by defining steps as Python functions decorated with @step. Each step handles specific event types and can emit new events, enabling dynamic and adaptive processing.\n", + "Here's an example of how CrewAI can be used to build a research assistant:\n", "\n", - "A key advantage is the ability to implement self-correction mechanisms and loops, which are challenging in acyclic graph models. For example, a workflow could include a step that evaluates the quality of an AI-generated response and triggers a refinement process if needed.\n", + "| Agent | Task | Tool |\n", + "| --- | --- | --- |\n", + "| Researcher | Research the latest advancements in AI hardware | Web Search Tool |\n", + "| Writer | Write a comprehensive 3-paragraph report outlining the key innovations | Writing Tool |\n", + "| Editor | Review and edit the report for clarity and coherence | Editing Tool |\n", "\n", - "LlamaIndex Workflows excel in:\n", + "In this example, the Researcher Agent uses the Web Search Tool to gather information, which is then passed to the Writer Agent to create a report. The Editor Agent reviews and edits the report to ensure clarity and coherence.\n", "\n", - "- Multi-stage prompt chaining\n", - "- Conditional retrieval based on user input\n", - "- Building conversational agents with reinforcement learning\n", + "### Sources\n", "\n", - "The framework also offers built-in instrumentation for observability, allowing developers to monitor each step's performance using tools like Arize Phoenix. This feature is particularly valuable for debugging complex AI pipelines and optimizing system performance in production environments.\n", + "* Build an AI Research Assistant Using CrewAI and Composio - Analytics Vidhya: https://www.analyticsvidhya.com/blog/2024/05/ai-research-assistant-using-crewai-and-composio/\n", + "* A Complete Guide to CREW AI and Agentic Frameworks: Unleashing the Power of Autonomous AI Crews - Medium: https://medium.com/@harshav.vanukuri/a-complete-guide-to-crew-ai-and-agentic-frameworks-unleashing-the-power-of-autonomous-ai-crews-9911f39110f5\n", + "* Understanding CrewAI: A Deep Dive into Multi-Agent AI Systems - Medium: https://medium.com/accredian/understanding-crewai-a-deep-dive-into-multi-agent-ai-systems-110d04703454\n", "\n", - "### Sources\n", - "- Introducing workflows beta: a new way to create complex AI applications with LlamaIndex : https://www.llamaindex.ai/blog/introducing-workflows-beta\n", - "- Understanding LlamaIndex Workflows: Streamlining Complex ... - Medium: https://medium.com/@pankaj_pandey/understanding-llamaindex-workflows-streamlining-complex-processes-easily-ba4c0809a704\n", + "## Comparative Analysis of LangGraph and CrewAI\n", "\n", - "## Summary and Recommendations\n", + "| **Dimension** | **LangGraph** | **CrewAI** |\n", + "| --- | --- | --- |\n", + "| **Core Features** | Persistence layer, graph-based architecture, support for complex task interdependencies | Role-Based Agent Design, Autonomous Inter-Agent Delegation, Flexible Task Management |\n", + "| **Agent Design** | Focus on individual agent development with customization options | Emphasis on collaborative, autonomous agents working together to achieve complex goals |\n", + "| **Task Management** | Supports complex task interdependencies and agent relationships | Enables dynamic task assignment and delegation amongst agents |\n", + "| **Visual Workflow** | Offers visual workflow design for iterative development and modification | No explicit visual workflow design, but enables agent collaboration and delegation |\n", + "| **Customization** | Allows for customization and extension of agent functionalities | Provides role-based agent design for customization and flexibility |\n", + "| **Use Cases** | Suitable for complex AI applications with domain-specific cognitive architecture | Ideal for building collaborative, autonomous AI agents for research, writing, and editing tasks |\n", "\n", - "LangGraph, CrewAI, OpenAI Swarm, and LlamaIndex Workflows each offer unique approaches to multi-agent AI systems. LangGraph's graph-based architecture excels in complex, non-linear workflows, while CrewAI focuses on structured, role-based collaboration. OpenAI Swarm provides a lightweight, experimental framework ideal for educational purposes, and LlamaIndex Workflows offers event-driven flexibility with built-in observability.\n", + "Based on the comparison, LangGraph excels in providing a flexible and customizable platform for individual agent development, with a strong focus on visual workflow design and complex task interdependencies. CrewAI, on the other hand, shines in its ability to orchestrate multiple AI agents to work together towards a common goal, with a emphasis on role-based agent design and autonomous inter-agent delegation.\n", "\n", - "| Framework | Key Strength | Best Use Case |\n", - "|-----------|--------------|----------------|\n", - "| LangGraph | Complex, non-linear workflows | Enterprise applications requiring sophisticated decision-making |\n", - "| CrewAI | Structured, role-based collaboration | Production-ready systems with defined agent roles |\n", - "| OpenAI Swarm | Simplicity and transparency | Educational projects and prototyping |\n", - "| LlamaIndex Workflows | Event-driven flexibility | Applications requiring adaptive processing and self-correction |\n", + "**Recommendations:**\n", "\n", - "For enterprise-level applications with complex decision trees, LangGraph is recommended. CrewAI is ideal for production systems with clearly defined agent roles. Developers exploring multi-agent concepts should consider OpenAI Swarm, while those needing adaptive workflows with strong observability should opt for LlamaIndex Workflows." + "* Use LangGraph for complex AI applications that require highly domain-specific cognitive architecture and customization options.\n", + "* Utilize CrewAI for building collaborative, autonomous AI agents that can work together to achieve complex goals, such as research, writing, and editing tasks.\n", + "* Consider combining both tools to leverage the strengths of each platform and create a comprehensive AI development workflow." ], "text/plain": [ "" ] }, - "execution_count": 39, + "execution_count": 17, "metadata": {}, "output_type": "execute_result" } @@ -1142,11 +1106,13 @@ ] }, { - "cell_type": "code", - "execution_count": null, + "cell_type": "markdown", "metadata": {}, - "outputs": [], - "source": [] + "source": [ + "Trace: \n", + "\n", + "https://smith.langchain.com/public/65d7ec4f-b89e-45d1-89e1-0d146078a19f/r" + ] }, { "cell_type": "code", @@ -1186,7 +1152,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.13.0" + "version": "3.13.1" } }, "nbformat": 4,