Provider: nebius · Model: meta-llama/Llama-3.3-70B-Instruct ─────────────────────────────────────────────────────\n", "\n" ], "text/plain": [ "\u001b[1;36mProvider: nebius · Model: meta-llama/Llama-\u001b[0m\u001b[1;36m3.3\u001b[0m\u001b[1;36m-70B-Instruct\u001b[0m \u001b[92m─────────────────────────────────────────────────────\u001b[0m\n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
LangSmith tracing: enabled \n",
"\n"
],
"text/plain": [
"LangSmith tracing: enabled \n"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"from agentic_architectures import get_llm, enable_langsmith, settings\n",
"from agentic_architectures.architectures import ReAct\n",
"from agentic_architectures.ui import print_md, print_header, print_step\n",
"\n",
"traced = enable_langsmith()\n",
"print_header(f\"Provider: {settings.llm_provider} · Model: {settings.llm_model}\")\n",
"print_md(f\"LangSmith tracing: {'enabled' if traced else 'disabled'}\")"
]
},
{
"cell_type": "markdown",
"id": "58455604",
"metadata": {
"papermill": {
"duration": 0.009991,
"end_time": "2026-05-27T04:26:16.288592+00:00",
"exception": false,
"start_time": "2026-05-27T04:26:16.278601+00:00",
"status": "completed"
},
"tags": []
},
"source": [
"## 5 · Library walkthrough\n",
"\n",
"Source: [`src/agentic_architectures/architectures/react.py`](../src/agentic_architectures/architectures/react.py).\n",
"\n",
"The class has three key pieces:\n",
"\n",
"1. **`_think(state)`** — invokes the LLM **without** binding tools. The model has no way to call a tool from this node; it can only produce text. The output is wrapped as an `AIMessage` with `additional_kwargs={\"react_step\": \"thought\"}` so downstream code can identify Thoughts separately from tool-calling AIMessages.\n",
"2. **`_act(state)`** — invokes the LLM **with** tools bound. Given the latest Thought in the message history, asks the model to call a tool or finalise.\n",
"3. **`build()`** — wires `think → act → tools → think` as a cycle; `act → END` is the exit when no tool calls remain.\n",
"\n",
"The two distinct instruction prompts (`THINK_INSTRUCTION`, `ACT_INSTRUCTION`) are appended *inline* to each invocation but **not** persisted in state — only the model's responses end up in the conversation history. That keeps the message log clean and reproducible."
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "3174e01b",
"metadata": {
"execution": {
"iopub.execute_input": "2026-05-27T04:26:16.317651Z",
"iopub.status.busy": "2026-05-27T04:26:16.310763Z",
"iopub.status.idle": "2026-05-27T04:26:16.340097Z",
"shell.execute_reply": "2026-05-27T04:26:16.335827Z"
},
"papermill": {
"duration": 0.040418,
"end_time": "2026-05-27T04:26:16.340097+00:00",
"exception": false,
"start_time": "2026-05-27T04:26:16.299679+00:00",
"status": "completed"
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"--- THINK_INSTRUCTION ---\n",
"Produce EXACTLY ONE short paragraph beginning with the literal word 'Thought:' that (a) reflects on what you have learned from the conversation so far, and (b) states the specific next step needed to advance toward an answer. Do NOT call any tools in this step — only produce the Thought.\n",
"\n",
"--- ACT_INSTRUCTION ---\n",
"Based on your latest Thought above, take exactly ONE action:\n",
" (a) Call exactly ONE tool whose arguments implement your Thought, OR\n",
" (b) Write the final answer (no tool call) if you already have enough evidence. Include source URLs in the final answer.\n"
]
}
],
"source": [
"from agentic_architectures.architectures import react as r_mod\n",
"\n",
"print('--- THINK_INSTRUCTION ---')\n",
"print(r_mod.ReAct.THINK_INSTRUCTION)\n",
"print()\n",
"print('--- ACT_INSTRUCTION ---')\n",
"print(r_mod.ReAct.ACT_INSTRUCTION)"
]
},
{
"cell_type": "markdown",
"id": "e6232800",
"metadata": {
"papermill": {
"duration": 0.016111,
"end_time": "2026-05-27T04:26:16.368653+00:00",
"exception": false,
"start_time": "2026-05-27T04:26:16.352542+00:00",
"status": "completed"
},
"tags": []
},
"source": [
"## 6 · Trace events\n",
"\n",
"A two-node ReAct trace contains five event types:\n",
"\n",
"| Event | Source | When emitted |\n",
"|---|---|---|\n",
"| `user` | the caller's `HumanMessage` | once, at the start |\n",
"| `thought` | output of `_think` (marked `react_step=thought`) | once per round |\n",
"| `tool_call` | `_act`'s AIMessage `tool_calls` | once per round (until the final round) |\n",
"| `tool_result` | ToolNode's `ToolMessage` | once per tool call |\n",
"| `agent` | `_act`'s final AIMessage (no tool calls) | once, at the end |\n",
"\n",
"The library's `_messages_to_trace` helper (in `tool_use.py`, shared with all tool-using architectures) checks the `react_step` marker so Thoughts are categorised correctly even though they look like normal AIMessages on the wire."
]
},
{
"cell_type": "markdown",
"id": "4341a857",
"metadata": {
"papermill": {
"duration": 0.015169,
"end_time": "2026-05-27T04:26:16.395258+00:00",
"exception": false,
"start_time": "2026-05-27T04:26:16.380089+00:00",
"status": "completed"
},
"tags": []
},
"source": [
"## 7 · Build the graph\n",
"\n",
"The cell below renders the **actual compiled `StateGraph`** as a PNG. Three nodes — `think`, `act`, `tools` — and a cycle `tools → think`. If this diagram disagrees with § 2's static one, the implementation has drifted."
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "0e4254c7",
"metadata": {
"execution": {
"iopub.execute_input": "2026-05-27T04:26:16.431019Z",
"iopub.status.busy": "2026-05-27T04:26:16.431019Z",
"iopub.status.idle": "2026-05-27T04:26:26.011941Z",
"shell.execute_reply": "2026-05-27T04:26:26.008126Z"
},
"papermill": {
"duration": 9.602655,
"end_time": "2026-05-27T04:26:26.011941+00:00",
"exception": false,
"start_time": "2026-05-27T04:26:16.409286+00:00",
"status": "completed"
},
"tags": []
},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAANgAAAFcCAIAAAAlFOfAAAAQAElEQVR4nOydB2AUxffH3+7d5dJ7I6SRBILUgDQBQ29KFaRJVYooYkNAQZqogIL+BaToDxBFEekggihNCEiT0Es66SSktyu7/3d3yeUS7kISruzuzcd4bJndS/a+92bem5k3YpZlgUCwNGIgEDgAESKBExAhEjgBESKBExAhEjgBESKBE1ijEDOTZDf/zcvNkJeWMEqFUikDwBgWRanO0QCMuhDFAqs5wgKj2qFpimVUJSmRegM3KdV/6g2gKVAd1FyOx1RXszSlKqm9t6ok3oumy98Cd2mWYsrPUTRG0vAuULELLFP5O0vsaBsb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eWVF8spD1Vb71gRk2fJlr7XBVdWuSl4VpdRr1GnnkpfrQd1HoD7IlE8ArRCiKmqrWqqOrXZbEFGgZKuFh0UiytPfPrTVk8O2RIgETkDCNwROQIRI4AREiAROQIRI4AREiAROQIRI4AT/DwAA//8TvlkSAAAABklEQVQDAI8LkTk4UhGxAAAAAElFTkSuQmCC",
"text/plain": [
"__start__
]):::first\n", "\tthink(think)\n", "\tact(act)\n", "\ttools(tools)\n", "\t__end__([__end__
]):::last\n", "\t__start__ --> think;\n", "\tact -.-> __end__;\n", "\tact -.-> tools;\n", "\tthink --> act;\n", "\ttools --> think;\n", "\tclassDef default fill:#f2f0ff,line-height:1.2\n", "\tclassDef first fill-opacity:0\n", "\tclassDef last fill:#bfb6fc\n", "\n" ] } ], "source": [ "from IPython.display import Image, display\n", "\n", "arch = ReAct(max_rounds=4)\n", "graph = arch.build()\n", "display(Image(graph.get_graph().draw_mermaid_png()))\n", "print(arch.diagram())" ] }, { "cell_type": "markdown", "id": "158af45c", "metadata": { "papermill": { "duration": 0.013752, "end_time": "2026-05-27T04:26:26.044301+00:00", "exception": false, "start_time": "2026-05-27T04:26:26.030549+00:00", "status": "completed" }, "tags": [] }, "source": [ "## 8 · Live run\n", "\n", "Concrete task: a multi-hop question whose answer requires at least one search. The citation requirement forces grounding." ] }, { "cell_type": "code", "execution_count": 4, "id": "220d41d1", "metadata": { "execution": { "iopub.execute_input": "2026-05-27T04:26:26.074583Z", "iopub.status.busy": "2026-05-27T04:26:26.074583Z", "iopub.status.idle": "2026-05-27T04:26:54.297552Z", "shell.execute_reply": "2026-05-27T04:26:54.294057Z" }, "papermill": { "duration": 28.241068, "end_time": "2026-05-27T04:26:54.299106+00:00", "exception": false, "start_time": "2026-05-27T04:26:26.058038+00:00", "status": "completed" }, "tags": [] }, "outputs": [ { "data": { "text/html": [ "Final answer ──────────────────────────────────────────────────────────────────────────────────────────────────────\n", "\n" ], "text/plain": [ "\u001b[1;36mFinal answer\u001b[0m \u001b[92m──────────────────────────────────────────────────────────────────────────────────────────────────────\u001b[0m\n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
Based on the search results, the current CEO of OpenAI as of 2026-05-27 is Sam Altman. According to the information\n",
"provided in the search results, Sam Altman has been the CEO of OpenAI since 2019. \n",
"\n",
"Source URLs: https://www.businessinsider.com/sam-altman \n",
"https://www.cnbc.com/2026/05/12/openai-trial-updates-sam-altman-set-to-testify-in-musk-suit.html \n",
"https://techcrunch.com/2026/05/16/openai-co-founder-greg-brockman-reportedly-takes-charge-of-product-strategy/ \n",
"\n"
],
"text/plain": [
"Based on the search results, the current CEO of OpenAI as of 2026-05-27 is Sam Altman. According to the information\n",
"provided in the search results, Sam Altman has been the CEO of OpenAI since 2019. \n",
"\n",
"Source URLs: https://www.businessinsider.com/sam-altman \n",
"https://www.cnbc.com/2026/05/12/openai-trial-updates-sam-altman-set-to-testify-in-musk-suit.html \n",
"https://techcrunch.com/2026/05/16/openai-co-founder-greg-brockman-reportedly-takes-charge-of-product-strategy/ \n"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n"
]
},
{
"data": {
"text/html": [
"2 tool call(s) · 3 thought(s) · 1 agent round(s) ──────────────────────────────────────────────────────────────\n", "\n" ], "text/plain": [ "\u001b[1;36m2\u001b[0m\u001b[1;36m tool \u001b[0m\u001b[1;36mcall\u001b[0m\u001b[1;36m(\u001b[0m\u001b[1;36ms\u001b[0m\u001b[1;36m)\u001b[0m\u001b[1;36m · \u001b[0m\u001b[1;36m3\u001b[0m\u001b[1;36m \u001b[0m\u001b[1;36mthought\u001b[0m\u001b[1;36m(\u001b[0m\u001b[1;36ms\u001b[0m\u001b[1;36m)\u001b[0m\u001b[1;36m · \u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;36m agent \u001b[0m\u001b[1;36mround\u001b[0m\u001b[1;36m(\u001b[0m\u001b[1;36ms\u001b[0m\u001b[1;36m)\u001b[0m \u001b[92m──────────────────────────────────────────────────────────────\u001b[0m\n" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "from datetime import date\n", "\n", "TASK = (\n", " f\"As of {date.today().isoformat()}, who is the current CEO of OpenAI, \"\n", " f\"and when did they first assume that role? Provide at least one source URL.\"\n", ")\n", "\n", "result = arch.run(TASK)\n", "\n", "print_header(\"Final answer\")\n", "print_md(result.output)\n", "print()\n", "print_header(\n", " f\"{result.metadata['tool_calls']} tool call(s) · \"\n", " f\"{result.metadata['thought_count']} thought(s) · \"\n", " f\"{result.metadata['rounds']} agent round(s)\"\n", ")" ] }, { "cell_type": "markdown", "id": "db0bd2fd", "metadata": { "papermill": { "duration": 0.013282, "end_time": "2026-05-27T04:26:54.328830+00:00", "exception": false, "start_time": "2026-05-27T04:26:54.315548+00:00", "status": "completed" }, "tags": [] }, "source": [ "### 8.0 · What just happened, briefly\n", "\n", "Look at the three counts above:\n", "\n", "- **`thought_count`** — with the two-node architecture, this should be **≥ tool_calls** (typically `tool_calls + 1`: one Thought before each Action plus one final Thought before the answer). If `thought_count = 0`, something is wrong with the graph wiring.\n", "- **`tool_calls`** — for a 1-fact question with citation, expect 1–2. More than 3 = over-thinking.\n", "- **`rounds`** = number of finalising agent turns. Always 1 in a well-behaved run.\n", "\n", "§ 9 below quantifies each from the actual run and flags any pathologies." ] }, { "cell_type": "markdown", "id": "5a534364", "metadata": { "papermill": { "duration": 0.018868, "end_time": "2026-05-27T04:26:54.358437+00:00", "exception": false, "start_time": "2026-05-27T04:26:54.339569+00:00", "status": "completed" }, "tags": [] }, "source": [ "### 8.1 · Full Thought → Action → Observation trace" ] }, { "cell_type": "code", "execution_count": 5, "id": "d3604ced", "metadata": { "execution": { "iopub.execute_input": "2026-05-27T04:26:54.394541Z", "iopub.status.busy": "2026-05-27T04:26:54.394541Z", "iopub.status.idle": "2026-05-27T04:26:54.658503Z", "shell.execute_reply": "2026-05-27T04:26:54.657882Z" }, "papermill": { "duration": 0.296722, "end_time": "2026-05-27T04:26:54.665500+00:00", "exception": false, "start_time": "2026-05-27T04:26:54.368778+00:00", "status": "completed" }, "tags": [] }, "outputs": [ { "data": { "text/html": [ "
› [1] USER\n", "\n" ], "text/plain": [ "\u001b[1;35m›\u001b[0m \u001b[1m[\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1m]\u001b[0m\u001b[1m USER\u001b[0m\n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
As of 2026-05-27, who is the current CEO of OpenAI, and when did they first assume that role? Provide at least one \n", "source URL.\n", "\n" ], "text/plain": [ "As of \u001b[1;36m2026\u001b[0m-\u001b[1;36m05\u001b[0m-\u001b[1;36m27\u001b[0m, who is the current CEO of OpenAI, and when did they first assume that role? Provide at least one \n", "source URL.\n" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "\n" ] }, { "data": { "text/html": [ "
› [2] THOUGHT\n", "\n" ], "text/plain": [ "\u001b[1;35m›\u001b[0m \u001b[1m[\u001b[0m\u001b[1;36m2\u001b[0m\u001b[1m]\u001b[0m\u001b[1m THOUGHT\u001b[0m\n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
Thought: From the conversation so far, I have learned that I need to find the current CEO of OpenAI as of \n",
"2026-05-27 and the date they first assumed that role. To advance toward an answer, the next step is to search for \n",
"the most recent and reliable sources of information on OpenAI's leadership, such as official company announcements,\n",
"reputable news articles, or the company's website, to determine \n",
"\n"
],
"text/plain": [
"Thought: From the conversation so far, I have learned that I need to find the current CEO of OpenAI as of \n",
"\u001b[1;36m2026\u001b[0m-\u001b[1;36m05\u001b[0m-\u001b[1;36m27\u001b[0m and the date they first assumed that role. To advance toward an answer, the next step is to search for \n",
"the most recent and reliable sources of information on OpenAI's leadership, such as official company announcements,\n",
"reputable news articles, or the company's website, to determine \n"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n"
]
},
{
"data": {
"text/html": [
"› [3] ACTION → tavily_search\n", "\n" ], "text/plain": [ "\u001b[1;35m›\u001b[0m \u001b[1m[\u001b[0m\u001b[1;36m3\u001b[0m\u001b[1m]\u001b[0m\u001b[1m ACTION → tavily_search\u001b[0m\n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
`OpenAI CEO as of 2026-05-27`\n", "\n" ], "text/plain": [ "`OpenAI CEO as of \u001b[1;36m2026\u001b[0m-\u001b[1;36m05\u001b[0m-\u001b[1;36m27\u001b[0m`\n" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "\n" ] }, { "data": { "text/html": [ "
› [4] OBSERVATION (tavily_search)\n", "\n" ], "text/plain": [ "\u001b[1;35m›\u001b[0m \u001b[1m[\u001b[0m\u001b[1;36m4\u001b[0m\u001b[1m]\u001b[0m\u001b[1m OBSERVATION \u001b[0m\u001b[1m(\u001b[0m\u001b[1mtavily_search\u001b[0m\u001b[1m)\u001b[0m\n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
{'error': ValueError('Error 400: When time_range is set, start_date or end_date cannot be set')}...\n", "\n" ], "text/plain": [ "\u001b[1m{\u001b[0m\u001b[32m'error'\u001b[0m: \u001b[1;35mValueError\u001b[0m\u001b[1m(\u001b[0m\u001b[32m'Error 400: When time_range is set, start_date or end_date cannot be set'\u001b[0m\u001b[1m)\u001b[0m\u001b[1m}\u001b[0m\u001b[33m...\u001b[0m\n" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "\n" ] }, { "data": { "text/html": [ "
› [5] THOUGHT\n", "\n" ], "text/plain": [ "\u001b[1;35m›\u001b[0m \u001b[1m[\u001b[0m\u001b[1;36m5\u001b[0m\u001b[1m]\u001b[0m\u001b[1m THOUGHT\u001b[0m\n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
Thought: From the conversation so far, I have learned that I need to find the current CEO of OpenAI as of \n",
"2026-05-27 and the date they first assumed that role. To advance toward an answer, the next step is to search for \n",
"the most recent and reliable sources of information on OpenAI's leadership, such as official company announcements,\n",
"reputable news articles, or the company's website, to determine \n",
"\n"
],
"text/plain": [
"Thought: From the conversation so far, I have learned that I need to find the current CEO of OpenAI as of \n",
"\u001b[1;36m2026\u001b[0m-\u001b[1;36m05\u001b[0m-\u001b[1;36m27\u001b[0m and the date they first assumed that role. To advance toward an answer, the next step is to search for \n",
"the most recent and reliable sources of information on OpenAI's leadership, such as official company announcements,\n",
"reputable news articles, or the company's website, to determine \n"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n"
]
},
{
"data": {
"text/html": [
"› [6] ACTION → tavily_search\n", "\n" ], "text/plain": [ "\u001b[1;35m›\u001b[0m \u001b[1m[\u001b[0m\u001b[1;36m6\u001b[0m\u001b[1m]\u001b[0m\u001b[1m ACTION → tavily_search\u001b[0m\n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
`OpenAI CEO as of 2026-05-27`\n", "\n" ], "text/plain": [ "`OpenAI CEO as of \u001b[1;36m2026\u001b[0m-\u001b[1;36m05\u001b[0m-\u001b[1;36m27\u001b[0m`\n" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "\n" ] }, { "data": { "text/html": [ "
› [7] OBSERVATION (tavily_search)\n", "\n" ], "text/plain": [ "\u001b[1;35m›\u001b[0m \u001b[1m[\u001b[0m\u001b[1;36m7\u001b[0m\u001b[1m]\u001b[0m\u001b[1m OBSERVATION \u001b[0m\u001b[1m(\u001b[0m\u001b[1mtavily_search\u001b[0m\u001b[1m)\u001b[0m\n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
{\"query\": \"OpenAI CEO as of 2026-05-27\", \"follow_up_questions\": null, \"answer\": null, \"images\": [], \"results\": \n", "[{\"url\": \"https://www.businessinsider.com/sam-altman\", \"title\": \"The career rise of OpenAI's billionaire CEO, Sam \n", "Altman - Business Insider\", \"score\": 0.8358192, \"publis...\n", "\n" ], "text/plain": [ "\u001b[1m{\u001b[0m\u001b[32m\"query\"\u001b[0m: \u001b[32m\"OpenAI CEO as of 2026-05-27\"\u001b[0m, \u001b[32m\"follow_up_questions\"\u001b[0m: null, \u001b[32m\"answer\"\u001b[0m: null, \u001b[32m\"images\"\u001b[0m: \u001b[1m[\u001b[0m\u001b[1m]\u001b[0m, \u001b[32m\"results\"\u001b[0m: \n", "\u001b[1m[\u001b[0m\u001b[1m{\u001b[0m\u001b[32m\"url\"\u001b[0m: \u001b[32m\"https://www.businessinsider.com/sam-altman\"\u001b[0m, \u001b[32m\"title\"\u001b[0m: \u001b[32m\"The career rise of OpenAI's billionaire CEO, Sam \u001b[0m\n", "\u001b[32mAltman - Business Insider\"\u001b[0m, \u001b[32m\"score\"\u001b[0m: \u001b[1;36m0.8358192\u001b[0m, \"publis\u001b[33m...\u001b[0m\n" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "\n" ] }, { "data": { "text/html": [ "
› [8] THOUGHT\n", "\n" ], "text/plain": [ "\u001b[1;35m›\u001b[0m \u001b[1m[\u001b[0m\u001b[1;36m8\u001b[0m\u001b[1m]\u001b[0m\u001b[1m THOUGHT\u001b[0m\n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
Thought: From the conversation so far, I have learned that I need to find the current CEO of OpenAI as of \n",
"2026-05-27 and the date they first assumed that role. To advance toward an answer, the next step is to carefully \n",
"review the search results provided, focusing on the most recent and reliable sources, such as official company \n",
"announcements or reputable news articles, to identify the current CEO \n",
"\n"
],
"text/plain": [
"Thought: From the conversation so far, I have learned that I need to find the current CEO of OpenAI as of \n",
"\u001b[1;36m2026\u001b[0m-\u001b[1;36m05\u001b[0m-\u001b[1;36m27\u001b[0m and the date they first assumed that role. To advance toward an answer, the next step is to carefully \n",
"review the search results provided, focusing on the most recent and reliable sources, such as official company \n",
"announcements or reputable news articles, to identify the current CEO \n"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n"
]
},
{
"data": {
"text/html": [
"› [9] FINAL ANSWER\n", "\n" ], "text/plain": [ "\u001b[1;35m›\u001b[0m \u001b[1m[\u001b[0m\u001b[1;36m9\u001b[0m\u001b[1m]\u001b[0m\u001b[1m FINAL ANSWER\u001b[0m\n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
Based on the search results, the current CEO of OpenAI as of 2026-05-27 is Sam Altman. According to the information\n", "provided in the search results, Sam Altman has been the CEO of OpenAI since 2019. \n", "\n", "Source URLs:\n", "https://www.businessinsider.com/sam-altman \n", "https://www.cnbc.com/2026/05/12/openai-tria\n", "\n" ], "text/plain": [ "Based on the search results, the current CEO of OpenAI as of \u001b[1;36m2026\u001b[0m-\u001b[1;36m05\u001b[0m-\u001b[1;36m27\u001b[0m is Sam Altman. According to the information\n", "provided in the search results, Sam Altman has been the CEO of OpenAI since \u001b[1;36m2019\u001b[0m. \n", "\n", "Source URLs:\n", "\u001b[4;94mhttps://www.businessinsider.com/sam-altman\u001b[0m \n", "\u001b[4;94mhttps://www.cnbc.com/2026/05/12/openai-tria\u001b[0m\n" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "\n" ] } ], "source": [ "for i, t in enumerate(result.trace, 1):\n", " if t['type'] == 'user':\n", " print_step(f\"[{i}] USER\", t['content'][:200])\n", " elif t['type'] == 'thought':\n", " print_step(f\"[{i}] THOUGHT\", t['content'][:400])\n", " elif t['type'] == 'tool_call':\n", " args = t['args'] if isinstance(t['args'], dict) else str(t['args'])\n", " query = args.get('query', args) if isinstance(args, dict) else args\n", " print_step(f\"[{i}] ACTION → {t['tool']}\", f\"`{query}`\")\n", " elif t['type'] == 'tool_result':\n", " snippet = t['content'][:280].replace('\\n', ' ')\n", " print_step(f\"[{i}] OBSERVATION ({t['tool']})\", snippet + '...')\n", " elif t['type'] == 'agent':\n", " print_step(f\"[{i}] FINAL ANSWER\", (t.get('content') or '')[:300])\n", " print()" ] }, { "cell_type": "markdown", "id": "715a500d", "metadata": { "papermill": { "duration": 0.030104, "end_time": "2026-05-27T04:26:54.721317+00:00", "exception": false, "start_time": "2026-05-27T04:26:54.691213+00:00", "status": "completed" }, "tags": [] }, "source": [ "## 9 · What we just observed\n", "\n", "The cells above are live. Below: a quantitative + qualitative breakdown of the **actual** ReAct loop the Nebius-hosted Llama-3.3-70B agent produced on this run.\n", "\n", "### 9.1 · Quantitative summary\n", "\n", "| Metric | Value |\n", "|---|---|\n", "| Tool calls (Actions) | **2** |\n", "| Thoughts | **3** |\n", "| Agent rounds | 1 |\n", "| Thought:Action ratio | 1.50 (target: 1.0 for clean ReAct) |\n", "| Final answer length | 575 chars |\n", "\n", "### 9.2 · Thought ↔ Action alignment\n", "\n", "| # | Thought (truncated) | Action |\n", "|---|---|---|\n", "| 1 | Thought: From the conversation so far, I have learned that I need to find the current CEO of OpenAI as of 2026-05-27 and the date they first assumed that role. … | `OpenAI CEO as of 2026-05-27` |\n", "\n", "### 9.3 · Pathologies surfaced in this run\n", "\n", "- **Query repetition.** 1 of 2 actions were duplicate queries. ReAct's thought step is supposed to *prevent* this by forcing the model to justify the next call. When it happens anyway, the thoughts were probably hollow.\n", "\n", "### 9.4 · The final answer (verbatim)\n", "\n", "> Based on the search results, the current CEO of OpenAI as of 2026-05-27 is Sam Altman. According to the information\n", "> provided in the search results, Sam Altman has been the CEO of OpenAI since 2019. \n", "> \n", "> Source URLs: https://www.businessinsider.com/sam-altman \n", "> https://www.cnbc.com/2026/05/12/openai-trial-updates-sam-altman-set-to-testify-in-musk-suit.html \n", "> https://techcrunch.com/2026/05/16/o…\n", "\n", "### 9.5 · The takeaway\n", "\n", "When the Thought:Action ratio is **1.0** and queries are *different* round-to-round, ReAct is buying you genuine value over Tool Use — the thoughts are doing real work. When the ratio drops below 1.0 or thoughts are short and queries repeat, you're paying ReAct's extra-token cost for no benefit — switch back to Tool Use (notebook 02) or escalate to **Planning (nb 04)** which decomposes the task upfront." ] }, { "cell_type": "markdown", "id": "83420c5d", "metadata": { "papermill": { "duration": 0.023667, "end_time": "2026-05-27T04:26:54.769786+00:00", "exception": false, "start_time": "2026-05-27T04:26:54.746119+00:00", "status": "completed" }, "tags": [] }, "source": [ "## 10 · Try other providers · also: a reasoning model\n", "\n", "ReAct needs **tool-calling**, same as Tool Use. But this is also where ReAct shines with a *reasoning* model — the model's internal `
Re-running on Nebius Qwen3-Thinking (reasoning model) ─────────────────────────────────────────────────────────────\n", "\n" ], "text/plain": [ "\u001b[1;36mRe-running on Nebius Qwen3-Thinking \u001b[0m\u001b[1;36m(\u001b[0m\u001b[1;36mreasoning model\u001b[0m\u001b[1;36m)\u001b[0m \u001b[92m─────────────────────────────────────────────────────────────\u001b[0m\n" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "The current spot price of one ounce of gold is **$4,529.38 USD**, as reported by Yahoo Finance at 06:13 ET (10:13 GMT) on the latest market data. This reflects a 0.9% decline in spot gold prices amid renewed geopolitical tensions. \n", "\n", "Source: [Yahoo Finance - Gold Retreats as Renewed U.S. Attacks on \n", " thoughts: 2, tool_calls: 1\n", "\n", " First Thought from Qwen3-Thinking (notice the depth vs Llama):\n", " Thought: From the user's initial query requesting the current gold price with a source citation and the subsequent strict formatting instructions for this reflection, I've learned that precision in both data sourcing and response structure is critical; the specific next step required to advance toward an answer is to utilize a reliable financial data API or trusted market source to retrieve the re\n" ] } ], "source": [ "from agentic_architectures.llm.factory import provider_supports_tools\n", "\n", "# (a) Try other providers if their keys are set.\n", "for p in [\"openai\", \"anthropic\", \"groq\"]:\n", " key = settings.api_key_for(p)\n", " if key is None or not key.get_secret_value():\n", " print(f\"[skip] {p}: no API key in .env\")\n", " continue\n", " if not provider_supports_tools(p):\n", " print(f\"[skip] {p}: provider does not advertise tool-calling\")\n", " continue\n", " print_header(f\"Re-running ReAct on {p}\")\n", " r = ReAct(llm=get_llm(provider=p), max_rounds=2).run(\n", " \"What is the current price (USD) of one ounce of gold? Cite the source URL.\"\n", " )\n", " print(r.output[:300])\n", " print(f\" thoughts: {r.metadata['thought_count']}, tool_calls: {r.metadata['tool_calls']}\")\n", " print()\n", "\n", "# (b) Swap to a Nebius reasoning model — same key, just a different model name.\n", "print_header(\"Re-running on Nebius Qwen3-Thinking (reasoning model)\")\n", "thinking_llm = get_llm(\n", " provider=\"nebius\",\n", " model=\"Qwen/Qwen3-235B-A22B-Thinking-2507-fast\",\n", " temperature=0.0,\n", ")\n", "thinking_arch = ReAct(llm=thinking_llm, max_rounds=2)\n", "r = thinking_arch.run(\n", " \"What is the current price (USD) of one ounce of gold? Cite the source URL.\"\n", ")\n", "print(r.output[:300])\n", "print(f\" thoughts: {r.metadata['thought_count']}, tool_calls: {r.metadata['tool_calls']}\")\n", "if r.trace:\n", " first_thought = next((t['content'] for t in r.trace if t['type'] == 'thought'), '')\n", " print()\n", " print(' First Thought from Qwen3-Thinking (notice the depth vs Llama):')\n", " print(' ' + first_thought[:400].replace('\\n', '\\n '))" ] }, { "cell_type": "markdown", "id": "eef83965", "metadata": { "papermill": { "duration": 0.020135, "end_time": "2026-05-27T04:27:18.050302+00:00", "exception": false, "start_time": "2026-05-27T04:27:18.030167+00:00", "status": "completed" }, "tags": [] }, "source": [ "## 11 · Failure modes, safety, extensions\n", "\n", "### 11.1 · Where this breaks (even with the architectural guarantee)\n", "\n", "| Failure | Mechanism | Mitigation |\n", "|---|---|---|\n", "| **Hollow thoughts** | Thought-shaped string with no real reasoning content | Tighten THINK_INSTRUCTION; or switch to a reasoning model (see § 10) |\n", "| **Thought–action mismatch** | Thought says \"search for X\" but Act calls with Y | Real but rare with 70B+ models; check by comparing thought.text and tool.args programmatically |\n", "| **Repeated thoughts** | Second Thought paraphrases the first | Wasted tokens but not a correctness bug; cap `max_rounds` |\n", "| **Over-thinking simple tasks** | 2 LLM calls per round adds up | Route via **Meta-Controller (nb 11)** or **Adaptive RAG (nb 26)** to pick Tool Use vs ReAct |\n", "| **Tool result hallucination** | Agent ignores tool result and answers from training data | Switch to **Self-RAG (nb 25)** or **Corrective RAG (nb 24)** |\n", "\n", "### 11.2 · Production safety\n", "\n", "- All Tool-Use safety rules from notebook 02 apply: cap rounds, whitelist tools, sanitise tool output, per-tool timeouts.\n", "- The Thought text is **user-visible** if you stream the agent — sometimes Thoughts reveal system-prompt internals or expose reasoning the user shouldn't see. Filter or hide before display.\n", "\n", "### 11.3 · Three extensions\n", "\n", "1. **Score Thoughts with `LLMJudge`.** Reject low-quality Thoughts and force the agent to re-think. Bridge to **Reflection (nb 01)** inside ReAct rounds.\n", "2. **Tree-search over ReAct branches.** At each Thought, generate K alternative Thoughts and expand the most promising. **Tree of Thoughts (nb 09)** and **LATS (nb 22)** do exactly this.\n", "3. **Add a verifier.** After the final answer, a separate LLM checks whether cited sources actually support the claim. Move to **PEV (nb 06)** and **Corrective RAG (nb 24)**.\n", "\n", "### 11.4 · What to read next\n", "\n", "- [**04 · Planning**](./04_planning.ipynb) — decompose the task upfront instead of reacting step-by-step.\n", "- [**06 · PEV**](./06_pev.ipynb) — ReAct + verifier + replanning.\n", "- [**09 · Tree of Thoughts**](./09_tree_of_thoughts.ipynb) — ReAct generalised to search.\n", "- [**22 · LATS**](./22_lats.ipynb) — ToT + reward → MCTS over the ReAct space.\n", "- [**26 · Adaptive RAG**](./26_adaptive_rag.ipynb) — auto-route task → Tool Use / ReAct / Planning.\n", "\n", "### 11.5 · References\n", "\n", "1. Yao, S. et al. *ReAct: Synergizing Reasoning and Acting in Language Models.* ICLR 2023. [arXiv:2210.03629](https://arxiv.org/abs/2210.03629)\n", "2. LangGraph `create_react_agent` — [official docs](https://langchain-ai.github.io/langgraph/reference/prebuilt/#langgraph.prebuilt.chat_agent_executor.create_react_agent) (note: we deliberately do NOT use this — see § 3.1)\n", "3. Qwen3 reasoning models on Nebius — [studio.nebius.com](https://studio.nebius.com)\n" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "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.10.0" }, "papermill": { "default_parameters": {}, "duration": 69.020554, "end_time": "2026-05-27T04:27:19.521416+00:00", "environment_variables": {}, "exception": null, "input_path": "all-agentic-architectures/notebooks/03_react.ipynb", "output_path": "all-agentic-architectures/notebooks/03_react.ipynb", "parameters": {}, "start_time": "2026-05-27T04:26:10.500862+00:00", "version": "2.7.0" } }, "nbformat": 4, "nbformat_minor": 5 }