{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "fecc3e39",
   "metadata": {},
   "outputs": [],
   "source": [
    "from dotenv import load_dotenv\n",
    "load_dotenv(\".env\", override=True)\n",
    "%load_ext autoreload\n",
    "%autoreload 2"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4c897bc9",
   "metadata": {},
   "source": [
    "# Deepagent for Research\n",
    "\n",
    "We will use the `deepagents` package to create a research agent. When using the `deepagents` package, it's important to: \n",
    "\n",
    "1. Understand the native tools available\n",
    "2. Supply task-specific tools\n",
    "3. Supply task-specific instructions\n",
    "4. Supply task-specific sub-agents"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3a14c09e",
   "metadata": {},
   "source": [
    "## Task-Specific Tools \n",
    "\n",
    "You can see an overview of the native tools in the [deepagents package README](https://github.com/langchain-ai/deepagents?tab=readme-ov-file#model) as well as the [quickstarts README](https://github.com/langchain-ai/deepagents-quickstarts). We'll extend this with two task-specific tools. \n",
    "\n",
    "### Search Tool \n",
    "\n",
    "There are different search tools that we can use. For example, we can use [Tavily](https://www.tavily.com/) to search for relevant URLs, then fetches the full webpage content.\n",
    "\n",
    "### Think Tool \n",
    "\n",
    "We'll supply a [think tool](https://www.anthropic.com/engineering/claude-think-tool), which is a useful way to help audit agent decision making. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "9163556f",
   "metadata": {},
   "outputs": [],
   "source": [
    "from research_agent.tools import tavily_search, think_tool\n",
    "tools = [tavily_search, think_tool]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7ba3ee5b",
   "metadata": {},
   "source": [
    "## Task-Specific Instructions\n",
    " \n",
    "Next, let's define task specific instructions using [a few prompting techniques for agents](https://youtu.be/XSZP9GhhuAc?si=zowpViL-2j-vI9hA):\n",
    "\n",
    "### 1. Think Like The Agent\n",
    "What instructions would you give a new work colleague?\n",
    "- **Read the question carefully** - What specific information does the user need?\n",
    "- **Start with broader searches** - Use broad, comprehensive queries first\n",
    "- **After each search, pause and assess** - Do I have enough to answer? What's still missing?\n",
    "- **Execute narrower searches as you gather information** - Fill in the gaps.\n",
    "\n",
    "### 2. Concrete Heuristics (Prevent \"Spin-Out\" on excessive tool calls)\n",
    "Use **Hard Limits** to prevent the research agent from calling tools excessively:\n",
    "- **Stop when you can answer confidently** - Don't keep searching for perfection.\n",
    "- **Give it budgets** - Use 2-3 search tool calls for simple queries. Use up to 5 for complex queries.\n",
    "- **Limit** - Always stop after 5 search tool calls if you cannot find the right source(s).\n",
    "\n",
    "### 3. Show your thinking\n",
    "After each search tool calling, use [`think_tool` to analyze the results](https://www.anthropic.com/engineering/claude-think-tool):\n",
    "- What key information did I find? \n",
    "- What's missing?\n",
    "- Do I have enough to answer the question comprehensively?\n",
    "- Should I search more or provide my answer?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "4487f04d",
   "metadata": {},
   "outputs": [],
   "source": [
    "from datetime import datetime\n",
    "from utils import show_prompt, format_messages\n",
    "from research_agent.prompts import (\n",
    "    RESEARCHER_INSTRUCTIONS,\n",
    "    RESEARCH_WORKFLOW_INSTRUCTIONS,\n",
    "    SUBAGENT_DELEGATION_INSTRUCTIONS,\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "a5eb7a89-8a26-4fb4-ba77-b05180f2c67e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #000080; text-decoration-color: #000080\">╭──────────────────────────────────────────────────── </span><span style=\"color: #008000; text-decoration-color: #008000; font-weight: bold\">Prompt</span><span style=\"color: #000080; text-decoration-color: #000080\"> ─────────────────────────────────────────────────────╮</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>                                                                                                                 <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  You are a research assistant conducting research on the user's input topic. For context, today's date is       <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  {date}.                                                                                                        <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>                                                                                                                 <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  <span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\">&lt;Task&gt;</span>                                                                                                         <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  Your job is to use tools to gather information about the user's input topic.                                   <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  You can use any of the research tools provided to you to find resources that can help answer the research      <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  question.                                                                                                      <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  You can call these tools in series or in parallel, your research is conducted in a tool-calling loop.          <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  <span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\">&lt;/Task&gt;</span>                                                                                                        <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>                                                                                                                 <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  <span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\">&lt;Available Research Tools&gt;</span>                                                                                     <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  You have access to two specific research tools:                                                                <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  1. **tavily_search**: For conducting web searches to gather information                                        <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  2. **think_tool**: For reflection and strategic planning during research                                       <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  **CRITICAL: Use think_tool after each search to reflect on results and plan next steps**                       <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  <span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\">&lt;/Available Research Tools&gt;</span>                                                                                    <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>                                                                                                                 <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  <span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\">&lt;Instructions&gt;</span>                                                                                                 <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  Think like a human researcher with limited time. Follow these steps:                                           <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>                                                                                                                 <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  1. **Read the question carefully** - What specific information does the user need?                             <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  2. **Start with broader searches** - Use broad, comprehensive queries first                                    <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  3. **After each search, pause and assess** - Do I have enough to answer? What's still missing?                 <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  4. **Execute narrower searches as you gather information** - Fill in the gaps                                  <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  5. **Stop when you can answer confidently** - Don't keep searching for perfection                              <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  <span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\">&lt;/Instructions&gt;</span>                                                                                                <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>                                                                                                                 <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  <span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\">&lt;Hard Limits&gt;</span>                                                                                                  <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  **Tool Call Budgets** (Prevent excessive searching):                                                           <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  - **Simple queries**: Use 2-3 search tool calls maximum                                                        <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  - **Complex queries**: Use up to 5 search tool calls maximum                                                   <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  - **Always stop**: After 5 search tool calls if you cannot find the right sources                              <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>                                                                                                                 <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  **Stop Immediately When**:                                                                                     <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  - You can answer the user's question comprehensively                                                           <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  - You have 3+ relevant examples/sources for the question                                                       <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  - Your last 2 searches returned similar information                                                            <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  <span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\">&lt;/Hard Limits&gt;</span>                                                                                                 <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>                                                                                                                 <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  <span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\">&lt;Show Your Thinking&gt;</span>                                                                                           <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  After each search tool call, use think_tool to analyze the results:                                            <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  - What key information did I find?                                                                             <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  - What's missing?                                                                                              <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  - Do I have enough to answer the question comprehensively?                                                     <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  - Should I search more or provide my answer?                                                                   <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  <span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\">&lt;/Show Your Thinking&gt;</span>                                                                                          <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>                                                                                                                 <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  <span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\">&lt;Final Response Format&gt;</span>                                                                                        <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  When providing your findings back to the orchestrator:                                                         <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>                                                                                                                 <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  1. **Structure your response**: Organize findings with clear headings and detailed explanations                <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  2. **Cite sources inline**: Use [1], [2], [3] format when referencing information from your searches           <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  3. **Include Sources section**: End with <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">### Sources listing each numbered source with title and URL</span>           <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>                                                                                                                 <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  Example:                                                                                                       <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  ```                                                                                                            <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  <span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">## Key Findings</span>                                                                                                <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>                                                                                                                 <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  Context engineering is a critical technique for AI agents [1]. Studies show that proper context management     <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  can improve performance by 40% [2].                                                                            <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>                                                                                                                 <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">### Sources</span>                                                                                                    <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  [1] Context Engineering Guide: https://example.com/context-guide                                               <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  [2] AI Performance Study: https://example.com/study                                                            <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  ```                                                                                                            <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>                                                                                                                 <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  The orchestrator will consolidate citations from all sub-agents into the final report.                         <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  <span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\">&lt;/Final Response Format&gt;</span>                                                                                       <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>                                                                                                                 <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>                                                                                                                 <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯</span>\n",
       "</pre>\n"
      ],
      "text/plain": [
       "\u001b[34m╭─\u001b[0m\u001b[34m───────────────────────────────────────────────────\u001b[0m\u001b[34m \u001b[0m\u001b[1;32mPrompt\u001b[0m\u001b[34m \u001b[0m\u001b[34m────────────────────────────────────────────────────\u001b[0m\u001b[34m─╮\u001b[0m\n",
       "\u001b[34m│\u001b[0m                                                                                                                 \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  You are a research assistant conducting research on the user's input topic. For context, today's date is       \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  {date}.                                                                                                        \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m                                                                                                                 \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  \u001b[1;34m<Task>\u001b[0m                                                                                                         \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  Your job is to use tools to gather information about the user's input topic.                                   \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  You can use any of the research tools provided to you to find resources that can help answer the research      \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  question.                                                                                                      \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  You can call these tools in series or in parallel, your research is conducted in a tool-calling loop.          \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  \u001b[1;34m</Task>\u001b[0m                                                                                                        \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m                                                                                                                 \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  \u001b[1;34m<Available Research Tools>\u001b[0m                                                                                     \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  You have access to two specific research tools:                                                                \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  1. **tavily_search**: For conducting web searches to gather information                                        \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  2. **think_tool**: For reflection and strategic planning during research                                       \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  **CRITICAL: Use think_tool after each search to reflect on results and plan next steps**                       \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  \u001b[1;34m</Available Research Tools>\u001b[0m                                                                                    \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m                                                                                                                 \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  \u001b[1;34m<Instructions>\u001b[0m                                                                                                 \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  Think like a human researcher with limited time. Follow these steps:                                           \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m                                                                                                                 \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  1. **Read the question carefully** - What specific information does the user need?                             \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  2. **Start with broader searches** - Use broad, comprehensive queries first                                    \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  3. **After each search, pause and assess** - Do I have enough to answer? What's still missing?                 \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  4. **Execute narrower searches as you gather information** - Fill in the gaps                                  \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  5. **Stop when you can answer confidently** - Don't keep searching for perfection                              \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  \u001b[1;34m</Instructions>\u001b[0m                                                                                                \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m                                                                                                                 \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  \u001b[1;34m<Hard Limits>\u001b[0m                                                                                                  \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  **Tool Call Budgets** (Prevent excessive searching):                                                           \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  - **Simple queries**: Use 2-3 search tool calls maximum                                                        \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  - **Complex queries**: Use up to 5 search tool calls maximum                                                   \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  - **Always stop**: After 5 search tool calls if you cannot find the right sources                              \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m                                                                                                                 \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  **Stop Immediately When**:                                                                                     \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  - You can answer the user's question comprehensively                                                           \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  - You have 3+ relevant examples/sources for the question                                                       \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  - Your last 2 searches returned similar information                                                            \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  \u001b[1;34m</Hard Limits>\u001b[0m                                                                                                 \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m                                                                                                                 \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  \u001b[1;34m<Show Your Thinking>\u001b[0m                                                                                           \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  After each search tool call, use think_tool to analyze the results:                                            \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  - What key information did I find?                                                                             \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  - What's missing?                                                                                              \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  - Do I have enough to answer the question comprehensively?                                                     \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  - Should I search more or provide my answer?                                                                   \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  \u001b[1;34m</Show Your Thinking>\u001b[0m                                                                                          \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m                                                                                                                 \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  \u001b[1;34m<Final Response Format>\u001b[0m                                                                                        \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  When providing your findings back to the orchestrator:                                                         \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m                                                                                                                 \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  1. **Structure your response**: Organize findings with clear headings and detailed explanations                \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  2. **Cite sources inline**: Use [1], [2], [3] format when referencing information from your searches           \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  3. **Include Sources section**: End with \u001b[1;36m#\u001b[0m\u001b[1;36m## Sources listing each numbered source with title and URL\u001b[0m           \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m                                                                                                                 \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  Example:                                                                                                       \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  ```                                                                                                            \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  \u001b[1;35m## Key Findings\u001b[0m                                                                                                \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m                                                                                                                 \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  Context engineering is a critical technique for AI agents [1]. Studies show that proper context management     \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  can improve performance by 40% [2].                                                                            \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m                                                                                                                 \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  \u001b[1;36m#\u001b[0m\u001b[1;36m## Sources\u001b[0m                                                                                                    \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  [1] Context Engineering Guide: https://example.com/context-guide                                               \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  [2] AI Performance Study: https://example.com/study                                                            \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  ```                                                                                                            \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m                                                                                                                 \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  The orchestrator will consolidate citations from all sub-agents into the final report.                         \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  \u001b[1;34m</Final Response Format>\u001b[0m                                                                                       \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m                                                                                                                 \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m                                                                                                                 \u001b[34m│\u001b[0m\n",
       "\u001b[34m╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯\u001b[0m\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "show_prompt(RESEARCHER_INSTRUCTIONS)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "48ab6e7e",
   "metadata": {},
   "source": [
    "## Task-Specific Sub-Agents\n",
    "\n",
    "You can specify [custom subagents](https://github.com/langchain-ai/deepagents?tab=readme-ov-file#subagents) as a means of context isolation. \n",
    "\n",
    "Here's well define a sub-agent that can search the web for information. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "a6570183",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Get current date\n",
    "current_date = datetime.now().strftime(\"%Y-%m-%d\")\n",
    "\n",
    "# Create research sub-agent\n",
    "research_sub_agent = {\n",
    "    \"name\": \"research-agent\",\n",
    "    \"description\": \"Delegate research to the sub-agent researcher. Only give this researcher one topic at a time.\",\n",
    "    \"system_prompt\": RESEARCHER_INSTRUCTIONS.format(date=current_date),\n",
    "    \"tools\": [tavily_search, think_tool],\n",
    "}"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8ef99f1d",
   "metadata": {},
   "source": [
    "## Putting it all together\n",
    "\n",
    "### Instructions\n",
    "\n",
    "Now, we can look at all of our instructions together. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "4e55b2c0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #000080; text-decoration-color: #000080\">╭──────────────────────────────────────────────────── </span><span style=\"color: #008000; text-decoration-color: #008000; font-weight: bold\">Prompt</span><span style=\"color: #000080; text-decoration-color: #000080\"> ─────────────────────────────────────────────────────╮</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>                                                                                                                 <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  # Research Workflow                                                                                            <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>                                                                                                                 <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  Follow this workflow for all research requests:                                                                <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>                                                                                                                 <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  1. **Plan**: Create a todo list with write_todos to break down the research into focused tasks                 <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  2. **Save the request**: Use write_file() to save the user's research question to `/research_request.md`       <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  3. **Research**: Delegate research tasks to sub-agents using the task() tool - ALWAYS use sub-agents for       <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  research, never conduct research yourself                                                                      <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  4. **Synthesize**: Review all sub-agent findings and consolidate citations (each unique URL gets one number    <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  across all findings)                                                                                           <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  5. **Write Report**: Write a comprehensive final report to `/final_report.md` (see Report Writing Guidelines   <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  below)                                                                                                         <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  6. **Verify**: Read `/research_request.md` and confirm you've addressed all aspects with proper citations and  <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  structure                                                                                                      <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>                                                                                                                 <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  <span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">## Research Planning Guidelines</span>                                                                                <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  - Batch similar research tasks into a single TODO to minimize overhead                                         <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  - For simple fact-finding questions, use 1 sub-agent                                                           <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  - For comparisons or multi-faceted topics, delegate to multiple parallel sub-agents                            <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  - Each sub-agent should research one specific aspect and return findings                                       <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>                                                                                                                 <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  <span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">## Report Writing Guidelines</span>                                                                                   <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>                                                                                                                 <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  When writing the final report to `/final_report.md`, follow these structure patterns:                          <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>                                                                                                                 <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  **For comparisons:**                                                                                           <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  1. Introduction                                                                                                <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  2. Overview of topic A                                                                                         <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  3. Overview of topic B                                                                                         <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  4. Detailed comparison                                                                                         <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  5. Conclusion                                                                                                  <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>                                                                                                                 <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  **For lists/rankings:**                                                                                        <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  Simply list items with details - no introduction needed:                                                       <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  1. Item 1 with explanation                                                                                     <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  2. Item 2 with explanation                                                                                     <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  3. Item 3 with explanation                                                                                     <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>                                                                                                                 <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  **For summaries/overviews:**                                                                                   <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  1. Overview of topic                                                                                           <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  2. Key concept 1                                                                                               <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  3. Key concept 2                                                                                               <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  4. Key concept 3                                                                                               <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  5. Conclusion                                                                                                  <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>                                                                                                                 <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  **General guidelines:**                                                                                        <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  - Use clear section headings (<span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">## for sections, </span><span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">### for subsections)</span>                                            <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  - Write in paragraph form by default - be text-heavy, not just bullet points                                   <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  - Do NOT use self-referential language (\"I found...\", \"I researched...\")                                       <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  - Write as a professional report without meta-commentary                                                       <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  - Each section should be comprehensive and detailed                                                            <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  - Use bullet points only when listing is more appropriate than prose                                           <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>                                                                                                                 <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  **Citation format:**                                                                                           <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  - Cite sources inline using [1], [2], [3] format                                                               <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  - Assign each unique URL a single citation number across ALL sub-agent findings                                <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  - End report with <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">### Sources section listing each numbered source</span>                                             <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  - Number sources sequentially without gaps (1,2,3,4...)                                                        <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  - Format: [1] Source Title: URL (each on separate line for proper list rendering)                              <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  - Example:                                                                                                     <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>                                                                                                                 <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>    Some important finding [1]. Another key insight [2].                                                         <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>                                                                                                                 <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>    <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">### Sources</span>                                                                                                  <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>    [1] AI Research Paper: https://example.com/paper                                                             <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>    [2] Industry Analysis: https://example.com/analysis                                                          <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>                                                                                                                 <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>                                                                                                                 <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  ================================================================================                               <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>                                                                                                                 <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  # Sub-Agent Research Coordination                                                                              <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>                                                                                                                 <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  Your role is to coordinate research by delegating tasks from your TODO list to specialized research            <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  sub-agents.                                                                                                    <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>                                                                                                                 <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  <span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">## Delegation Strategy</span>                                                                                         <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>                                                                                                                 <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  **DEFAULT: Start with 1 sub-agent** for most queries:                                                          <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  - \"What is quantum computing?\" → 1 sub-agent (general overview)                                                <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  - \"List the top 10 coffee shops in San Francisco\" → 1 sub-agent                                                <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  - \"Summarize the history of the internet\" → 1 sub-agent                                                        <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  - \"Research context engineering for AI agents\" → 1 sub-agent (covers all aspects)                              <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>                                                                                                                 <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  **ONLY parallelize when the query EXPLICITLY requires comparison or has clearly independent aspects:**         <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>                                                                                                                 <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  **Explicit comparisons** → 1 sub-agent per element:                                                            <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  - \"Compare OpenAI vs Anthropic vs DeepMind AI safety approaches\" → 3 parallel sub-agents                       <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  - \"Compare Python vs JavaScript for web development\" → 2 parallel sub-agents                                   <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>                                                                                                                 <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  **Clearly separated aspects** → 1 sub-agent per aspect (use sparingly):                                        <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  - \"Research renewable energy adoption in Europe, Asia, and North America\" → 3 parallel sub-agents (geographic  <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  separation)                                                                                                    <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  - Only use this pattern when aspects cannot be covered efficiently by a single comprehensive search            <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>                                                                                                                 <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  <span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">## Key Principles</span>                                                                                              <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  - **Bias towards single sub-agent**: One comprehensive research task is more token-efficient than multiple     <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  narrow ones                                                                                                    <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  - **Avoid premature decomposition**: Don't break \"research X\" into \"research X overview\", \"research X          <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  techniques\", \"research X applications\" - just use 1 sub-agent for all of X                                     <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  - **Parallelize only for clear comparisons**: Use multiple sub-agents when comparing distinct entities or      <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  geographically separated data                                                                                  <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>                                                                                                                 <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  <span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">## Parallel Execution Limits</span>                                                                                   <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  - Use at most 3 parallel sub-agents per iteration                                                              <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  - Make multiple task() calls in a single response to enable parallel execution                                 <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  - Each sub-agent returns findings independently                                                                <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>                                                                                                                 <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  <span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">## Research Limits</span>                                                                                             <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  - Stop after 3 delegation rounds if you haven't found adequate sources                                         <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  - Stop when you have sufficient information to answer comprehensively                                          <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  - Bias towards focused research over exhaustive exploration                                                    <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>                                                                                                                 <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯</span>\n",
       "</pre>\n"
      ],
      "text/plain": [
       "\u001b[34m╭─\u001b[0m\u001b[34m───────────────────────────────────────────────────\u001b[0m\u001b[34m \u001b[0m\u001b[1;32mPrompt\u001b[0m\u001b[34m \u001b[0m\u001b[34m────────────────────────────────────────────────────\u001b[0m\u001b[34m─╮\u001b[0m\n",
       "\u001b[34m│\u001b[0m                                                                                                                 \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  # Research Workflow                                                                                            \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m                                                                                                                 \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  Follow this workflow for all research requests:                                                                \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m                                                                                                                 \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  1. **Plan**: Create a todo list with write_todos to break down the research into focused tasks                 \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  2. **Save the request**: Use write_file() to save the user's research question to `/research_request.md`       \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  3. **Research**: Delegate research tasks to sub-agents using the task() tool - ALWAYS use sub-agents for       \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  research, never conduct research yourself                                                                      \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  4. **Synthesize**: Review all sub-agent findings and consolidate citations (each unique URL gets one number    \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  across all findings)                                                                                           \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  5. **Write Report**: Write a comprehensive final report to `/final_report.md` (see Report Writing Guidelines   \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  below)                                                                                                         \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  6. **Verify**: Read `/research_request.md` and confirm you've addressed all aspects with proper citations and  \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  structure                                                                                                      \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m                                                                                                                 \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  \u001b[1;35m## Research Planning Guidelines\u001b[0m                                                                                \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  - Batch similar research tasks into a single TODO to minimize overhead                                         \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  - For simple fact-finding questions, use 1 sub-agent                                                           \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  - For comparisons or multi-faceted topics, delegate to multiple parallel sub-agents                            \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  - Each sub-agent should research one specific aspect and return findings                                       \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m                                                                                                                 \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  \u001b[1;35m## Report Writing Guidelines\u001b[0m                                                                                   \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m                                                                                                                 \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  When writing the final report to `/final_report.md`, follow these structure patterns:                          \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m                                                                                                                 \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  **For comparisons:**                                                                                           \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  1. Introduction                                                                                                \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  2. Overview of topic A                                                                                         \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  3. Overview of topic B                                                                                         \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  4. Detailed comparison                                                                                         \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  5. Conclusion                                                                                                  \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m                                                                                                                 \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  **For lists/rankings:**                                                                                        \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  Simply list items with details - no introduction needed:                                                       \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  1. Item 1 with explanation                                                                                     \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  2. Item 2 with explanation                                                                                     \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  3. Item 3 with explanation                                                                                     \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m                                                                                                                 \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  **For summaries/overviews:**                                                                                   \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  1. Overview of topic                                                                                           \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  2. Key concept 1                                                                                               \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  3. Key concept 2                                                                                               \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  4. Key concept 3                                                                                               \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  5. Conclusion                                                                                                  \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m                                                                                                                 \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  **General guidelines:**                                                                                        \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  - Use clear section headings (\u001b[1;35m## for sections, \u001b[0m\u001b[1;36m#\u001b[0m\u001b[1;36m## for subsections)\u001b[0m                                            \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  - Write in paragraph form by default - be text-heavy, not just bullet points                                   \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  - Do NOT use self-referential language (\"I found...\", \"I researched...\")                                       \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  - Write as a professional report without meta-commentary                                                       \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  - Each section should be comprehensive and detailed                                                            \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  - Use bullet points only when listing is more appropriate than prose                                           \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m                                                                                                                 \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  **Citation format:**                                                                                           \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  - Cite sources inline using [1], [2], [3] format                                                               \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  - Assign each unique URL a single citation number across ALL sub-agent findings                                \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  - End report with \u001b[1;36m#\u001b[0m\u001b[1;36m## Sources section listing each numbered source\u001b[0m                                             \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  - Number sources sequentially without gaps (1,2,3,4...)                                                        \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  - Format: [1] Source Title: URL (each on separate line for proper list rendering)                              \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  - Example:                                                                                                     \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m                                                                                                                 \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m    Some important finding [1]. Another key insight [2].                                                         \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m                                                                                                                 \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m    \u001b[1;36m#\u001b[0m\u001b[1;36m## Sources\u001b[0m                                                                                                  \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m    [1] AI Research Paper: https://example.com/paper                                                             \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m    [2] Industry Analysis: https://example.com/analysis                                                          \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m                                                                                                                 \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m                                                                                                                 \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  ================================================================================                               \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m                                                                                                                 \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  # Sub-Agent Research Coordination                                                                              \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m                                                                                                                 \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  Your role is to coordinate research by delegating tasks from your TODO list to specialized research            \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  sub-agents.                                                                                                    \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m                                                                                                                 \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  \u001b[1;35m## Delegation Strategy\u001b[0m                                                                                         \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m                                                                                                                 \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  **DEFAULT: Start with 1 sub-agent** for most queries:                                                          \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  - \"What is quantum computing?\" → 1 sub-agent (general overview)                                                \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  - \"List the top 10 coffee shops in San Francisco\" → 1 sub-agent                                                \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  - \"Summarize the history of the internet\" → 1 sub-agent                                                        \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  - \"Research context engineering for AI agents\" → 1 sub-agent (covers all aspects)                              \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m                                                                                                                 \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  **ONLY parallelize when the query EXPLICITLY requires comparison or has clearly independent aspects:**         \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m                                                                                                                 \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  **Explicit comparisons** → 1 sub-agent per element:                                                            \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  - \"Compare OpenAI vs Anthropic vs DeepMind AI safety approaches\" → 3 parallel sub-agents                       \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  - \"Compare Python vs JavaScript for web development\" → 2 parallel sub-agents                                   \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m                                                                                                                 \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  **Clearly separated aspects** → 1 sub-agent per aspect (use sparingly):                                        \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  - \"Research renewable energy adoption in Europe, Asia, and North America\" → 3 parallel sub-agents (geographic  \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  separation)                                                                                                    \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  - Only use this pattern when aspects cannot be covered efficiently by a single comprehensive search            \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m                                                                                                                 \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  \u001b[1;35m## Key Principles\u001b[0m                                                                                              \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  - **Bias towards single sub-agent**: One comprehensive research task is more token-efficient than multiple     \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  narrow ones                                                                                                    \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  - **Avoid premature decomposition**: Don't break \"research X\" into \"research X overview\", \"research X          \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  techniques\", \"research X applications\" - just use 1 sub-agent for all of X                                     \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  - **Parallelize only for clear comparisons**: Use multiple sub-agents when comparing distinct entities or      \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  geographically separated data                                                                                  \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m                                                                                                                 \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  \u001b[1;35m## Parallel Execution Limits\u001b[0m                                                                                   \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  - Use at most 3 parallel sub-agents per iteration                                                              \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  - Make multiple task() calls in a single response to enable parallel execution                                 \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  - Each sub-agent returns findings independently                                                                \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m                                                                                                                 \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  \u001b[1;35m## Research Limits\u001b[0m                                                                                             \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  - Stop after 3 delegation rounds if you haven't found adequate sources                                         \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  - Stop when you have sufficient information to answer comprehensively                                          \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  - Bias towards focused research over exhaustive exploration                                                    \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m                                                                                                                 \u001b[34m│\u001b[0m\n",
       "\u001b[34m╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯\u001b[0m\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Limits\n",
    "max_concurrent_research_units = 3\n",
    "max_researcher_iterations = 3\n",
    "\n",
    "# Combine orchestrator instructions (RESEARCHER_INSTRUCTIONS only for sub-agents)\n",
    "INSTRUCTIONS = (\n",
    "    RESEARCH_WORKFLOW_INSTRUCTIONS\n",
    "    + \"\\n\\n\"\n",
    "    + \"=\" * 80\n",
    "    + \"\\n\\n\"\n",
    "    +  SUBAGENT_DELEGATION_INSTRUCTIONS.format(\n",
    "        max_concurrent_research_units=max_concurrent_research_units,\n",
    "        max_researcher_iterations=max_researcher_iterations,\n",
    "    )\n",
    ")\n",
    "\n",
    "show_prompt(INSTRUCTIONS)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ab6e3639",
   "metadata": {},
   "source": [
    "### Create the agent\n",
    "\n",
    "Now, we create our deepagent with these components. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e979ff23-e36a-45b2-bd52-03cf4171f36c",
   "metadata": {},
   "outputs": [],
   "source": [
    "from IPython.display import Image, display\n",
    "from deepagents import create_deep_agent\n",
    "from langchain.chat_models import init_chat_model\n",
    "from langchain_google_genai import ChatGoogleGenerativeAI\n",
    "\n",
    "# Model Gemini 3 \n",
    "model = ChatGoogleGenerativeAI(model=\"gemini-3-pro-preview\")\n",
    "\n",
    "# Model Claude 4.5\n",
    "model = init_chat_model(model=\"anthropic:claude-sonnet-4-5-20250929\", temperature=0.0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "62da8411",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAVEAAAG/CAIAAABuWnPnAAAQAElEQVR4nOydBWAURxfHZ+/iToAQICGChQT3UlyLfWiBIkWLOxQrLsUpVqy4FddCkUIp7gS3kOAQJCGud/v97zY5juQkCbkkd/t+pNe9ldnZnfnPvPdmb9aM53lGEIRoMGMEQYgJ0jxBiAvSPEGIC9I8QYgL0jxBiAvSPEGIC9J8DiU0OO722U8fXifExch4GZeQKFes5RjjmdSMkycwnuOxIEtUDLVyEsbLmVTK5HKGsVdOyjG5YhBWIuE4jslkPP6HfeQyxc5SKSdTLkiQGsfJ5cplCYcjmHLcNsUylnh5Uq6kZhJZolzCmFztqyrPFhacRMpZ2UlcCllUqOdkYWnBiJwHR+PzOYrgF1HHN78L+yCDzMwtOAsriZkFJ5VKEuN5hdyhYCjZjCUm8JCzBOKH5jnlarliPS9Tal6i+GTKBYblRKbaB3BS5QKv2ITVvDy51VAeolxW1go+aWcsqGle0cqgucE/fE3KQDJSCz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U5s8J+Jj1LNr78rXc6rcMDfL2cjlTJ5o3H2laavepJ5VqN4ir5UNu3Qk2NLOvEhV05kYM+D8y9jIhGr/cypfR6STAmUxFLc3Jio2yIu/dVOC7h4PsnSwKFg6r7W1sf4KJSY6/vWt9zHh8baO0oG/FWEEkRmY5jOJ3Sd5Pb0XeXL7+ydnXnESZm5lZutkaeVoaW4tNTe34FRPrCqmRIEDmtSs83IJJ5ErVireV8apmnue5zjhDWZJmwQUw7hYjxVyxQ9reRyOdYo9eeXxymFeTjiE54R/co5XRFCwp0SOE8iFlLEo4THElZiQEB+dGB0WFx0WmxgnwxobR2mLvq7uxY3plZsSM8UEPsxo4U3ctDdRzQNPX7seUxRSObEt+OWjmKjQ6NDXGn7ZqtSthmWtu/Gfvb3Pi8lLqt1Sb2JyDQFTYX9e2agkNTIcMzPnrO0lhcra1fnelRkh8kQM0RuxdcyZuGlvuppXUa8DPaBKEJ+h3xsRmQycKc6YX+asML6Ykb9MWyekeSKTsbAy7uftzSwY4j7MdDHtWYCIbCBPAYuI0HhmnISFxcgSWNmaJvtDWkaaJzKdJj0Kxsfxzx8Zatoyg3Jy01tnVxM3fknzRObTfnih/7YH373wgRkVOxc9MTdnP4zyZCaNcc+TQ+RYQt7G71z4HAsW1pLEBM3uPfflE2+KZxX4pOcZUu35xUpOwvHCsw06a69EwslTzYbOpXpNDQZH5TJZXAxv6yjpOt6bmTqkecKAnPvrffDT2NjoNNUxQY2c/ldH8UrNKwYIdE+8p3EHLtWjtdC8lR0rVc3Jy8+eiQDSPEGICxqrIwhxQZonCHFBmicIcUGaJwhxQZonCHFBmicIcfF/AAAA//8RFCewAAAABklEQVQDAKxBehbhgw4JAAAAAElFTkSuQmCC",
      "text/plain": [
       "<IPython.core.display.Image object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Create the agent\n",
    "agent = create_deep_agent(\n",
    "      model=model,\n",
    "      tools=tools, \n",
    "      system_prompt=INSTRUCTIONS,\n",
    "      subagents=[research_sub_agent],\n",
    "  )\n",
    "  \n",
    "# Show the agent\n",
    "display(Image(agent.get_graph().draw_mermaid_png()))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "613634c2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #000080; text-decoration-color: #000080\">╭─────────────────────────────────────────────────── 🧑 Human ────────────────────────────────────────────────────╮</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span> research context engineering approaches used to build AI agents                                                 <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯</span>\n",
       "</pre>\n"
      ],
      "text/plain": [
       "\u001b[34m╭─\u001b[0m\u001b[34m──────────────────────────────────────────────────\u001b[0m\u001b[34m 🧑 Human \u001b[0m\u001b[34m───────────────────────────────────────────────────\u001b[0m\u001b[34m─╮\u001b[0m\n",
       "\u001b[34m│\u001b[0m research context engineering approaches used to build AI agents                                                 \u001b[34m│\u001b[0m\n",
       "\u001b[34m╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯\u001b[0m\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">╭───────────────────────────────────────────────────── 📝 AI ─────────────────────────────────────────────────────╮</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>                                                                                                                 <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> 🔧 Tool Call: write_todos                                                                                       <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>    Args: {                                                                                                      <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>   \"todos\": [                                                                                                    <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>     {                                                                                                           <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>       \"status\": \"in_progress\",                                                                                  <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>       \"content\": \"Save research request to /research_request.md\"                                                <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>     },                                                                                                          <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>     {                                                                                                           <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>       \"status\": \"pending\",                                                                                      <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>       \"content\": \"Research context engineering approaches for AI agents using a sub-agent\"                      <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>     },                                                                                                          <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>     {                                                                                                           <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>       \"status\": \"pending\",                                                                                      <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>       \"content\": \"Synthesize findings and write final report to /final_report.md\"                               <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>     },                                                                                                          <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>     {                                                                                                           <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>       \"status\": \"pending\",                                                                                      <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>       \"content\": \"Verify report against original request\"                                                       <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>     }                                                                                                           <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>   ]                                                                                                             <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> }                                                                                                               <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>    ID: 61820e98-a91b-4f74-ac2c-f443af11d389                                                                     <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>                                                                                                                 <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> 🔧 Tool Call: write_file                                                                                        <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>    Args: {                                                                                                      <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>   \"file_path\": \"/research_request.md\",                                                                          <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>   \"content\": \"research context engineering approaches used to build AI agents\"                                  <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> }                                                                                                               <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>    ID: 3a5e0fbf-0181-4d89-9501-c5fac4b3cef2                                                                     <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯</span>\n",
       "</pre>\n"
      ],
      "text/plain": [
       "\u001b[37m╭─\u001b[0m\u001b[37m────────────────────────────────────────────────────\u001b[0m\u001b[37m 📝 AI \u001b[0m\u001b[37m────────────────────────────────────────────────────\u001b[0m\u001b[37m─╮\u001b[0m\n",
       "\u001b[37m│\u001b[0m                                                                                                                 \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m 🔧 Tool Call: write_todos                                                                                       \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m    Args: {                                                                                                      \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m   \"todos\": [                                                                                                    \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m     {                                                                                                           \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m       \"status\": \"in_progress\",                                                                                  \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m       \"content\": \"Save research request to /research_request.md\"                                                \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m     },                                                                                                          \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m     {                                                                                                           \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m       \"status\": \"pending\",                                                                                      \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m       \"content\": \"Research context engineering approaches for AI agents using a sub-agent\"                      \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m     },                                                                                                          \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m     {                                                                                                           \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m       \"status\": \"pending\",                                                                                      \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m       \"content\": \"Synthesize findings and write final report to /final_report.md\"                               \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m     },                                                                                                          \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m     {                                                                                                           \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m       \"status\": \"pending\",                                                                                      \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m       \"content\": \"Verify report against original request\"                                                       \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m     }                                                                                                           \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m   ]                                                                                                             \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m }                                                                                                               \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m    ID: 61820e98-a91b-4f74-ac2c-f443af11d389                                                                     \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m                                                                                                                 \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m 🔧 Tool Call: write_file                                                                                        \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m    Args: {                                                                                                      \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m   \"file_path\": \"/research_request.md\",                                                                          \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m   \"content\": \"research context engineering approaches used to build AI agents\"                                  \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m }                                                                                                               \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m    ID: 3a5e0fbf-0181-4d89-9501-c5fac4b3cef2                                                                     \u001b[37m│\u001b[0m\n",
       "\u001b[37m╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯\u001b[0m\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #808000; text-decoration-color: #808000\">╭──────────────────────────────────────────────── 🔧 Tool Output ─────────────────────────────────────────────────╮</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> Updated todo list to [{'content': 'Save research request to /research_request.md', 'status': 'in_progress'},    <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> {'content': 'Research context engineering approaches for AI agents using a sub-agent', 'status': 'pending'},    <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> {'content': 'Synthesize findings and write final report to /final_report.md', 'status': 'pending'}, {'content': <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> 'Verify report against original request', 'status': 'pending'}]                                                 <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯</span>\n",
       "</pre>\n"
      ],
      "text/plain": [
       "\u001b[33m╭─\u001b[0m\u001b[33m───────────────────────────────────────────────\u001b[0m\u001b[33m 🔧 Tool Output \u001b[0m\u001b[33m────────────────────────────────────────────────\u001b[0m\u001b[33m─╮\u001b[0m\n",
       "\u001b[33m│\u001b[0m Updated todo list to [{'content': 'Save research request to /research_request.md', 'status': 'in_progress'},    \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m {'content': 'Research context engineering approaches for AI agents using a sub-agent', 'status': 'pending'},    \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m {'content': 'Synthesize findings and write final report to /final_report.md', 'status': 'pending'}, {'content': \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m 'Verify report against original request', 'status': 'pending'}]                                                 \u001b[33m│\u001b[0m\n",
       "\u001b[33m╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯\u001b[0m\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #808000; text-decoration-color: #808000\">╭──────────────────────────────────────────────── 🔧 Tool Output ─────────────────────────────────────────────────╮</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> Updated file /research_request.md                                                                               <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯</span>\n",
       "</pre>\n"
      ],
      "text/plain": [
       "\u001b[33m╭─\u001b[0m\u001b[33m───────────────────────────────────────────────\u001b[0m\u001b[33m 🔧 Tool Output \u001b[0m\u001b[33m────────────────────────────────────────────────\u001b[0m\u001b[33m─╮\u001b[0m\n",
       "\u001b[33m│\u001b[0m Updated file /research_request.md                                                                               \u001b[33m│\u001b[0m\n",
       "\u001b[33m╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯\u001b[0m\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">╭───────────────────────────────────────────────────── 📝 AI ─────────────────────────────────────────────────────╮</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>                                                                                                                 <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> 🔧 Tool Call: write_todos                                                                                       <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>    Args: {                                                                                                      <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>   \"todos\": [                                                                                                    <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>     {                                                                                                           <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>       \"status\": \"completed\",                                                                                    <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>       \"content\": \"Save research request to /research_request.md\"                                                <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>     },                                                                                                          <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>     {                                                                                                           <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>       \"status\": \"in_progress\",                                                                                  <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>       \"content\": \"Research context engineering approaches for AI agents using a sub-agent\"                      <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>     },                                                                                                          <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>     {                                                                                                           <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>       \"status\": \"pending\",                                                                                      <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>       \"content\": \"Synthesize findings and write final report to /final_report.md\"                               <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>     },                                                                                                          <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>     {                                                                                                           <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>       \"status\": \"pending\",                                                                                      <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>       \"content\": \"Verify report against original request\"                                                       <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>     }                                                                                                           <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>   ]                                                                                                             <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> }                                                                                                               <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>    ID: b317fa1b-6f81-47df-b0ca-aa5e50bd2b70                                                                     <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>                                                                                                                 <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> 🔧 Tool Call: task                                                                                              <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>    Args: {                                                                                                      <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>   \"subagent_type\": \"research-agent\",                                                                            <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>   \"description\": \"Research context engineering approaches used to build AI agents.\\nFocus on:\\n1. Definition    <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> and core concepts of context engineering.\\n2. Key techniques and strategies (e.g., dynamic context injection,   <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> RAG, memory management/history pruning, summarization, prompt structuring).\\n3. Architectures or frameworks     <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> often used (e.g., how LangChain or LlamaIndex handle context).\\n4. Approaches for handling context window       <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> limits vs. utilizing long-context models.\\n5. Specific patterns like \\\"Needle in a Haystack\\\" optimization or   <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> \\\"Context Stuffing\\\" vs \\\"Context Selection\\\".\\n\\nReturn a comprehensive summary of findings with citations.\"   <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> }                                                                                                               <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>    ID: b682976a-b1fa-47a1-89be-153134ba28c7                                                                     <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯</span>\n",
       "</pre>\n"
      ],
      "text/plain": [
       "\u001b[37m╭─\u001b[0m\u001b[37m────────────────────────────────────────────────────\u001b[0m\u001b[37m 📝 AI \u001b[0m\u001b[37m────────────────────────────────────────────────────\u001b[0m\u001b[37m─╮\u001b[0m\n",
       "\u001b[37m│\u001b[0m                                                                                                                 \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m 🔧 Tool Call: write_todos                                                                                       \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m    Args: {                                                                                                      \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m   \"todos\": [                                                                                                    \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m     {                                                                                                           \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m       \"status\": \"completed\",                                                                                    \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m       \"content\": \"Save research request to /research_request.md\"                                                \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m     },                                                                                                          \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m     {                                                                                                           \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m       \"status\": \"in_progress\",                                                                                  \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m       \"content\": \"Research context engineering approaches for AI agents using a sub-agent\"                      \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m     },                                                                                                          \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m     {                                                                                                           \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m       \"status\": \"pending\",                                                                                      \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m       \"content\": \"Synthesize findings and write final report to /final_report.md\"                               \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m     },                                                                                                          \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m     {                                                                                                           \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m       \"status\": \"pending\",                                                                                      \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m       \"content\": \"Verify report against original request\"                                                       \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m     }                                                                                                           \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m   ]                                                                                                             \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m }                                                                                                               \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m    ID: b317fa1b-6f81-47df-b0ca-aa5e50bd2b70                                                                     \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m                                                                                                                 \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m 🔧 Tool Call: task                                                                                              \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m    Args: {                                                                                                      \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m   \"subagent_type\": \"research-agent\",                                                                            \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m   \"description\": \"Research context engineering approaches used to build AI agents.\\nFocus on:\\n1. Definition    \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m and core concepts of context engineering.\\n2. Key techniques and strategies (e.g., dynamic context injection,   \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m RAG, memory management/history pruning, summarization, prompt structuring).\\n3. Architectures or frameworks     \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m often used (e.g., how LangChain or LlamaIndex handle context).\\n4. Approaches for handling context window       \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m limits vs. utilizing long-context models.\\n5. Specific patterns like \\\"Needle in a Haystack\\\" optimization or   \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m \\\"Context Stuffing\\\" vs \\\"Context Selection\\\".\\n\\nReturn a comprehensive summary of findings with citations.\"   \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m }                                                                                                               \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m    ID: b682976a-b1fa-47a1-89be-153134ba28c7                                                                     \u001b[37m│\u001b[0m\n",
       "\u001b[37m╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯\u001b[0m\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #808000; text-decoration-color: #808000\">╭──────────────────────────────────────────────── 🔧 Tool Output ─────────────────────────────────────────────────╮</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> Updated todo list to [{'content': 'Save research request to /research_request.md', 'status': 'completed'},      <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> {'content': 'Research context engineering approaches for AI agents using a sub-agent', 'status':                <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> 'in_progress'}, {'content': 'Synthesize findings and write final report to /final_report.md', 'status':         <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> 'pending'}, {'content': 'Verify report against original request', 'status': 'pending'}]                         <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯</span>\n",
       "</pre>\n"
      ],
      "text/plain": [
       "\u001b[33m╭─\u001b[0m\u001b[33m───────────────────────────────────────────────\u001b[0m\u001b[33m 🔧 Tool Output \u001b[0m\u001b[33m────────────────────────────────────────────────\u001b[0m\u001b[33m─╮\u001b[0m\n",
       "\u001b[33m│\u001b[0m Updated todo list to [{'content': 'Save research request to /research_request.md', 'status': 'completed'},      \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m {'content': 'Research context engineering approaches for AI agents using a sub-agent', 'status':                \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m 'in_progress'}, {'content': 'Synthesize findings and write final report to /final_report.md', 'status':         \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m 'pending'}, {'content': 'Verify report against original request', 'status': 'pending'}]                         \u001b[33m│\u001b[0m\n",
       "\u001b[33m╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯\u001b[0m\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #808000; text-decoration-color: #808000\">╭──────────────────────────────────────────────── 🔧 Tool Output ─────────────────────────────────────────────────╮</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> Context engineering is the systematic practice of designing, managing, and optimizing the information provided  <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> to AI models to ensure accurate, consistent, and context-aware behavior. It moves beyond simple prompt          <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> engineering by treating context as a dynamic resource that must be architected, managed, and validated.         <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span>                                                                                                                 <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> ### 1. Definition and Core Concepts                                                                             <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> **Context Engineering** is the \"process of designing, testing, and iterating on the contextual information      <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> provided to AI agents to shape their behavior and improve task performance\" [1]. Unlike a static prompt,        <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> context in an agentic system is a living state that changes with every user interaction, tool output, and       <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> internal reasoning step.                                                                                        <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span>                                                                                                                 <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> *   **Core Concepts**:                                                                                          <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span>     *   **Context Window**: The working memory limit of the LLM (e.g., 128k tokens). Managing this finite       <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> resource is the central challenge.                                                                              <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span>     *   **State Management**: Tracking the \"world state\" (user intent, task progress, tool results) across a    <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> multi-turn conversation.                                                                                        <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span>     *   **Context Pollution**: The degradation of model performance caused by irrelevant or contradictory       <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> information in the context [2].                                                                                 <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span>     *   **Context Continuity**: Ensuring the agent retains critical information (like user constraints)         <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> throughout a long interaction without \"forgetting\" them due to truncation.                                      <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span>                                                                                                                 <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> ### 2. Key Techniques and Strategies                                                                            <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> Effective context engineering employs a mix of retrieval, summarization, and structural strategies:             <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span>                                                                                                                 <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> *   **Dynamic Context Injection**: Instead of loading all data at once, agents \"pull\" information only when     <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> needed. For example, an agent might use a `search_tool` to inject real-time web results into the context only   <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> after identifying a knowledge gap [2].                                                                          <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> *   **Retrieval-Augmented Generation (RAG)**: A standard pattern for handling large knowledge bases. The agent  <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> retrieves strictly relevant chunks (e.g., top-5 matches) from a vector database to populate the context window, <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> rather than stuffing the entire document [2, 3].                                                                <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> *   **Memory Management**:                                                                                      <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span>     *   **Short-term Memory**: Stores immediate conversation history (e.g., last 10 turns).                     <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span>     *   **Long-term Memory**: Persists key facts (e.g., \"User is a vegetarian\") in an external database         <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> (Postgres, Vector Store) and retrieves them only when relevant [2].                                             <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span>     *   **Pruning/Trimming**: Algorithms that remove older, less relevant tokens to free up space while         <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> preserving recent interactions [2].                                                                             <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> *   **Summarization**: Compressing verbose tool outputs. Instead of feeding raw HTML from a scraped website, an <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> intermediate \"summarizer agent\" distills it into key points before passing it to the main agent [2].            <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> *   **Prompt Structuring**: Using structured formats (like JSON schemas or XML tags) within the context to      <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> clearly separate \"System Instructions,\" \"User Input,\" and \"Tool Outputs,\" preventing the model from confusing   <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> data with instructions.                                                                                         <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span>                                                                                                                 <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> ### 3. Architectures and Frameworks                                                                             <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> Two primary frameworks dominate the landscape, each with distinct approaches to context handling:               <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span>                                                                                                                 <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> | Feature | **LangChain** [3, 4] | **LlamaIndex** [3, 4] |                                                      <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> | :--- | :--- | :--- |                                                                                          <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> | **Primary Focus** | Flexible workflow &amp; agent orchestration | Data indexing &amp; advanced retrieval (RAG) |      <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> | **Memory Classes** | `ConversationBufferMemory` (raw history)&lt;br&gt;`ConversationSummaryMemory` (LLM-summarized  <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> history)&lt;br&gt;`ChatMessageHistory` (storage backend) | `ChatEngine` with modes:&lt;br&gt;`context` (standard            <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> RAG)&lt;br&gt;`condense_question` (rewrites queries based on history) |                                               <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> | **Context Strategy** | **Chains**: Sequential passing of context between steps.&lt;br&gt;**Agents**: Dynamic tool   <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> selection to populate context. | **Indices**: `VectorStoreIndex` (semantic search), `ListIndex` (sequential),   <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> `TreeIndex` (hierarchical summaries). |                                                                         <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> | **Optimization** | `Context Compression`: Removing irrelevant tokens from retrieved docs. | `Response         <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> Synthesizers`: &lt;br&gt;`compact` (stuffs max chunks into prompt)&lt;br&gt;`tree_summarize` (hierarchical reduction) |     <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span>                                                                                                                 <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> ### 4. Handling Context Limits vs. Long-Context Models                                                          <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> A critical architectural decision is whether to use RAG or rely on massive context windows (e.g., Gemini 1.5    <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> Pro's 2M tokens).                                                                                               <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span>                                                                                                                 <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> *   **RAG + Small Context**:                                                                                    <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span>     *   **Pros**: Significantly cheaper (fewer tokens processed), lower latency, and often higher accuracy for  <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> specific fact retrieval.                                                                                        <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span>     *   **Cons**: Can miss \"global\" insights that require reading the entire corpus at once.                    <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> *   **Long-Context Models (LCW)**:                                                                              <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span>     *   **Pros**: Can ingest entire books or codebases, enabling \"whole-document\" reasoning.                    <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span>     *   **Cons**: \"Lost in the Middle\" phenomenon where models forget information in the middle of a massive    <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> context.                                                                                                        <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span>     *   **Trade-off**: Benchmarks show that RAG systems often outperform LCW models in \"Needle in a Haystack\"   <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> tests for large corpora (2M+ tokens) because they filter noise before the model sees it [3].                    <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span>                                                                                                                 <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> ### 5. Specific Patterns                                                                                        <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> *   **Needle in a Haystack Optimization**:                                                                      <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span>     *   **The Problem**: LLMs struggle to find a specific fact (\"needle\") buried in a large amount of           <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> irrelevant text (\"haystack\").                                                                                   <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span>     *   **Optimization**: Place critical instructions or facts at the very **beginning** or very **end** of the <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> context window, as models pay most attention to these areas (Serial Position Effect).                           <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> *   **Context Stuffing vs. Context Selection**:                                                                 <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span>     *   **Context Stuffing**: Naively filling the window with as much data as possible. This often leads to     <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> *context distraction* and higher costs [2].                                                                     <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span>     *   **Context Selection**: Intentionally curating what enters the window.                                   <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span>         *   *Techniques*: Using **Node Postprocessors** (LlamaIndex) to filter retrieved nodes by keywords or   <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> similarity score before they reach the LLM [4].                                                                 <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span>         *   *Query Transformations*: Rewriting a user's vague query into a precise search term to select better <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> context (e.g., LangChain's `HyDE` or LlamaIndex's `Multi-step query decomposition`) [4].                        <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span>                                                                                                                 <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> ### Sources                                                                                                     <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> [1] Context Engineering Guide: https://www.promptingguide.ai/agents/context-engineering                         <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> [2] Context Engineering Strategies (n8n):                                                                       <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> https://www.theaiautomators.com/context-engineering-strategies-to-build-better-ai-agents/                       <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> [3] RAG vs Long Context Window Study:                                                                           <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> https://www.legionintel.com/blog/rag-systems-vs-lcw-performance-and-cost-trade-offs                             <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> [4] LangChain &amp; LlamaIndex Comparison:                                                                          <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> https://medium.com/badal-io/exploring-langchain-and-llamaindex-to-achieve-standardization-and-interoperability- <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> in-large-2b5f3fabc360                                                                                           <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯</span>\n",
       "</pre>\n"
      ],
      "text/plain": [
       "\u001b[33m╭─\u001b[0m\u001b[33m───────────────────────────────────────────────\u001b[0m\u001b[33m 🔧 Tool Output \u001b[0m\u001b[33m────────────────────────────────────────────────\u001b[0m\u001b[33m─╮\u001b[0m\n",
       "\u001b[33m│\u001b[0m Context engineering is the systematic practice of designing, managing, and optimizing the information provided  \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m to AI models to ensure accurate, consistent, and context-aware behavior. It moves beyond simple prompt          \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m engineering by treating context as a dynamic resource that must be architected, managed, and validated.         \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m                                                                                                                 \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m ### 1. Definition and Core Concepts                                                                             \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m **Context Engineering** is the \"process of designing, testing, and iterating on the contextual information      \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m provided to AI agents to shape their behavior and improve task performance\" [1]. Unlike a static prompt,        \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m context in an agentic system is a living state that changes with every user interaction, tool output, and       \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m internal reasoning step.                                                                                        \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m                                                                                                                 \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m *   **Core Concepts**:                                                                                          \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m     *   **Context Window**: The working memory limit of the LLM (e.g., 128k tokens). Managing this finite       \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m resource is the central challenge.                                                                              \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m     *   **State Management**: Tracking the \"world state\" (user intent, task progress, tool results) across a    \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m multi-turn conversation.                                                                                        \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m     *   **Context Pollution**: The degradation of model performance caused by irrelevant or contradictory       \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m information in the context [2].                                                                                 \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m     *   **Context Continuity**: Ensuring the agent retains critical information (like user constraints)         \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m throughout a long interaction without \"forgetting\" them due to truncation.                                      \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m                                                                                                                 \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m ### 2. Key Techniques and Strategies                                                                            \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m Effective context engineering employs a mix of retrieval, summarization, and structural strategies:             \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m                                                                                                                 \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m *   **Dynamic Context Injection**: Instead of loading all data at once, agents \"pull\" information only when     \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m needed. For example, an agent might use a `search_tool` to inject real-time web results into the context only   \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m after identifying a knowledge gap [2].                                                                          \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m *   **Retrieval-Augmented Generation (RAG)**: A standard pattern for handling large knowledge bases. The agent  \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m retrieves strictly relevant chunks (e.g., top-5 matches) from a vector database to populate the context window, \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m rather than stuffing the entire document [2, 3].                                                                \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m *   **Memory Management**:                                                                                      \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m     *   **Short-term Memory**: Stores immediate conversation history (e.g., last 10 turns).                     \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m     *   **Long-term Memory**: Persists key facts (e.g., \"User is a vegetarian\") in an external database         \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m (Postgres, Vector Store) and retrieves them only when relevant [2].                                             \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m     *   **Pruning/Trimming**: Algorithms that remove older, less relevant tokens to free up space while         \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m preserving recent interactions [2].                                                                             \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m *   **Summarization**: Compressing verbose tool outputs. Instead of feeding raw HTML from a scraped website, an \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m intermediate \"summarizer agent\" distills it into key points before passing it to the main agent [2].            \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m *   **Prompt Structuring**: Using structured formats (like JSON schemas or XML tags) within the context to      \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m clearly separate \"System Instructions,\" \"User Input,\" and \"Tool Outputs,\" preventing the model from confusing   \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m data with instructions.                                                                                         \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m                                                                                                                 \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m ### 3. Architectures and Frameworks                                                                             \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m Two primary frameworks dominate the landscape, each with distinct approaches to context handling:               \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m                                                                                                                 \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m | Feature | **LangChain** [3, 4] | **LlamaIndex** [3, 4] |                                                      \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m | :--- | :--- | :--- |                                                                                          \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m | **Primary Focus** | Flexible workflow & agent orchestration | Data indexing & advanced retrieval (RAG) |      \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m | **Memory Classes** | `ConversationBufferMemory` (raw history)<br>`ConversationSummaryMemory` (LLM-summarized  \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m history)<br>`ChatMessageHistory` (storage backend) | `ChatEngine` with modes:<br>`context` (standard            \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m RAG)<br>`condense_question` (rewrites queries based on history) |                                               \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m | **Context Strategy** | **Chains**: Sequential passing of context between steps.<br>**Agents**: Dynamic tool   \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m selection to populate context. | **Indices**: `VectorStoreIndex` (semantic search), `ListIndex` (sequential),   \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m `TreeIndex` (hierarchical summaries). |                                                                         \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m | **Optimization** | `Context Compression`: Removing irrelevant tokens from retrieved docs. | `Response         \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m Synthesizers`: <br>`compact` (stuffs max chunks into prompt)<br>`tree_summarize` (hierarchical reduction) |     \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m                                                                                                                 \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m ### 4. Handling Context Limits vs. Long-Context Models                                                          \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m A critical architectural decision is whether to use RAG or rely on massive context windows (e.g., Gemini 1.5    \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m Pro's 2M tokens).                                                                                               \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m                                                                                                                 \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m *   **RAG + Small Context**:                                                                                    \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m     *   **Pros**: Significantly cheaper (fewer tokens processed), lower latency, and often higher accuracy for  \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m specific fact retrieval.                                                                                        \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m     *   **Cons**: Can miss \"global\" insights that require reading the entire corpus at once.                    \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m *   **Long-Context Models (LCW)**:                                                                              \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m     *   **Pros**: Can ingest entire books or codebases, enabling \"whole-document\" reasoning.                    \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m     *   **Cons**: \"Lost in the Middle\" phenomenon where models forget information in the middle of a massive    \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m context.                                                                                                        \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m     *   **Trade-off**: Benchmarks show that RAG systems often outperform LCW models in \"Needle in a Haystack\"   \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m tests for large corpora (2M+ tokens) because they filter noise before the model sees it [3].                    \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m                                                                                                                 \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m ### 5. Specific Patterns                                                                                        \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m *   **Needle in a Haystack Optimization**:                                                                      \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m     *   **The Problem**: LLMs struggle to find a specific fact (\"needle\") buried in a large amount of           \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m irrelevant text (\"haystack\").                                                                                   \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m     *   **Optimization**: Place critical instructions or facts at the very **beginning** or very **end** of the \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m context window, as models pay most attention to these areas (Serial Position Effect).                           \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m *   **Context Stuffing vs. Context Selection**:                                                                 \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m     *   **Context Stuffing**: Naively filling the window with as much data as possible. This often leads to     \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m *context distraction* and higher costs [2].                                                                     \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m     *   **Context Selection**: Intentionally curating what enters the window.                                   \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m         *   *Techniques*: Using **Node Postprocessors** (LlamaIndex) to filter retrieved nodes by keywords or   \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m similarity score before they reach the LLM [4].                                                                 \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m         *   *Query Transformations*: Rewriting a user's vague query into a precise search term to select better \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m context (e.g., LangChain's `HyDE` or LlamaIndex's `Multi-step query decomposition`) [4].                        \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m                                                                                                                 \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m ### Sources                                                                                                     \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m [1] Context Engineering Guide: https://www.promptingguide.ai/agents/context-engineering                         \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m [2] Context Engineering Strategies (n8n):                                                                       \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m https://www.theaiautomators.com/context-engineering-strategies-to-build-better-ai-agents/                       \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m [3] RAG vs Long Context Window Study:                                                                           \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m https://www.legionintel.com/blog/rag-systems-vs-lcw-performance-and-cost-trade-offs                             \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m [4] LangChain & LlamaIndex Comparison:                                                                          \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m https://medium.com/badal-io/exploring-langchain-and-llamaindex-to-achieve-standardization-and-interoperability- \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m in-large-2b5f3fabc360                                                                                           \u001b[33m│\u001b[0m\n",
       "\u001b[33m╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯\u001b[0m\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">╭───────────────────────────────────────────────────── 📝 AI ─────────────────────────────────────────────────────╮</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>                                                                                                                 <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> 🔧 Tool Call: write_todos                                                                                       <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>    Args: {                                                                                                      <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>   \"todos\": [                                                                                                    <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>     {                                                                                                           <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>       \"status\": \"completed\",                                                                                    <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>       \"content\": \"Save research request to /research_request.md\"                                                <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>     },                                                                                                          <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>     {                                                                                                           <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>       \"status\": \"completed\",                                                                                    <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>       \"content\": \"Research context engineering approaches for AI agents using a sub-agent\"                      <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>     },                                                                                                          <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>     {                                                                                                           <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>       \"status\": \"in_progress\",                                                                                  <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>       \"content\": \"Synthesize findings and write final report to /final_report.md\"                               <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>     },                                                                                                          <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>     {                                                                                                           <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>       \"status\": \"pending\",                                                                                      <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>       \"content\": \"Verify report against original request\"                                                       <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>     }                                                                                                           <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>   ]                                                                                                             <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> }                                                                                                               <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>    ID: ea8aeaae-7e6a-4f8b-beba-1f252efabd24                                                                     <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>                                                                                                                 <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> 🔧 Tool Call: write_file                                                                                        <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>    Args: {                                                                                                      <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>   \"file_path\": \"/final_report.md\",                                                                              <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>   \"content\": \"# Context Engineering Approaches for AI Agents\\n\\n## 1. Introduction\\nContext Engineering is the  <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> systematic practice of designing, managing, and optimizing the information provided to AI models to ensure      <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> accurate, consistent, and context-aware behavior. While often confused with prompt engineering (which focuses   <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> on static instructions), context engineering treats the AI's context window as a dynamic, finite resource that  <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> must be architected and managed throughout the lifecycle of an interaction. It is a critical discipline for     <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> building robust AI agents that can maintain state and relevance over long, complex tasks.\\n\\n## 2. Core         <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> Concepts\\nTo build effective agents, developers must manage several fundamental aspects of the Large Language   <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> Model (LLM) environment:\\n\\n*   **Context Window**: The hard limit on the amount of text (tokens) an LLM can    <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> process at once (e.g., 8k, 128k, or 1M tokens). Effective engineering ensures this space is used                <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> efficiently.\\n*   **State Management**: Tracking the \\\"world state\\\" across multi-turn conversations. This      <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> includes user intent, task progress, and tool outputs.\\n*   **Context Pollution**: The phenomenon where         <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> irrelevant or contradictory information in the context degrades model performance, leading to hallucinations or <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> confusion [2].\\n*   **Serial Position Effect**: The tendency of LLMs to pay more attention to information at    <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> the very beginning and very end of the context window, often ignoring details buried in the middle (\\\"Lost in   <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> the Middle\\\") [3].\\n\\n## 3. Key Approaches and Techniques\\n\\n### Dynamic Context Injection &amp; Retrieval          <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> (RAG)\\nRather than loading all available data at once, agents \\\"pull\\\" information only when necessary.\\n*      <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> **Dynamic Injection**: Agents use tools (like search APIs or database queries) to fetch real-time data only     <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> after identifying a specific knowledge gap [2].\\n*   **RAG (Retrieval-Augmented Generation)**: The standard for <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> large knowledge bases. Instead of \\\"stuffing\\\" a document, the system retrieves only the top-k most relevant    <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> chunks from a vector store to populate the context [2][3].\\n\\n### Memory Management\\nAgents require             <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> sophisticated memory systems to maintain continuity without overflowing context limits:\\n*   **Short-term       <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> Memory**: A sliding window of the most recent interaction turns (e.g., last 10 messages).\\n*   **Long-term      <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> Memory**: Key facts (e.g., user preferences) are persisted in external databases (Postgres, Vector Stores) and  <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> retrieved only when relevant to the current query [2].\\n*   **Pruning and Trimming**: Algorithms that           <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> selectively remove older, less relevant tokens while preserving the semantic core of the conversation           <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> history.\\n\\n### Summarization and Compression\\n*   **Tool Output Summarization**: Raw outputs from tools (like  <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> HTML from a web scraper) are often too verbose. An intermediate step or \\\"summarizer agent\\\" distills this data <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> into key points before passing it to the main reasoning agent [2].\\n*   **Context Compression**: Removing stop  <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> words or irrelevant sections from retrieved documents to maximize information density per token.\\n\\n### Prompt  <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> Structuring\\nUsing strict formats within the context window helps the model parse information correctly:\\n*     <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> **Separation of Concerns**: Clearly formatting \\\"System Instructions,\\\" \\\"User Input,\\\" and \\\"Tool Outputs\\\"    <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> (often using XML tags or JSON schemas) prevents the model from confusing data with instructions.\\n\\n## 4.       <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> Architectural Frameworks\\nTwo primary frameworks dominate the implementation of these                           <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> strategies:\\n\\n**LangChain**\\n*   **Focus**: Flexible orchestration and agent workflows.\\n*   **Approach**:     <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> Uses \\\"Chains\\\" to pass context sequentially between steps and \\\"Memory\\\" classes (e.g.,                        <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> `ConversationSummaryMemory`) to automatically manage history compression and persistence [4].\\n*                <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> **Strategy**: Emphasizes dynamic tool selection where the agent decides what information to add to its own      <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> context.\\n\\n**LlamaIndex**\\n*   **Focus**: Data indexing and advanced retrieval.\\n*   **Approach**: specialized <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> in structuring data for LLMs using indices (`VectorStoreIndex`, `TreeIndex`).\\n*   **Strategy**: Uses           <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> \\\"Response Synthesizers\\\" to optimize how retrieved context is presented to the LLM (e.g., `compact` mode to    <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> stuff chunks or `tree_summarize` for hierarchical reduction) [4].\\n\\n## 5. Strategic Patterns\\n\\n### RAG vs.    <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> Long-Context Windows (LCW)\\n*   **RAG**: Preferred for cost efficiency and low latency. It filters noise before <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> the model sees it, often resulting in higher accuracy for \\\"Needle in a Haystack\\\" retrieval tasks [3].\\n*      <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> **Long-Context Models (e.g., Gemini 1.5)**: Best for \\\"whole-document\\\" reasoning where global context is       <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> required. However, they are more expensive and prone to the \\\"Lost in the Middle\\\" effect.\\n\\n### Context       <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> Selection vs. Stuffing\\n*   **Context Stuffing**: Naively filling the window with all available data. This is   <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> generally an anti-pattern as it increases costs and distracts the model.\\n*   **Context Selection**: The        <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> proactive curation of inputs. Techniques include \\\"Node Postprocessors\\\" (filtering results by similarity       <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> score) and \\\"Query Transformations\\\" (rewriting vague user queries to fetch better context) [4].\\n\\n## 6.       <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> Conclusion\\nContext engineering is the bridge between raw data and intelligent agent behavior. By moving from   <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> naive context stuffing to sophisticated dynamic injection, memory management, and structured retrieval,         <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> developers can build agents that are both powerful and cost-effective. The choice between RAG architectures and <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> long-context models remains a key trade-off, with hybrid approaches often providing the best balance of         <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> accuracy and performance.\\n\\n### Sources\\n[1] Context Engineering Guide:                                        <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> https://www.promptingguide.ai/agents/context-engineering\\n[2] Context Engineering Strategies (n8n):             <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> https://www.theaiautomators.com/context-engineering-strategies-to-build-better-ai-agents/\\n[3] RAG vs Long      <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> Context Window Study: https://www.legionintel.com/blog/rag-systems-vs-lcw-performance-and-cost-trade-offs\\n[4]  <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> LangChain &amp; LlamaIndex Comparison:                                                                              <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> https://medium.com/badal-io/exploring-langchain-and-llamaindex-to-achieve-standardization-and-interoperability- <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> in-large-2b5f3fabc366\"                                                                                          <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> }                                                                                                               <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>    ID: 589357a0-fbce-4941-9090-8f91d12880cb                                                                     <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯</span>\n",
       "</pre>\n"
      ],
      "text/plain": [
       "\u001b[37m╭─\u001b[0m\u001b[37m────────────────────────────────────────────────────\u001b[0m\u001b[37m 📝 AI \u001b[0m\u001b[37m────────────────────────────────────────────────────\u001b[0m\u001b[37m─╮\u001b[0m\n",
       "\u001b[37m│\u001b[0m                                                                                                                 \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m 🔧 Tool Call: write_todos                                                                                       \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m    Args: {                                                                                                      \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m   \"todos\": [                                                                                                    \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m     {                                                                                                           \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m       \"status\": \"completed\",                                                                                    \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m       \"content\": \"Save research request to /research_request.md\"                                                \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m     },                                                                                                          \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m     {                                                                                                           \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m       \"status\": \"completed\",                                                                                    \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m       \"content\": \"Research context engineering approaches for AI agents using a sub-agent\"                      \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m     },                                                                                                          \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m     {                                                                                                           \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m       \"status\": \"in_progress\",                                                                                  \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m       \"content\": \"Synthesize findings and write final report to /final_report.md\"                               \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m     },                                                                                                          \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m     {                                                                                                           \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m       \"status\": \"pending\",                                                                                      \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m       \"content\": \"Verify report against original request\"                                                       \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m     }                                                                                                           \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m   ]                                                                                                             \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m }                                                                                                               \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m    ID: ea8aeaae-7e6a-4f8b-beba-1f252efabd24                                                                     \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m                                                                                                                 \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m 🔧 Tool Call: write_file                                                                                        \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m    Args: {                                                                                                      \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m   \"file_path\": \"/final_report.md\",                                                                              \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m   \"content\": \"# Context Engineering Approaches for AI Agents\\n\\n## 1. Introduction\\nContext Engineering is the  \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m systematic practice of designing, managing, and optimizing the information provided to AI models to ensure      \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m accurate, consistent, and context-aware behavior. While often confused with prompt engineering (which focuses   \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m on static instructions), context engineering treats the AI's context window as a dynamic, finite resource that  \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m must be architected and managed throughout the lifecycle of an interaction. It is a critical discipline for     \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m building robust AI agents that can maintain state and relevance over long, complex tasks.\\n\\n## 2. Core         \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m Concepts\\nTo build effective agents, developers must manage several fundamental aspects of the Large Language   \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m Model (LLM) environment:\\n\\n*   **Context Window**: The hard limit on the amount of text (tokens) an LLM can    \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m process at once (e.g., 8k, 128k, or 1M tokens). Effective engineering ensures this space is used                \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m efficiently.\\n*   **State Management**: Tracking the \\\"world state\\\" across multi-turn conversations. This      \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m includes user intent, task progress, and tool outputs.\\n*   **Context Pollution**: The phenomenon where         \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m irrelevant or contradictory information in the context degrades model performance, leading to hallucinations or \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m confusion [2].\\n*   **Serial Position Effect**: The tendency of LLMs to pay more attention to information at    \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m the very beginning and very end of the context window, often ignoring details buried in the middle (\\\"Lost in   \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m the Middle\\\") [3].\\n\\n## 3. Key Approaches and Techniques\\n\\n### Dynamic Context Injection & Retrieval          \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m (RAG)\\nRather than loading all available data at once, agents \\\"pull\\\" information only when necessary.\\n*      \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m **Dynamic Injection**: Agents use tools (like search APIs or database queries) to fetch real-time data only     \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m after identifying a specific knowledge gap [2].\\n*   **RAG (Retrieval-Augmented Generation)**: The standard for \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m large knowledge bases. Instead of \\\"stuffing\\\" a document, the system retrieves only the top-k most relevant    \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m chunks from a vector store to populate the context [2][3].\\n\\n### Memory Management\\nAgents require             \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m sophisticated memory systems to maintain continuity without overflowing context limits:\\n*   **Short-term       \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m Memory**: A sliding window of the most recent interaction turns (e.g., last 10 messages).\\n*   **Long-term      \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m Memory**: Key facts (e.g., user preferences) are persisted in external databases (Postgres, Vector Stores) and  \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m retrieved only when relevant to the current query [2].\\n*   **Pruning and Trimming**: Algorithms that           \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m selectively remove older, less relevant tokens while preserving the semantic core of the conversation           \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m history.\\n\\n### Summarization and Compression\\n*   **Tool Output Summarization**: Raw outputs from tools (like  \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m HTML from a web scraper) are often too verbose. An intermediate step or \\\"summarizer agent\\\" distills this data \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m into key points before passing it to the main reasoning agent [2].\\n*   **Context Compression**: Removing stop  \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m words or irrelevant sections from retrieved documents to maximize information density per token.\\n\\n### Prompt  \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m Structuring\\nUsing strict formats within the context window helps the model parse information correctly:\\n*     \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m **Separation of Concerns**: Clearly formatting \\\"System Instructions,\\\" \\\"User Input,\\\" and \\\"Tool Outputs\\\"    \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m (often using XML tags or JSON schemas) prevents the model from confusing data with instructions.\\n\\n## 4.       \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m Architectural Frameworks\\nTwo primary frameworks dominate the implementation of these                           \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m strategies:\\n\\n**LangChain**\\n*   **Focus**: Flexible orchestration and agent workflows.\\n*   **Approach**:     \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m Uses \\\"Chains\\\" to pass context sequentially between steps and \\\"Memory\\\" classes (e.g.,                        \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m `ConversationSummaryMemory`) to automatically manage history compression and persistence [4].\\n*                \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m **Strategy**: Emphasizes dynamic tool selection where the agent decides what information to add to its own      \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m context.\\n\\n**LlamaIndex**\\n*   **Focus**: Data indexing and advanced retrieval.\\n*   **Approach**: specialized \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m in structuring data for LLMs using indices (`VectorStoreIndex`, `TreeIndex`).\\n*   **Strategy**: Uses           \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m \\\"Response Synthesizers\\\" to optimize how retrieved context is presented to the LLM (e.g., `compact` mode to    \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m stuff chunks or `tree_summarize` for hierarchical reduction) [4].\\n\\n## 5. Strategic Patterns\\n\\n### RAG vs.    \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m Long-Context Windows (LCW)\\n*   **RAG**: Preferred for cost efficiency and low latency. It filters noise before \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m the model sees it, often resulting in higher accuracy for \\\"Needle in a Haystack\\\" retrieval tasks [3].\\n*      \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m **Long-Context Models (e.g., Gemini 1.5)**: Best for \\\"whole-document\\\" reasoning where global context is       \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m required. However, they are more expensive and prone to the \\\"Lost in the Middle\\\" effect.\\n\\n### Context       \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m Selection vs. Stuffing\\n*   **Context Stuffing**: Naively filling the window with all available data. This is   \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m generally an anti-pattern as it increases costs and distracts the model.\\n*   **Context Selection**: The        \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m proactive curation of inputs. Techniques include \\\"Node Postprocessors\\\" (filtering results by similarity       \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m score) and \\\"Query Transformations\\\" (rewriting vague user queries to fetch better context) [4].\\n\\n## 6.       \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m Conclusion\\nContext engineering is the bridge between raw data and intelligent agent behavior. By moving from   \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m naive context stuffing to sophisticated dynamic injection, memory management, and structured retrieval,         \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m developers can build agents that are both powerful and cost-effective. The choice between RAG architectures and \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m long-context models remains a key trade-off, with hybrid approaches often providing the best balance of         \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m accuracy and performance.\\n\\n### Sources\\n[1] Context Engineering Guide:                                        \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m https://www.promptingguide.ai/agents/context-engineering\\n[2] Context Engineering Strategies (n8n):             \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m https://www.theaiautomators.com/context-engineering-strategies-to-build-better-ai-agents/\\n[3] RAG vs Long      \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m Context Window Study: https://www.legionintel.com/blog/rag-systems-vs-lcw-performance-and-cost-trade-offs\\n[4]  \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m LangChain & LlamaIndex Comparison:                                                                              \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m https://medium.com/badal-io/exploring-langchain-and-llamaindex-to-achieve-standardization-and-interoperability- \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m in-large-2b5f3fabc366\"                                                                                          \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m }                                                                                                               \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m    ID: 589357a0-fbce-4941-9090-8f91d12880cb                                                                     \u001b[37m│\u001b[0m\n",
       "\u001b[37m╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯\u001b[0m\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #808000; text-decoration-color: #808000\">╭──────────────────────────────────────────────── 🔧 Tool Output ─────────────────────────────────────────────────╮</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> Updated todo list to [{'content': 'Save research request to /research_request.md', 'status': 'completed'},      <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> {'content': 'Research context engineering approaches for AI agents using a sub-agent', 'status': 'completed'},  <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> {'content': 'Synthesize findings and write final report to /final_report.md', 'status': 'in_progress'},         <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> {'content': 'Verify report against original request', 'status': 'pending'}]                                     <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯</span>\n",
       "</pre>\n"
      ],
      "text/plain": [
       "\u001b[33m╭─\u001b[0m\u001b[33m───────────────────────────────────────────────\u001b[0m\u001b[33m 🔧 Tool Output \u001b[0m\u001b[33m────────────────────────────────────────────────\u001b[0m\u001b[33m─╮\u001b[0m\n",
       "\u001b[33m│\u001b[0m Updated todo list to [{'content': 'Save research request to /research_request.md', 'status': 'completed'},      \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m {'content': 'Research context engineering approaches for AI agents using a sub-agent', 'status': 'completed'},  \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m {'content': 'Synthesize findings and write final report to /final_report.md', 'status': 'in_progress'},         \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m {'content': 'Verify report against original request', 'status': 'pending'}]                                     \u001b[33m│\u001b[0m\n",
       "\u001b[33m╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯\u001b[0m\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #808000; text-decoration-color: #808000\">╭──────────────────────────────────────────────── 🔧 Tool Output ─────────────────────────────────────────────────╮</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> Updated file /final_report.md                                                                                   <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯</span>\n",
       "</pre>\n"
      ],
      "text/plain": [
       "\u001b[33m╭─\u001b[0m\u001b[33m───────────────────────────────────────────────\u001b[0m\u001b[33m 🔧 Tool Output \u001b[0m\u001b[33m────────────────────────────────────────────────\u001b[0m\u001b[33m─╮\u001b[0m\n",
       "\u001b[33m│\u001b[0m Updated file /final_report.md                                                                                   \u001b[33m│\u001b[0m\n",
       "\u001b[33m╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯\u001b[0m\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">╭───────────────────────────────────────────────────── 📝 AI ─────────────────────────────────────────────────────╮</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>                                                                                                                 <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> 🔧 Tool Call: read_file                                                                                         <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>    Args: {                                                                                                      <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>   \"file_path\": \"/research_request.md\"                                                                           <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> }                                                                                                               <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>    ID: dacd96a0-c106-462a-a710-6fc389064df5                                                                     <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯</span>\n",
       "</pre>\n"
      ],
      "text/plain": [
       "\u001b[37m╭─\u001b[0m\u001b[37m────────────────────────────────────────────────────\u001b[0m\u001b[37m 📝 AI \u001b[0m\u001b[37m────────────────────────────────────────────────────\u001b[0m\u001b[37m─╮\u001b[0m\n",
       "\u001b[37m│\u001b[0m                                                                                                                 \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m 🔧 Tool Call: read_file                                                                                         \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m    Args: {                                                                                                      \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m   \"file_path\": \"/research_request.md\"                                                                           \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m }                                                                                                               \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m    ID: dacd96a0-c106-462a-a710-6fc389064df5                                                                     \u001b[37m│\u001b[0m\n",
       "\u001b[37m╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯\u001b[0m\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #808000; text-decoration-color: #808000\">╭──────────────────────────────────────────────── 🔧 Tool Output ─────────────────────────────────────────────────╮</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span>      1  research context engineering approaches used to build AI agents                                         <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯</span>\n",
       "</pre>\n"
      ],
      "text/plain": [
       "\u001b[33m╭─\u001b[0m\u001b[33m───────────────────────────────────────────────\u001b[0m\u001b[33m 🔧 Tool Output \u001b[0m\u001b[33m────────────────────────────────────────────────\u001b[0m\u001b[33m─╮\u001b[0m\n",
       "\u001b[33m│\u001b[0m      1  research context engineering approaches used to build AI agents                                         \u001b[33m│\u001b[0m\n",
       "\u001b[33m╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯\u001b[0m\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">╭───────────────────────────────────────────────────── 📝 AI ─────────────────────────────────────────────────────╮</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>                                                                                                                 <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> 🔧 Tool Call: write_todos                                                                                       <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>    Args: {                                                                                                      <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>   \"todos\": [                                                                                                    <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>     {                                                                                                           <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>       \"status\": \"completed\",                                                                                    <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>       \"content\": \"Save research request to /research_request.md\"                                                <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>     },                                                                                                          <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>     {                                                                                                           <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>       \"status\": \"completed\",                                                                                    <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>       \"content\": \"Research context engineering approaches for AI agents using a sub-agent\"                      <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>     },                                                                                                          <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>     {                                                                                                           <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>       \"status\": \"completed\",                                                                                    <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>       \"content\": \"Synthesize findings and write final report to /final_report.md\"                               <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>     },                                                                                                          <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>     {                                                                                                           <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>       \"status\": \"completed\",                                                                                    <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>       \"content\": \"Verify report against original request\"                                                       <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>     }                                                                                                           <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>   ]                                                                                                             <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> }                                                                                                               <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>    ID: 4c420284-baa7-4a5b-90ab-e156b502c709                                                                     <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>                                                                                                                 <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> 🔧 Tool Call: read_file                                                                                         <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>    Args: {                                                                                                      <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>   \"file_path\": \"/final_report.md\"                                                                               <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> }                                                                                                               <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>    ID: 2d15c15f-589e-4c3d-98b0-03116707c143                                                                     <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯</span>\n",
       "</pre>\n"
      ],
      "text/plain": [
       "\u001b[37m╭─\u001b[0m\u001b[37m────────────────────────────────────────────────────\u001b[0m\u001b[37m 📝 AI \u001b[0m\u001b[37m────────────────────────────────────────────────────\u001b[0m\u001b[37m─╮\u001b[0m\n",
       "\u001b[37m│\u001b[0m                                                                                                                 \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m 🔧 Tool Call: write_todos                                                                                       \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m    Args: {                                                                                                      \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m   \"todos\": [                                                                                                    \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m     {                                                                                                           \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m       \"status\": \"completed\",                                                                                    \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m       \"content\": \"Save research request to /research_request.md\"                                                \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m     },                                                                                                          \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m     {                                                                                                           \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m       \"status\": \"completed\",                                                                                    \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m       \"content\": \"Research context engineering approaches for AI agents using a sub-agent\"                      \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m     },                                                                                                          \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m     {                                                                                                           \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m       \"status\": \"completed\",                                                                                    \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m       \"content\": \"Synthesize findings and write final report to /final_report.md\"                               \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m     },                                                                                                          \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m     {                                                                                                           \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m       \"status\": \"completed\",                                                                                    \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m       \"content\": \"Verify report against original request\"                                                       \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m     }                                                                                                           \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m   ]                                                                                                             \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m }                                                                                                               \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m    ID: 4c420284-baa7-4a5b-90ab-e156b502c709                                                                     \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m                                                                                                                 \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m 🔧 Tool Call: read_file                                                                                         \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m    Args: {                                                                                                      \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m   \"file_path\": \"/final_report.md\"                                                                               \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m }                                                                                                               \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m    ID: 2d15c15f-589e-4c3d-98b0-03116707c143                                                                     \u001b[37m│\u001b[0m\n",
       "\u001b[37m╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯\u001b[0m\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #808000; text-decoration-color: #808000\">╭──────────────────────────────────────────────── 🔧 Tool Output ─────────────────────────────────────────────────╮</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> Updated todo list to [{'content': 'Save research request to /research_request.md', 'status': 'completed'},      <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> {'content': 'Research context engineering approaches for AI agents using a sub-agent', 'status': 'completed'},  <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> {'content': 'Synthesize findings and write final report to /final_report.md', 'status': 'completed'},           <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> {'content': 'Verify report against original request', 'status': 'completed'}]                                   <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯</span>\n",
       "</pre>\n"
      ],
      "text/plain": [
       "\u001b[33m╭─\u001b[0m\u001b[33m───────────────────────────────────────────────\u001b[0m\u001b[33m 🔧 Tool Output \u001b[0m\u001b[33m────────────────────────────────────────────────\u001b[0m\u001b[33m─╮\u001b[0m\n",
       "\u001b[33m│\u001b[0m Updated todo list to [{'content': 'Save research request to /research_request.md', 'status': 'completed'},      \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m {'content': 'Research context engineering approaches for AI agents using a sub-agent', 'status': 'completed'},  \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m {'content': 'Synthesize findings and write final report to /final_report.md', 'status': 'completed'},           \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m {'content': 'Verify report against original request', 'status': 'completed'}]                                   \u001b[33m│\u001b[0m\n",
       "\u001b[33m╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯\u001b[0m\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #808000; text-decoration-color: #808000\">╭──────────────────────────────────────────────── 🔧 Tool Output ─────────────────────────────────────────────────╮</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span>      1  # Context Engineering Approaches for AI Agents                                                          <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span>      2                                                                                                          <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span>      3  ## 1. Introduction                                                                                      <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span>      4  Context Engineering is the systematic practice of designing, managing, and optimizing the information   <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> provided to AI models to ensure accurate, consistent, and context-aware behavior. While often confused with     <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> prompt engineering (which focuses on static instructions), context engineering treats the AI's context window   <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> as a dynamic, finite resource that must be architected and managed throughout the lifecycle of an interaction.  <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> It is a critical discipline for building robust AI agents that can maintain state and relevance over long,      <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> complex tasks.                                                                                                  <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span>      5                                                                                                          <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span>      6  ## 2. Core Concepts                                                                                     <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span>      7  To build effective agents, developers must manage several fundamental aspects of the Large Language     <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> Model (LLM) environment:                                                                                        <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span>      8                                                                                                          <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span>      9  *   **Context Window**: The hard limit on the amount of text (tokens) an LLM can process at once (e.g., <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> 8k, 128k, or 1M tokens). Effective engineering ensures this space is used efficiently.                          <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span>     10  *   **State Management**: Tracking the \"world state\" across multi-turn conversations. This includes     <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> user intent, task progress, and tool outputs.                                                                   <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span>     11  *   **Context Pollution**: The phenomenon where irrelevant or contradictory information in the context  <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> degrades model performance, leading to hallucinations or confusion [2].                                         <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span>     12  *   **Serial Position Effect**: The tendency of LLMs to pay more attention to information at the very   <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> beginning and very end of the context window, often ignoring details buried in the middle (\"Lost in the         <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> Middle\") [3].                                                                                                   <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span>     13                                                                                                          <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span>     14  ## 3. Key Approaches and Techniques                                                                     <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span>     15                                                                                                          <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span>     16  ### Dynamic Context Injection &amp; Retrieval (RAG)                                                         <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span>     17  Rather than loading all available data at once, agents \"pull\" information only when necessary.          <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span>     18  *   **Dynamic Injection**: Agents use tools (like search APIs or database queries) to fetch real-time   <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> data only after identifying a specific knowledge gap [2].                                                       <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span>     19  *   **RAG (Retrieval-Augmented Generation)**: The standard for large knowledge bases. Instead of        <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> \"stuffing\" a document, the system retrieves only the top-k most relevant chunks from a vector store to populate <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> the context [2][3].                                                                                             <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span>     20                                                                                                          <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span>     21  ### Memory Management                                                                                   <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span>     22  Agents require sophisticated memory systems to maintain continuity without overflowing context limits:  <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span>     23  *   **Short-term Memory**: A sliding window of the most recent interaction turns (e.g., last 10         <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> messages).                                                                                                      <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span>     24  *   **Long-term Memory**: Key facts (e.g., user preferences) are persisted in external databases        <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> (Postgres, Vector Stores) and retrieved only when relevant to the current query [2].                            <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span>     25  *   **Pruning and Trimming**: Algorithms that selectively remove older, less relevant tokens while      <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> preserving the semantic core of the conversation history.                                                       <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span>     26                                                                                                          <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span>     27  ### Summarization and Compression                                                                       <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span>     28  *   **Tool Output Summarization**: Raw outputs from tools (like HTML from a web scraper) are often too  <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> verbose. An intermediate step or \"summarizer agent\" distills this data into key points before passing it to the <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> main reasoning agent [2].                                                                                       <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span>     29  *   **Context Compression**: Removing stop words or irrelevant sections from retrieved documents to     <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> maximize information density per token.                                                                         <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span>     30                                                                                                          <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span>     31  ### Prompt Structuring                                                                                  <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span>     32  Using strict formats within the context window helps the model parse information correctly:             <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span>     33  *   **Separation of Concerns**: Clearly formatting \"System Instructions,\" \"User Input,\" and \"Tool       <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> Outputs\" (often using XML tags or JSON schemas) prevents the model from confusing data with instructions.       <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span>     34                                                                                                          <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span>     35  ## 4. Architectural Frameworks                                                                          <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span>     36  Two primary frameworks dominate the implementation of these strategies:                                 <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span>     37                                                                                                          <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span>     38  **LangChain**                                                                                           <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span>     39  *   **Focus**: Flexible orchestration and agent workflows.                                              <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span>     40  *   **Approach**: Uses \"Chains\" to pass context sequentially between steps and \"Memory\" classes (e.g.,  <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> `ConversationSummaryMemory`) to automatically manage history compression and persistence [4].                   <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span>     41  *   **Strategy**: Emphasizes dynamic tool selection where the agent decides what information to add to  <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> its own context.                                                                                                <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span>     42                                                                                                          <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span>     43  **LlamaIndex**                                                                                          <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span>     44  *   **Focus**: Data indexing and advanced retrieval.                                                    <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span>     45  *   **Approach**: specialized in structuring data for LLMs using indices (`VectorStoreIndex`,           <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> `TreeIndex`).                                                                                                   <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span>     46  *   **Strategy**: Uses \"Response Synthesizers\" to optimize how retrieved context is presented to the    <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> LLM (e.g., `compact` mode to stuff chunks or `tree_summarize` for hierarchical reduction) [4].                  <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span>     47                                                                                                          <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span>     48  ## 5. Strategic Patterns                                                                                <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span>     49                                                                                                          <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span>     50  ### RAG vs. Long-Context Windows (LCW)                                                                  <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span>     51  *   **RAG**: Preferred for cost efficiency and low latency. It filters noise before the model sees it,  <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> often resulting in higher accuracy for \"Needle in a Haystack\" retrieval tasks [3].                              <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span>     52  *   **Long-Context Models (e.g., Gemini 1.5)**: Best for \"whole-document\" reasoning where global        <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> context is required. However, they are more expensive and prone to the \"Lost in the Middle\" effect.             <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span>     53                                                                                                          <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span>     54  ### Context Selection vs. Stuffing                                                                      <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span>     55  *   **Context Stuffing**: Naively filling the window with all available data. This is generally an      <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> anti-pattern as it increases costs and distracts the model.                                                     <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span>     56  *   **Context Selection**: The proactive curation of inputs. Techniques include \"Node Postprocessors\"   <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> (filtering results by similarity score) and \"Query Transformations\" (rewriting vague user queries to fetch      <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> better context) [4].                                                                                            <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span>     57                                                                                                          <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span>     58  ## 6. Conclusion                                                                                        <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span>     59  Context engineering is the bridge between raw data and intelligent agent behavior. By moving from naive <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> context stuffing to sophisticated dynamic injection, memory management, and structured retrieval, developers    <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> can build agents that are both powerful and cost-effective. The choice between RAG architectures and            <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> long-context models remains a key trade-off, with hybrid approaches often providing the best balance of         <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> accuracy and performance.                                                                                       <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span>     60                                                                                                          <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span>     61  ### Sources                                                                                             <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span>     62  [1] Context Engineering Guide: https://www.promptingguide.ai/agents/context-engineering                 <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span>     63  [2] Context Engineering Strategies (n8n):                                                               <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> https://www.theaiautomators.com/context-engineering-strategies-to-build-better-ai-agents/                       <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span>     64  [3] RAG vs Long Context Window Study:                                                                   <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> https://www.legionintel.com/blog/rag-systems-vs-lcw-performance-and-cost-trade-offs                             <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span>     65  [4] LangChain &amp; LlamaIndex Comparison:                                                                  <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> https://medium.com/badal-io/exploring-langchain-and-llamaindex-to-achieve-standardization-and-interoperability- <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">│</span> in-large-2b5f3fabc366                                                                                           <span style=\"color: #808000; text-decoration-color: #808000\">│</span>\n",
       "<span style=\"color: #808000; text-decoration-color: #808000\">╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯</span>\n",
       "</pre>\n"
      ],
      "text/plain": [
       "\u001b[33m╭─\u001b[0m\u001b[33m───────────────────────────────────────────────\u001b[0m\u001b[33m 🔧 Tool Output \u001b[0m\u001b[33m────────────────────────────────────────────────\u001b[0m\u001b[33m─╮\u001b[0m\n",
       "\u001b[33m│\u001b[0m      1  # Context Engineering Approaches for AI Agents                                                          \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m      2                                                                                                          \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m      3  ## 1. Introduction                                                                                      \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m      4  Context Engineering is the systematic practice of designing, managing, and optimizing the information   \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m provided to AI models to ensure accurate, consistent, and context-aware behavior. While often confused with     \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m prompt engineering (which focuses on static instructions), context engineering treats the AI's context window   \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m as a dynamic, finite resource that must be architected and managed throughout the lifecycle of an interaction.  \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m It is a critical discipline for building robust AI agents that can maintain state and relevance over long,      \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m complex tasks.                                                                                                  \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m      5                                                                                                          \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m      6  ## 2. Core Concepts                                                                                     \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m      7  To build effective agents, developers must manage several fundamental aspects of the Large Language     \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m Model (LLM) environment:                                                                                        \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m      8                                                                                                          \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m      9  *   **Context Window**: The hard limit on the amount of text (tokens) an LLM can process at once (e.g., \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m 8k, 128k, or 1M tokens). Effective engineering ensures this space is used efficiently.                          \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m     10  *   **State Management**: Tracking the \"world state\" across multi-turn conversations. This includes     \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m user intent, task progress, and tool outputs.                                                                   \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m     11  *   **Context Pollution**: The phenomenon where irrelevant or contradictory information in the context  \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m degrades model performance, leading to hallucinations or confusion [2].                                         \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m     12  *   **Serial Position Effect**: The tendency of LLMs to pay more attention to information at the very   \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m beginning and very end of the context window, often ignoring details buried in the middle (\"Lost in the         \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m Middle\") [3].                                                                                                   \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m     13                                                                                                          \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m     14  ## 3. Key Approaches and Techniques                                                                     \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m     15                                                                                                          \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m     16  ### Dynamic Context Injection & Retrieval (RAG)                                                         \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m     17  Rather than loading all available data at once, agents \"pull\" information only when necessary.          \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m     18  *   **Dynamic Injection**: Agents use tools (like search APIs or database queries) to fetch real-time   \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m data only after identifying a specific knowledge gap [2].                                                       \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m     19  *   **RAG (Retrieval-Augmented Generation)**: The standard for large knowledge bases. Instead of        \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m \"stuffing\" a document, the system retrieves only the top-k most relevant chunks from a vector store to populate \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m the context [2][3].                                                                                             \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m     20                                                                                                          \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m     21  ### Memory Management                                                                                   \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m     22  Agents require sophisticated memory systems to maintain continuity without overflowing context limits:  \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m     23  *   **Short-term Memory**: A sliding window of the most recent interaction turns (e.g., last 10         \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m messages).                                                                                                      \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m     24  *   **Long-term Memory**: Key facts (e.g., user preferences) are persisted in external databases        \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m (Postgres, Vector Stores) and retrieved only when relevant to the current query [2].                            \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m     25  *   **Pruning and Trimming**: Algorithms that selectively remove older, less relevant tokens while      \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m preserving the semantic core of the conversation history.                                                       \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m     26                                                                                                          \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m     27  ### Summarization and Compression                                                                       \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m     28  *   **Tool Output Summarization**: Raw outputs from tools (like HTML from a web scraper) are often too  \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m verbose. An intermediate step or \"summarizer agent\" distills this data into key points before passing it to the \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m main reasoning agent [2].                                                                                       \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m     29  *   **Context Compression**: Removing stop words or irrelevant sections from retrieved documents to     \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m maximize information density per token.                                                                         \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m     30                                                                                                          \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m     31  ### Prompt Structuring                                                                                  \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m     32  Using strict formats within the context window helps the model parse information correctly:             \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m     33  *   **Separation of Concerns**: Clearly formatting \"System Instructions,\" \"User Input,\" and \"Tool       \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m Outputs\" (often using XML tags or JSON schemas) prevents the model from confusing data with instructions.       \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m     34                                                                                                          \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m     35  ## 4. Architectural Frameworks                                                                          \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m     36  Two primary frameworks dominate the implementation of these strategies:                                 \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m     37                                                                                                          \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m     38  **LangChain**                                                                                           \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m     39  *   **Focus**: Flexible orchestration and agent workflows.                                              \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m     40  *   **Approach**: Uses \"Chains\" to pass context sequentially between steps and \"Memory\" classes (e.g.,  \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m `ConversationSummaryMemory`) to automatically manage history compression and persistence [4].                   \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m     41  *   **Strategy**: Emphasizes dynamic tool selection where the agent decides what information to add to  \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m its own context.                                                                                                \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m     42                                                                                                          \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m     43  **LlamaIndex**                                                                                          \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m     44  *   **Focus**: Data indexing and advanced retrieval.                                                    \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m     45  *   **Approach**: specialized in structuring data for LLMs using indices (`VectorStoreIndex`,           \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m `TreeIndex`).                                                                                                   \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m     46  *   **Strategy**: Uses \"Response Synthesizers\" to optimize how retrieved context is presented to the    \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m LLM (e.g., `compact` mode to stuff chunks or `tree_summarize` for hierarchical reduction) [4].                  \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m     47                                                                                                          \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m     48  ## 5. Strategic Patterns                                                                                \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m     49                                                                                                          \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m     50  ### RAG vs. Long-Context Windows (LCW)                                                                  \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m     51  *   **RAG**: Preferred for cost efficiency and low latency. It filters noise before the model sees it,  \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m often resulting in higher accuracy for \"Needle in a Haystack\" retrieval tasks [3].                              \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m     52  *   **Long-Context Models (e.g., Gemini 1.5)**: Best for \"whole-document\" reasoning where global        \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m context is required. However, they are more expensive and prone to the \"Lost in the Middle\" effect.             \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m     53                                                                                                          \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m     54  ### Context Selection vs. Stuffing                                                                      \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m     55  *   **Context Stuffing**: Naively filling the window with all available data. This is generally an      \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m anti-pattern as it increases costs and distracts the model.                                                     \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m     56  *   **Context Selection**: The proactive curation of inputs. Techniques include \"Node Postprocessors\"   \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m (filtering results by similarity score) and \"Query Transformations\" (rewriting vague user queries to fetch      \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m better context) [4].                                                                                            \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m     57                                                                                                          \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m     58  ## 6. Conclusion                                                                                        \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m     59  Context engineering is the bridge between raw data and intelligent agent behavior. By moving from naive \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m context stuffing to sophisticated dynamic injection, memory management, and structured retrieval, developers    \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m can build agents that are both powerful and cost-effective. The choice between RAG architectures and            \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m long-context models remains a key trade-off, with hybrid approaches often providing the best balance of         \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m accuracy and performance.                                                                                       \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m     60                                                                                                          \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m     61  ### Sources                                                                                             \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m     62  [1] Context Engineering Guide: https://www.promptingguide.ai/agents/context-engineering                 \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m     63  [2] Context Engineering Strategies (n8n):                                                               \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m https://www.theaiautomators.com/context-engineering-strategies-to-build-better-ai-agents/                       \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m     64  [3] RAG vs Long Context Window Study:                                                                   \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m https://www.legionintel.com/blog/rag-systems-vs-lcw-performance-and-cost-trade-offs                             \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m     65  [4] LangChain & LlamaIndex Comparison:                                                                  \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m https://medium.com/badal-io/exploring-langchain-and-llamaindex-to-achieve-standardization-and-interoperability- \u001b[33m│\u001b[0m\n",
       "\u001b[33m│\u001b[0m in-large-2b5f3fabc366                                                                                           \u001b[33m│\u001b[0m\n",
       "\u001b[33m╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯\u001b[0m\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">╭───────────────────────────────────────────────────── 📝 AI ─────────────────────────────────────────────────────╮</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> I have completed the research on context engineering approaches for AI agents. The final report details         <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> definitions, core concepts, key techniques (RAG, Memory, Summarization), and architectural frameworks           <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> (LangChain vs LlamaIndex).                                                                                      <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>                                                                                                                 <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> ### **Research Findings Summary**                                                                               <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> Context engineering is the discipline of managing the finite \"context window\" of an AI model to ensure it has   <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> the right information at the right time. It is distinct from prompt engineering and focuses on dynamic state    <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> management.                                                                                                     <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>                                                                                                                 <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> **Key Approaches:**                                                                                             <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> 1.  **Dynamic Context Injection (RAG)**: Instead of loading all data, agents \"pull\" specific information from   <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> vector databases or APIs only when needed to answer a query.                                                    <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> 2.  **Memory Management**: Using sliding windows (short-term memory) and external databases (long-term memory)  <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> to maintain conversation history without exceeding token limits.                                                <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> 3.  **Summarization**: Compressing verbose tool outputs (like web scrape results) before passing them to the    <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> reasoning agent to save tokens.                                                                                 <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> 4.  **Architectural Frameworks**:                                                                               <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>     *   **LangChain**: Focuses on \"Chains\" and dynamic tool selection.                                          <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>     *   **LlamaIndex**: Focuses on data indexing and advanced retrieval strategies.                             <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>                                                                                                                 <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> **Strategic Trade-offs:**                                                                                       <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> *   **RAG vs. Long-Context**: RAG is often more cost-effective and accurate for finding specific facts          <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> (\"needles\") in large datasets, while massive context windows (e.g., 1M+ tokens) are better for holistic         <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> analysis but prone to the \"Lost in the Middle\" phenomenon.                                                      <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> *   **Selection vs. Stuffing**: \"Context Stuffing\" (filling the window blindly) is an anti-pattern. \"Context    <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> Selection\" (curating inputs via filtering and query transformation) leads to better performance.                <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>                                                                                                                 <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span> The full detailed report can be found in `/final_report.md`.                                                    <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯</span>\n",
       "</pre>\n"
      ],
      "text/plain": [
       "\u001b[37m╭─\u001b[0m\u001b[37m────────────────────────────────────────────────────\u001b[0m\u001b[37m 📝 AI \u001b[0m\u001b[37m────────────────────────────────────────────────────\u001b[0m\u001b[37m─╮\u001b[0m\n",
       "\u001b[37m│\u001b[0m I have completed the research on context engineering approaches for AI agents. The final report details         \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m definitions, core concepts, key techniques (RAG, Memory, Summarization), and architectural frameworks           \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m (LangChain vs LlamaIndex).                                                                                      \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m                                                                                                                 \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m ### **Research Findings Summary**                                                                               \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m Context engineering is the discipline of managing the finite \"context window\" of an AI model to ensure it has   \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m the right information at the right time. It is distinct from prompt engineering and focuses on dynamic state    \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m management.                                                                                                     \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m                                                                                                                 \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m **Key Approaches:**                                                                                             \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m 1.  **Dynamic Context Injection (RAG)**: Instead of loading all data, agents \"pull\" specific information from   \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m vector databases or APIs only when needed to answer a query.                                                    \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m 2.  **Memory Management**: Using sliding windows (short-term memory) and external databases (long-term memory)  \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m to maintain conversation history without exceeding token limits.                                                \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m 3.  **Summarization**: Compressing verbose tool outputs (like web scrape results) before passing them to the    \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m reasoning agent to save tokens.                                                                                 \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m 4.  **Architectural Frameworks**:                                                                               \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m     *   **LangChain**: Focuses on \"Chains\" and dynamic tool selection.                                          \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m     *   **LlamaIndex**: Focuses on data indexing and advanced retrieval strategies.                             \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m                                                                                                                 \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m **Strategic Trade-offs:**                                                                                       \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m *   **RAG vs. Long-Context**: RAG is often more cost-effective and accurate for finding specific facts          \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m (\"needles\") in large datasets, while massive context windows (e.g., 1M+ tokens) are better for holistic         \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m analysis but prone to the \"Lost in the Middle\" phenomenon.                                                      \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m *   **Selection vs. Stuffing**: \"Context Stuffing\" (filling the window blindly) is an anti-pattern. \"Context    \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m Selection\" (curating inputs via filtering and query transformation) leads to better performance.                \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m                                                                                                                 \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m The full detailed report can be found in `/final_report.md`.                                                    \u001b[37m│\u001b[0m\n",
       "\u001b[37m╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯\u001b[0m\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "result = agent.invoke(\n",
    "    {\n",
    "        \"messages\": [\n",
    "            {\n",
    "                \"role\": \"user\",\n",
    "                \"content\": \"research context engineering approaches used to build AI agents\",\n",
    "            }\n",
    "        ],\n",
    "    }, \n",
    ")\n",
    "format_messages(result[\"messages\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "188b5ab5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #000080; text-decoration-color: #000080\">╭──────────────────────────────────────────────────── </span><span style=\"color: #008000; text-decoration-color: #008000; font-weight: bold\">Prompt</span><span style=\"color: #000080; text-decoration-color: #000080\"> ─────────────────────────────────────────────────────╮</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>                                                                                                                 <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  # Context Engineering Approaches for AI Agents                                                                 <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>                                                                                                                 <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  <span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">## 1. Introduction</span>                                                                                             <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  Context Engineering is the systematic practice of designing, managing, and optimizing the information          <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  provided to AI models to ensure accurate, consistent, and context-aware behavior. While often confused with    <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  prompt engineering (which focuses on static instructions), context engineering treats the AI's context window  <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  as a dynamic, finite resource that must be architected and managed throughout the lifecycle of an              <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  interaction. It is a critical discipline for building robust AI agents that can maintain state and relevance   <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  over long, complex tasks.                                                                                      <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>                                                                                                                 <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  <span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">## 2. Core Concepts</span>                                                                                            <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  To build effective agents, developers must manage several fundamental aspects of the Large Language Model      <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  (LLM) environment:                                                                                             <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>                                                                                                                 <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  *   **Context Window**: The hard limit on the amount of text (tokens) an LLM can process at once (e.g., 8k,    <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  128k, or 1M tokens). Effective engineering ensures this space is used efficiently.                             <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  *   **State Management**: Tracking the \"world state\" across multi-turn conversations. This includes user       <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  intent, task progress, and tool outputs.                                                                       <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  *   **Context Pollution**: The phenomenon where irrelevant or contradictory information in the context         <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  degrades model performance, leading to hallucinations or confusion [2].                                        <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  *   **Serial Position Effect**: The tendency of LLMs to pay more attention to information at the very          <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  beginning and very end of the context window, often ignoring details buried in the middle (\"Lost in the        <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  Middle\") [3].                                                                                                  <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>                                                                                                                 <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  <span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">## 3. Key Approaches and Techniques</span>                                                                            <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>                                                                                                                 <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">### Dynamic Context Injection &amp; Retrieval (RAG)</span>                                                                <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  Rather than loading all available data at once, agents \"pull\" information only when necessary.                 <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  *   **Dynamic Injection**: Agents use tools (like search APIs or database queries) to fetch real-time data     <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  only after identifying a specific knowledge gap [2].                                                           <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  *   **RAG (Retrieval-Augmented Generation)**: The standard for large knowledge bases. Instead of \"stuffing\" a  <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  document, the system retrieves only the top-k most relevant chunks from a vector store to populate the         <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  context [2][3].                                                                                                <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>                                                                                                                 <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">### Memory Management</span>                                                                                          <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  Agents require sophisticated memory systems to maintain continuity without overflowing context limits:         <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  *   **Short-term Memory**: A sliding window of the most recent interaction turns (e.g., last 10 messages).     <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  *   **Long-term Memory**: Key facts (e.g., user preferences) are persisted in external databases (Postgres,    <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  Vector Stores) and retrieved only when relevant to the current query [2].                                      <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  *   **Pruning and Trimming**: Algorithms that selectively remove older, less relevant tokens while preserving  <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  the semantic core of the conversation history.                                                                 <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>                                                                                                                 <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">### Summarization and Compression</span>                                                                              <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  *   **Tool Output Summarization**: Raw outputs from tools (like HTML from a web scraper) are often too         <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  verbose. An intermediate step or \"summarizer agent\" distills this data into key points before passing it to    <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  the main reasoning agent [2].                                                                                  <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  *   **Context Compression**: Removing stop words or irrelevant sections from retrieved documents to maximize   <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  information density per token.                                                                                 <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>                                                                                                                 <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">### Prompt Structuring</span>                                                                                         <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  Using strict formats within the context window helps the model parse information correctly:                    <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  *   **Separation of Concerns**: Clearly formatting \"System Instructions,\" \"User Input,\" and \"Tool Outputs\"     <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  (often using XML tags or JSON schemas) prevents the model from confusing data with instructions.               <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>                                                                                                                 <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  <span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">## 4. Architectural Frameworks</span>                                                                                 <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  Two primary frameworks dominate the implementation of these strategies:                                        <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>                                                                                                                 <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  **LangChain**                                                                                                  <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  *   **Focus**: Flexible orchestration and agent workflows.                                                     <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  *   **Approach**: Uses \"Chains\" to pass context sequentially between steps and \"Memory\" classes (e.g.,         <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  `ConversationSummaryMemory`) to automatically manage history compression and persistence [4].                  <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  *   **Strategy**: Emphasizes dynamic tool selection where the agent decides what information to add to its     <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  own context.                                                                                                   <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>                                                                                                                 <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  **LlamaIndex**                                                                                                 <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  *   **Focus**: Data indexing and advanced retrieval.                                                           <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  *   **Approach**: specialized in structuring data for LLMs using indices (`VectorStoreIndex`, `TreeIndex`).    <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  *   **Strategy**: Uses \"Response Synthesizers\" to optimize how retrieved context is presented to the LLM       <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  (e.g., `compact` mode to stuff chunks or `tree_summarize` for hierarchical reduction) [4].                     <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>                                                                                                                 <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  <span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">## 5. Strategic Patterns</span>                                                                                       <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>                                                                                                                 <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">### RAG vs. Long-Context Windows (LCW)</span>                                                                         <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  *   **RAG**: Preferred for cost efficiency and low latency. It filters noise before the model sees it, often   <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  resulting in higher accuracy for \"Needle in a Haystack\" retrieval tasks [3].                                   <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  *   **Long-Context Models (e.g., Gemini 1.5)**: Best for \"whole-document\" reasoning where global context is    <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  required. However, they are more expensive and prone to the \"Lost in the Middle\" effect.                       <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>                                                                                                                 <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">### Context Selection vs. Stuffing</span>                                                                             <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  *   **Context Stuffing**: Naively filling the window with all available data. This is generally an             <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  anti-pattern as it increases costs and distracts the model.                                                    <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  *   **Context Selection**: The proactive curation of inputs. Techniques include \"Node Postprocessors\"          <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  (filtering results by similarity score) and \"Query Transformations\" (rewriting vague user queries to fetch     <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  better context) [4].                                                                                           <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>                                                                                                                 <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  <span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">## 6. Conclusion</span>                                                                                               <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  Context engineering is the bridge between raw data and intelligent agent behavior. By moving from naive        <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  context stuffing to sophisticated dynamic injection, memory management, and structured retrieval, developers   <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  can build agents that are both powerful and cost-effective. The choice between RAG architectures and           <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  long-context models remains a key trade-off, with hybrid approaches often providing the best balance of        <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  accuracy and performance.                                                                                      <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>                                                                                                                 <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">### Sources</span>                                                                                                    <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  [1] Context Engineering Guide: https://www.promptingguide.ai/agents/context-engineering                        <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  [2] Context Engineering Strategies (n8n):                                                                      <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  https://www.theaiautomators.com/context-engineering-strategies-to-build-better-ai-agents/                      <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  [3] RAG vs Long Context Window Study:                                                                          <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  https://www.legionintel.com/blog/rag-systems-vs-lcw-performance-and-cost-trade-offs                            <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  [4] LangChain &amp; LlamaIndex Comparison:                                                                         <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  https://medium.com/badal-io/exploring-langchain-and-llamaindex-to-achieve-standardization-and-interoperabilit  <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>  y-in-large-2b5f3fabc366                                                                                        <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>                                                                                                                 <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯</span>\n",
       "</pre>\n"
      ],
      "text/plain": [
       "\u001b[34m╭─\u001b[0m\u001b[34m───────────────────────────────────────────────────\u001b[0m\u001b[34m \u001b[0m\u001b[1;32mPrompt\u001b[0m\u001b[34m \u001b[0m\u001b[34m────────────────────────────────────────────────────\u001b[0m\u001b[34m─╮\u001b[0m\n",
       "\u001b[34m│\u001b[0m                                                                                                                 \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  # Context Engineering Approaches for AI Agents                                                                 \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m                                                                                                                 \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  \u001b[1;35m## 1. Introduction\u001b[0m                                                                                             \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  Context Engineering is the systematic practice of designing, managing, and optimizing the information          \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  provided to AI models to ensure accurate, consistent, and context-aware behavior. While often confused with    \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  prompt engineering (which focuses on static instructions), context engineering treats the AI's context window  \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  as a dynamic, finite resource that must be architected and managed throughout the lifecycle of an              \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  interaction. It is a critical discipline for building robust AI agents that can maintain state and relevance   \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  over long, complex tasks.                                                                                      \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m                                                                                                                 \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  \u001b[1;35m## 2. Core Concepts\u001b[0m                                                                                            \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  To build effective agents, developers must manage several fundamental aspects of the Large Language Model      \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  (LLM) environment:                                                                                             \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m                                                                                                                 \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  *   **Context Window**: The hard limit on the amount of text (tokens) an LLM can process at once (e.g., 8k,    \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  128k, or 1M tokens). Effective engineering ensures this space is used efficiently.                             \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  *   **State Management**: Tracking the \"world state\" across multi-turn conversations. This includes user       \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  intent, task progress, and tool outputs.                                                                       \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  *   **Context Pollution**: The phenomenon where irrelevant or contradictory information in the context         \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  degrades model performance, leading to hallucinations or confusion [2].                                        \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  *   **Serial Position Effect**: The tendency of LLMs to pay more attention to information at the very          \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  beginning and very end of the context window, often ignoring details buried in the middle (\"Lost in the        \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  Middle\") [3].                                                                                                  \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m                                                                                                                 \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  \u001b[1;35m## 3. Key Approaches and Techniques\u001b[0m                                                                            \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m                                                                                                                 \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  \u001b[1;36m#\u001b[0m\u001b[1;36m## Dynamic Context Injection & Retrieval (RAG)\u001b[0m                                                                \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  Rather than loading all available data at once, agents \"pull\" information only when necessary.                 \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  *   **Dynamic Injection**: Agents use tools (like search APIs or database queries) to fetch real-time data     \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  only after identifying a specific knowledge gap [2].                                                           \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  *   **RAG (Retrieval-Augmented Generation)**: The standard for large knowledge bases. Instead of \"stuffing\" a  \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  document, the system retrieves only the top-k most relevant chunks from a vector store to populate the         \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  context [2][3].                                                                                                \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m                                                                                                                 \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  \u001b[1;36m#\u001b[0m\u001b[1;36m## Memory Management\u001b[0m                                                                                          \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  Agents require sophisticated memory systems to maintain continuity without overflowing context limits:         \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  *   **Short-term Memory**: A sliding window of the most recent interaction turns (e.g., last 10 messages).     \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  *   **Long-term Memory**: Key facts (e.g., user preferences) are persisted in external databases (Postgres,    \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  Vector Stores) and retrieved only when relevant to the current query [2].                                      \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  *   **Pruning and Trimming**: Algorithms that selectively remove older, less relevant tokens while preserving  \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  the semantic core of the conversation history.                                                                 \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m                                                                                                                 \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  \u001b[1;36m#\u001b[0m\u001b[1;36m## Summarization and Compression\u001b[0m                                                                              \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  *   **Tool Output Summarization**: Raw outputs from tools (like HTML from a web scraper) are often too         \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  verbose. An intermediate step or \"summarizer agent\" distills this data into key points before passing it to    \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  the main reasoning agent [2].                                                                                  \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  *   **Context Compression**: Removing stop words or irrelevant sections from retrieved documents to maximize   \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  information density per token.                                                                                 \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m                                                                                                                 \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  \u001b[1;36m#\u001b[0m\u001b[1;36m## Prompt Structuring\u001b[0m                                                                                         \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  Using strict formats within the context window helps the model parse information correctly:                    \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  *   **Separation of Concerns**: Clearly formatting \"System Instructions,\" \"User Input,\" and \"Tool Outputs\"     \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  (often using XML tags or JSON schemas) prevents the model from confusing data with instructions.               \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m                                                                                                                 \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  \u001b[1;35m## 4. Architectural Frameworks\u001b[0m                                                                                 \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  Two primary frameworks dominate the implementation of these strategies:                                        \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m                                                                                                                 \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  **LangChain**                                                                                                  \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  *   **Focus**: Flexible orchestration and agent workflows.                                                     \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  *   **Approach**: Uses \"Chains\" to pass context sequentially between steps and \"Memory\" classes (e.g.,         \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  `ConversationSummaryMemory`) to automatically manage history compression and persistence [4].                  \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  *   **Strategy**: Emphasizes dynamic tool selection where the agent decides what information to add to its     \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  own context.                                                                                                   \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m                                                                                                                 \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  **LlamaIndex**                                                                                                 \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  *   **Focus**: Data indexing and advanced retrieval.                                                           \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  *   **Approach**: specialized in structuring data for LLMs using indices (`VectorStoreIndex`, `TreeIndex`).    \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  *   **Strategy**: Uses \"Response Synthesizers\" to optimize how retrieved context is presented to the LLM       \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  (e.g., `compact` mode to stuff chunks or `tree_summarize` for hierarchical reduction) [4].                     \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m                                                                                                                 \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  \u001b[1;35m## 5. Strategic Patterns\u001b[0m                                                                                       \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m                                                                                                                 \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  \u001b[1;36m#\u001b[0m\u001b[1;36m## RAG vs. Long-Context Windows (LCW)\u001b[0m                                                                         \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  *   **RAG**: Preferred for cost efficiency and low latency. It filters noise before the model sees it, often   \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  resulting in higher accuracy for \"Needle in a Haystack\" retrieval tasks [3].                                   \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  *   **Long-Context Models (e.g., Gemini 1.5)**: Best for \"whole-document\" reasoning where global context is    \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  required. However, they are more expensive and prone to the \"Lost in the Middle\" effect.                       \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m                                                                                                                 \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  \u001b[1;36m#\u001b[0m\u001b[1;36m## Context Selection vs. Stuffing\u001b[0m                                                                             \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  *   **Context Stuffing**: Naively filling the window with all available data. This is generally an             \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  anti-pattern as it increases costs and distracts the model.                                                    \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  *   **Context Selection**: The proactive curation of inputs. Techniques include \"Node Postprocessors\"          \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  (filtering results by similarity score) and \"Query Transformations\" (rewriting vague user queries to fetch     \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  better context) [4].                                                                                           \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m                                                                                                                 \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  \u001b[1;35m## 6. Conclusion\u001b[0m                                                                                               \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  Context engineering is the bridge between raw data and intelligent agent behavior. By moving from naive        \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  context stuffing to sophisticated dynamic injection, memory management, and structured retrieval, developers   \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  can build agents that are both powerful and cost-effective. The choice between RAG architectures and           \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  long-context models remains a key trade-off, with hybrid approaches often providing the best balance of        \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  accuracy and performance.                                                                                      \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m                                                                                                                 \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  \u001b[1;36m#\u001b[0m\u001b[1;36m## Sources\u001b[0m                                                                                                    \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  [1] Context Engineering Guide: https://www.promptingguide.ai/agents/context-engineering                        \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  [2] Context Engineering Strategies (n8n):                                                                      \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  https://www.theaiautomators.com/context-engineering-strategies-to-build-better-ai-agents/                      \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  [3] RAG vs Long Context Window Study:                                                                          \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  https://www.legionintel.com/blog/rag-systems-vs-lcw-performance-and-cost-trade-offs                            \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  [4] LangChain & LlamaIndex Comparison:                                                                         \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  https://medium.com/badal-io/exploring-langchain-and-llamaindex-to-achieve-standardization-and-interoperabilit  \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m  y-in-large-2b5f3fabc366                                                                                        \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m                                                                                                                 \u001b[34m│\u001b[0m\n",
       "\u001b[34m╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯\u001b[0m\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "from deepagents.backends.utils import file_data_to_string\n",
    "\n",
    "# Convert a specific file to string\n",
    "file_content = file_data_to_string(result[\"files\"]['/final_report.md'])\n",
    "show_prompt(file_content) "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fdcc6784",
   "metadata": {},
   "source": [
    "Trace: \n",
    "\n",
    "https://smith.langchain.com/public/72d23852-4616-4bcc-8d8a-b0d1905c945b/r"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2d73925c",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "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.13.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
