{"id":55405,"date":"2025-12-04T08:23:36","date_gmt":"2025-12-04T08:23:36","guid":{"rendered":"https:\/\/youzum.net\/how-to-build-a-meta-cognitive-ai-agent-that-dynamically-adjusts-its-own-reasoning-depth-for-efficient-problem-solving\/"},"modified":"2025-12-04T08:23:36","modified_gmt":"2025-12-04T08:23:36","slug":"how-to-build-a-meta-cognitive-ai-agent-that-dynamically-adjusts-its-own-reasoning-depth-for-efficient-problem-solving","status":"publish","type":"post","link":"https:\/\/youzum.net\/es\/how-to-build-a-meta-cognitive-ai-agent-that-dynamically-adjusts-its-own-reasoning-depth-for-efficient-problem-solving\/","title":{"rendered":"How to Build a Meta-Cognitive AI Agent That Dynamically Adjusts Its Own Reasoning Depth for Efficient Problem Solving"},"content":{"rendered":"<p>In this tutorial, we build an advanced meta-cognitive control agent that learns how to regulate its own depth of thinking. We treat reasoning as a spectrum, ranging from fast heuristics to deep chain-of-thought to precise tool-like solving, and we train a neural meta-controller to decide which mode to use for each task. By optimizing the trade-off between accuracy, computation cost, and a limited reasoning budget, we explore how an agent can monitor its internal state and adapt its reasoning strategy in real time. Through each snippet, we experiment, observe patterns, and understand how meta-cognition emerges when an agent learns to think about its own thinking. Check out the\u00a0<strong><a href=\"https:\/\/github.com\/Marktechpost\/AI-Tutorial-Codes-Included\/blob\/main\/AI%20Agents%20Codes\/meta_cognitive_reasoning_controller_Marktechpost.ipynb\" target=\"_blank\" rel=\"noreferrer noopener\">FULL CODE NOTEBOOK<\/a><\/strong>.<\/p>\n<div class=\"dm-code-snippet dark dm-normal-version default no-background-mobile\">\n<div class=\"control-language\">\n<div class=\"dm-buttons\">\n<div class=\"dm-buttons-left\">\n<div class=\"dm-button-snippet red-button\"><\/div>\n<div class=\"dm-button-snippet orange-button\"><\/div>\n<div class=\"dm-button-snippet green-button\"><\/div>\n<\/div>\n<div class=\"dm-buttons-right\"><a><span class=\"dm-copy-text\">Copy Code<\/span><span class=\"dm-copy-confirmed\">Copied<\/span><span class=\"dm-error-message\">Use a different Browser<\/span><\/a><\/div>\n<\/div>\n<pre class=\"no-line-numbers\"><code class=\"no-wrap language-php\">import random\nimport numpy as np\nimport torch\nimport torch.nn as nn\nimport torch.optim as optim\n\n\n\n\nOPS = ['+', '*']\n\n\ndef make_task():\n   op = random.choice(OPS)\n   if op == '+':\n       a, b = random.randint(1, 99), random.randint(1, 99)\n   else:\n       a, b = random.randint(2, 19), random.randint(2, 19)\n   return a, b, op\n\n\ndef true_answer(a, b, op):\n   return a + b if op == '+' else a * b\n\n\ndef true_difficulty(a, b, op):\n   if op == '+' and a &lt;= 30 and b &lt;= 30:\n       return 0\n   if op == '*' and a &lt;= 10 and b &lt;= 10:\n       return 1\n   return 2\n\n\ndef heuristic_difficulty(a, b, op):\n   score = 0\n   if op == '*':\n       score += 0.6\n   score += max(a, b) \/ 100.0\n   return min(score, 1.0)\n\n\ndef fast_heuristic(a, b, op):\n   if op == '+':\n       base = a + b\n       noise = random.choice([-2, -1, 0, 0, 0, 1, 2, 3])\n   else:\n       base = int(0.8 * a * b)\n       noise = random.choice([-5, -3, 0, 0, 2, 5, 8])\n   return base + noise, 0.5\n\n\ndef deep_chain_of_thought(a, b, op, verbose=False):\n   if op == '+':\n       x, y = a, b\n       carry = 0\n       pos = 1\n       result = 0\n       step = 0\n       while x &gt; 0 or y &gt; 0 or carry:\n           dx, dy = x % 10, y % 10\n           s = dx + dy + carry\n           carry, digit = divmod(s, 10)\n           result += digit * pos\n           x \/\/= 10; y \/\/= 10; pos *= 10\n           step += 1\n   else:\n       result = 0\n       step = 0\n       for i, d in enumerate(reversed(str(b))):\n           row = a * int(d) * (10 ** i)\n           result += row\n           step += 1\n   return result, max(2.0, 0.4 * step)\n\n\ndef tool_solver(a, b, op):\n   return eval(f\"{a}{op}{b}\"), 1.2\n\n\nACTION_NAMES = [\"fast\", \"deep\", \"tool\"]<\/code><\/pre>\n<\/div>\n<\/div>\n<p>We set up the world our meta-agent operates in. We generate arithmetic tasks, define ground-truth answers, estimate difficulty, and implement three different reasoning modes. As we run it, we observe how each solver behaves differently in terms of accuracy and computational cost, which form the foundation of the agent\u2019s decision space. Check out the\u00a0<strong><a href=\"https:\/\/github.com\/Marktechpost\/AI-Tutorial-Codes-Included\/blob\/main\/AI%20Agents%20Codes\/meta_cognitive_reasoning_controller_Marktechpost.ipynb\" target=\"_blank\" rel=\"noreferrer noopener\">FULL CODE NOTEBOOK<\/a><\/strong>.<\/p>\n<div class=\"dm-code-snippet dark dm-normal-version default no-background-mobile\">\n<div class=\"control-language\">\n<div class=\"dm-buttons\">\n<div class=\"dm-buttons-left\">\n<div class=\"dm-button-snippet red-button\"><\/div>\n<div class=\"dm-button-snippet orange-button\"><\/div>\n<div class=\"dm-button-snippet green-button\"><\/div>\n<\/div>\n<div class=\"dm-buttons-right\"><a><span class=\"dm-copy-text\">Copy Code<\/span><span class=\"dm-copy-confirmed\">Copied<\/span><span class=\"dm-error-message\">Use a different Browser<\/span><\/a><\/div>\n<\/div>\n<pre class=\"no-line-numbers\"><code class=\"no-wrap language-php\">def encode_state(a, b, op, rem_budget, error_ema, last_action):\n   a_n = a \/ 100.0\n   b_n = b \/ 100.0\n   op_plus = 1.0 if op == '+' else 0.0\n   op_mul = 1.0 - op_plus\n   diff_hat = heuristic_difficulty(a, b, op)\n   rem_n = rem_budget \/ MAX_BUDGET\n   last_onehot = [0.0, 0.0, 0.0]\n   if last_action is not None:\n       last_onehot[last_action] = 1.0\n   feats = [\n       a_n, b_n, op_plus, op_mul,\n       diff_hat, rem_n, error_ema\n   ] + last_onehot\n   return torch.tensor(feats, dtype=torch.float32, device=device)\n\n\nSTATE_DIM = 10\nN_ACTIONS = 3\n\n\nclass PolicyNet(nn.Module):\n   def __init__(self, state_dim, hidden=48, n_actions=3):\n       super().__init__()\n       self.net = nn.Sequential(\n           nn.Linear(state_dim, hidden),\n           nn.Tanh(),\n           nn.Linear(hidden, hidden),\n           nn.Tanh(),\n           nn.Linear(hidden, n_actions)\n       )\n   def forward(self, x):\n       return self.net(x)\n\n\npolicy = PolicyNet(STATE_DIM, hidden=48, n_actions=N_ACTIONS).to(device)\noptimizer = optim.Adam(policy.parameters(), lr=3e-3)<\/code><\/pre>\n<\/div>\n<\/div>\n<p>We encode each task into a structured state that captures operands, operation type, predicted difficulty, remaining budget, and recent performance. We then define a neural policy network that maps this state to a probability distribution over actions. As we work through it, we see how the policy becomes the core mechanism through which the agent learns to regulate its thinking. Check out the\u00a0<strong><a href=\"https:\/\/github.com\/Marktechpost\/AI-Tutorial-Codes-Included\/blob\/main\/AI%20Agents%20Codes\/meta_cognitive_reasoning_controller_Marktechpost.ipynb\" target=\"_blank\" rel=\"noreferrer noopener\">FULL CODE NOTEBOOK<\/a><\/strong>.<\/p>\n<div class=\"dm-code-snippet dark dm-normal-version default no-background-mobile\">\n<div class=\"control-language\">\n<div class=\"dm-buttons\">\n<div class=\"dm-buttons-left\">\n<div class=\"dm-button-snippet red-button\"><\/div>\n<div class=\"dm-button-snippet orange-button\"><\/div>\n<div class=\"dm-button-snippet green-button\"><\/div>\n<\/div>\n<div class=\"dm-buttons-right\"><a><span class=\"dm-copy-text\">Copy Code<\/span><span class=\"dm-copy-confirmed\">Copied<\/span><span class=\"dm-error-message\">Use a different Browser<\/span><\/a><\/div>\n<\/div>\n<pre class=\"no-line-numbers\"><code class=\"no-wrap language-php\">GAMMA = 0.98\nCOST_PENALTY = 0.25\nMAX_BUDGET = 25.0\nEPISODES = 600\nSTEPS_PER_EP = 20\nERROR_EMA_DECAY = 0.9\n\n\ndef run_episode(train=True):\n   log_probs = []\n   rewards = []\n   info = []\n   rem_budget = MAX_BUDGET\n   error_ema = 0.0\n   last_action = None\n\n\n   for _ in range(STEPS_PER_EP):\n       a, b, op = make_task()\n       state = encode_state(a, b, op, rem_budget, error_ema, last_action)\n       logits = policy(state)\n       dist = torch.distributions.Categorical(logits=logits)\n       action = dist.sample() if train else torch.argmax(logits)\n       act_idx = int(action.item())\n\n\n       if act_idx == 0:\n           pred, cost = fast_heuristic(a, b, op)\n       elif act_idx == 1:\n           pred, cost = deep_chain_of_thought(a, b, op, verbose=False)\n       else:\n           pred, cost = tool_solver(a, b, op)\n\n\n       correct = (pred == true_answer(a, b, op))\n       acc_reward = 1.0 if correct else 0.0\n       budget_penalty = 0.0\n\n\n       rem_budget -= cost\n       if rem_budget &lt; 0:\n           budget_penalty = -1.5 * (abs(rem_budget) \/ MAX_BUDGET)\n\n\n       step_reward = acc_reward - COST_PENALTY * cost + budget_penalty\n       rewards.append(step_reward)\n\n\n       if train:\n           log_probs.append(dist.log_prob(action))\n\n\n       err = 0.0 if correct else 1.0\n       error_ema = ERROR_EMA_DECAY * error_ema + (1 - ERROR_EMA_DECAY) * err\n       last_action = act_idx\n\n\n       info.append({\n           \"correct\": correct,\n           \"cost\": cost,\n           \"difficulty\": true_difficulty(a, b, op),\n           \"action\": act_idx\n       })\n\n\n   if train:\n       returns = []\n       G = 0.0\n       for r in reversed(rewards):\n           G = r + GAMMA * G\n           returns.append(G)\n       returns = list(reversed(returns))\n       returns_t = torch.tensor(returns, dtype=torch.float32, device=device)\n       baseline = returns_t.mean()\n       adv = returns_t - baseline\n       loss = -(torch.stack(log_probs) * adv).mean()\n       optimizer.zero_grad()\n       loss.backward()\n       optimizer.step()\n\n\n   return rewards, info<\/code><\/pre>\n<\/div>\n<\/div>\n<p>We implement the heart of learning using the REINFORCE policy gradient algorithm. We run multi-step episodes, collect log-probabilities, accumulate rewards, and compute returns. As we execute this part, we watch the meta-controller adjust its strategy by reinforcing decisions that balance accuracy with cost. Check out the\u00a0<strong><a href=\"https:\/\/github.com\/Marktechpost\/AI-Tutorial-Codes-Included\/blob\/main\/AI%20Agents%20Codes\/meta_cognitive_reasoning_controller_Marktechpost.ipynb\" target=\"_blank\" rel=\"noreferrer noopener\">FULL CODE NOTEBOOK<\/a><\/strong>.<\/p>\n<div class=\"dm-code-snippet dark dm-normal-version default no-background-mobile\">\n<div class=\"control-language\">\n<div class=\"dm-buttons\">\n<div class=\"dm-buttons-left\">\n<div class=\"dm-button-snippet red-button\"><\/div>\n<div class=\"dm-button-snippet orange-button\"><\/div>\n<div class=\"dm-button-snippet green-button\"><\/div>\n<\/div>\n<div class=\"dm-buttons-right\"><a><span class=\"dm-copy-text\">Copy Code<\/span><span class=\"dm-copy-confirmed\">Copied<\/span><span class=\"dm-error-message\">Use a different Browser<\/span><\/a><\/div>\n<\/div>\n<pre class=\"no-line-numbers\"><code class=\"no-wrap language-php\">print(\"Training meta-cognitive controller...\")\nfor ep in range(EPISODES):\n   rewards, _ = run_episode(train=True)\n   if (ep + 1) % 100 == 0:\n       print(f\" episode {ep+1:4d} | avg reward {np.mean(rewards):.3f}\")\n\n\ndef evaluate(n_episodes=50):\n   all_actions = {0: [0,0,0], 1: [0,0,0], 2: [0,0,0]}\n   stats = {0: {\"n\":0,\"acc\":0,\"cost\":0},\n            1: {\"n\":0,\"acc\":0,\"cost\":0},\n            2: {\"n\":0,\"acc\":0,\"cost\":0}}\n\n\n   for _ in range(n_episodes):\n       _, info = run_episode(train=False)\n       for step in info:\n           d = step[\"difficulty\"]\n           a_idx = step[\"action\"]\n           all_actions[d][a_idx] += 1\n           stats[d][\"n\"] += 1\n           stats[d][\"acc\"] += 1 if step[\"correct\"] else 0\n           stats[d][\"cost\"] += step[\"cost\"]\n\n\n   for d in [0,1,2]:\n       if stats[d][\"n\"] == 0:\n           continue\n       n = stats[d][\"n\"]\n       print(f\"Difficulty {d}:\")\n       print(\" action counts [fast, deep, tool]:\", all_actions[d])\n       print(\" accuracy:\", stats[d][\"acc\"]\/n)\n       print(\" avg cost:\", stats[d][\"cost\"]\/n)\n       print()\n\n\nprint(\"Policy behavior by difficulty:\")\nevaluate()<\/code><\/pre>\n<\/div>\n<\/div>\n<p>We train the meta-cognitive agent over hundreds of episodes and evaluate its behavior across difficulty levels. We observe how the policy evolves, using fast heuristics for simple tasks while resorting to deeper reasoning for harder ones. As we analyze the outputs, we understand how training shapes the agent\u2019s reasoning choices. Check out the\u00a0<strong><a href=\"https:\/\/github.com\/Marktechpost\/AI-Tutorial-Codes-Included\/blob\/main\/AI%20Agents%20Codes\/meta_cognitive_reasoning_controller_Marktechpost.ipynb\" target=\"_blank\" rel=\"noreferrer noopener\">FULL CODE NOTEBOOK<\/a><\/strong>.<\/p>\n<div class=\"dm-code-snippet dark dm-normal-version default no-background-mobile\">\n<div class=\"control-language\">\n<div class=\"dm-buttons\">\n<div class=\"dm-buttons-left\">\n<div class=\"dm-button-snippet red-button\"><\/div>\n<div class=\"dm-button-snippet orange-button\"><\/div>\n<div class=\"dm-button-snippet green-button\"><\/div>\n<\/div>\n<div class=\"dm-buttons-right\"><a><span class=\"dm-copy-text\">Copy Code<\/span><span class=\"dm-copy-confirmed\">Copied<\/span><span class=\"dm-error-message\">Use a different Browser<\/span><\/a><\/div>\n<\/div>\n<pre class=\"no-line-numbers\"><code class=\"no-wrap language-php\">print(\"nExample hard task with meta-selected thinking mode:\")\na, b, op = 47, 18, '*'\nstate = encode_state(a, b, op, MAX_BUDGET, 0.3, None)\nwith torch.no_grad():\n   logits = policy(state)\n   act = int(torch.argmax(logits).item())\n\n\nprint(f\"Task: {a} {op} {b}\")\nprint(\"Chosen mode:\", ACTION_NAMES[act])\n\n\nif act == 1:\n   pred, cost = deep_chain_of_thought(a, b, op, verbose=True)\nelif act == 0:\n   pred, cost = fast_heuristic(a, b, op)\n   print(\"Fast heuristic:\", pred)\nelse:\n   pred, cost = tool_solver(a, b, op)\n   print(\"Tool solver:\", pred)\n\n\nprint(\"True:\", true_answer(a,b,op), \"| cost:\", cost)<\/code><\/pre>\n<\/div>\n<\/div>\n<p>We inspect a detailed reasoning trace for a hard example chosen by the trained policy. We see the agent confidently pick a mode and walk through the reasoning steps, allowing us to witness its meta-cognitive behavior in action. As we test different tasks, we appreciate how the model adapts its thinking based on context.<\/p>\n<p>In conclusion, we have seen how a neural controller can learn to dynamically choose the most effective reasoning pathway based on the task\u2019s difficulty and the constraints of the moment. We observe how the agent gradually discovers when quick heuristics are sufficient, when deeper reasoning is necessary, and when calling a precise solver is worth the cost. Through this process, we experience how metacognitive control transforms decision-making, leading to more efficient and adaptable reasoning systems.<\/p>\n<hr class=\"wp-block-separator has-alpha-channel-opacity\" \/>\n<p>Check out the\u00a0<strong><a href=\"https:\/\/github.com\/Marktechpost\/AI-Tutorial-Codes-Included\/blob\/main\/AI%20Agents%20Codes\/meta_cognitive_reasoning_controller_Marktechpost.ipynb\" target=\"_blank\" rel=\"noreferrer noopener\">FULL CODE NOTEBOOK<\/a><\/strong>.\u00a0Feel free to check out our\u00a0<strong><mark><a href=\"https:\/\/github.com\/Marktechpost\/AI-Tutorial-Codes-Included\" target=\"_blank\" rel=\"noreferrer noopener\">GitHub Page for Tutorials, Codes and Notebooks<\/a><\/mark><\/strong>.\u00a0Also,\u00a0feel free to follow us on\u00a0<strong><a href=\"https:\/\/x.com\/intent\/follow?screen_name=marktechpost\" target=\"_blank\" rel=\"noreferrer noopener\"><mark>Twitter<\/mark><\/a><\/strong>\u00a0and don\u2019t forget to join our\u00a0<strong><a href=\"https:\/\/www.reddit.com\/r\/machinelearningnews\/\" target=\"_blank\" rel=\"noreferrer noopener\">100k+ ML SubReddit<\/a><\/strong>\u00a0and Subscribe to\u00a0<strong><a href=\"https:\/\/www.aidevsignals.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">our Newsletter<\/a><\/strong>. Wait! are you on telegram?\u00a0<strong><a href=\"https:\/\/t.me\/machinelearningresearchnews\" target=\"_blank\" rel=\"noreferrer noopener\">now you can join us on telegram as well.<\/a><\/strong><\/p>\n<p>The post <a href=\"https:\/\/www.marktechpost.com\/2025\/12\/03\/how-to-build-a-meta-cognitive-ai-agent-that-dynamically-adjusts-its-own-reasoning-depth-for-efficient-problem-solving\/\">How to Build a Meta-Cognitive AI Agent That Dynamically Adjusts Its Own Reasoning Depth for Efficient Problem Solving<\/a> appeared first on <a href=\"https:\/\/www.marktechpost.com\/\">MarkTechPost<\/a>.<\/p>","protected":false},"excerpt":{"rendered":"<p>In this tutorial, we build an advanced meta-cognitive control agent that learns how to regulate its own depth of thinking. We treat reasoning as a spectrum, ranging from fast heuristics to deep chain-of-thought to precise tool-like solving, and we train a neural meta-controller to decide which mode to use for each task. By optimizing the trade-off between accuracy, computation cost, and a limited reasoning budget, we explore how an agent can monitor its internal state and adapt its reasoning strategy in real time. Through each snippet, we experiment, observe patterns, and understand how meta-cognition emerges when an agent learns to think about its own thinking. Check out the\u00a0FULL CODE NOTEBOOK. Copy CodeCopiedUse a different Browser import random import numpy as np import torch import torch.nn as nn import torch.optim as optim OPS = [&#8216;+&#8217;, &#8216;*&#8217;] def make_task(): op = random.choice(OPS) if op == &#8216;+&#8217;: a, b = random.randint(1, 99), random.randint(1, 99) else: a, b = random.randint(2, 19), random.randint(2, 19) return a, b, op def true_answer(a, b, op): return a + b if op == &#8216;+&#8217; else a * b def true_difficulty(a, b, op): if op == &#8216;+&#8217; and a &lt;= 30 and b &lt;= 30: return 0 if op == &#8216;*&#8217; and a &lt;= 10 and b &lt;= 10: return 1 return 2 def heuristic_difficulty(a, b, op): score = 0 if op == &#8216;*&#8217;: score += 0.6 score += max(a, b) \/ 100.0 return min(score, 1.0) def fast_heuristic(a, b, op): if op == &#8216;+&#8217;: base = a + b noise = random.choice([-2, -1, 0, 0, 0, 1, 2, 3]) else: base = int(0.8 * a * b) noise = random.choice([-5, -3, 0, 0, 2, 5, 8]) return base + noise, 0.5 def deep_chain_of_thought(a, b, op, verbose=False): if op == &#8216;+&#8217;: x, y = a, b carry = 0 pos = 1 result = 0 step = 0 while x &gt; 0 or y &gt; 0 or carry: dx, dy = x % 10, y % 10 s = dx + dy + carry carry, digit = divmod(s, 10) result += digit * pos x \/\/= 10; y \/\/= 10; pos *= 10 step += 1 else: result = 0 step = 0 for i, d in enumerate(reversed(str(b))): row = a * int(d) * (10 ** i) result += row step += 1 return result, max(2.0, 0.4 * step) def tool_solver(a, b, op): return eval(f&#8221;{a}{op}{b}&#8221;), 1.2 ACTION_NAMES = [&#8220;fast&#8221;, &#8220;deep&#8221;, &#8220;tool&#8221;] We set up the world our meta-agent operates in. We generate arithmetic tasks, define ground-truth answers, estimate difficulty, and implement three different reasoning modes. As we run it, we observe how each solver behaves differently in terms of accuracy and computational cost, which form the foundation of the agent\u2019s decision space. Check out the\u00a0FULL CODE NOTEBOOK. Copy CodeCopiedUse a different Browser def encode_state(a, b, op, rem_budget, error_ema, last_action): a_n = a \/ 100.0 b_n = b \/ 100.0 op_plus = 1.0 if op == &#8216;+&#8217; else 0.0 op_mul = 1.0 &#8211; op_plus diff_hat = heuristic_difficulty(a, b, op) rem_n = rem_budget \/ MAX_BUDGET last_onehot = [0.0, 0.0, 0.0] if last_action is not None: last_onehot[last_action] = 1.0 feats = [ a_n, b_n, op_plus, op_mul, diff_hat, rem_n, error_ema ] + last_onehot return torch.tensor(feats, dtype=torch.float32, device=device) STATE_DIM = 10 N_ACTIONS = 3 class PolicyNet(nn.Module): def __init__(self, state_dim, hidden=48, n_actions=3): super().__init__() self.net = nn.Sequential( nn.Linear(state_dim, hidden), nn.Tanh(), nn.Linear(hidden, hidden), nn.Tanh(), nn.Linear(hidden, n_actions) ) def forward(self, x): return self.net(x) policy = PolicyNet(STATE_DIM, hidden=48, n_actions=N_ACTIONS).to(device) optimizer = optim.Adam(policy.parameters(), lr=3e-3) We encode each task into a structured state that captures operands, operation type, predicted difficulty, remaining budget, and recent performance. We then define a neural policy network that maps this state to a probability distribution over actions. As we work through it, we see how the policy becomes the core mechanism through which the agent learns to regulate its thinking. Check out the\u00a0FULL CODE NOTEBOOK. Copy CodeCopiedUse a different Browser GAMMA = 0.98 COST_PENALTY = 0.25 MAX_BUDGET = 25.0 EPISODES = 600 STEPS_PER_EP = 20 ERROR_EMA_DECAY = 0.9 def run_episode(train=True): log_probs = [] rewards = [] info = [] rem_budget = MAX_BUDGET error_ema = 0.0 last_action = None for _ in range(STEPS_PER_EP): a, b, op = make_task() state = encode_state(a, b, op, rem_budget, error_ema, last_action) logits = policy(state) dist = torch.distributions.Categorical(logits=logits) action = dist.sample() if train else torch.argmax(logits) act_idx = int(action.item()) if act_idx == 0: pred, cost = fast_heuristic(a, b, op) elif act_idx == 1: pred, cost = deep_chain_of_thought(a, b, op, verbose=False) else: pred, cost = tool_solver(a, b, op) correct = (pred == true_answer(a, b, op)) acc_reward = 1.0 if correct else 0.0 budget_penalty = 0.0 rem_budget -= cost if rem_budget &lt; 0: budget_penalty = -1.5 * (abs(rem_budget) \/ MAX_BUDGET) step_reward = acc_reward &#8211; COST_PENALTY * cost + budget_penalty rewards.append(step_reward) if train: log_probs.append(dist.log_prob(action)) err = 0.0 if correct else 1.0 error_ema = ERROR_EMA_DECAY * error_ema + (1 &#8211; ERROR_EMA_DECAY) * err last_action = act_idx info.append({ &#8220;correct&#8221;: correct, &#8220;cost&#8221;: cost, &#8220;difficulty&#8221;: true_difficulty(a, b, op), &#8220;action&#8221;: act_idx }) if train: returns = [] G = 0.0 for r in reversed(rewards): G = r + GAMMA * G returns.append(G) returns = list(reversed(returns)) returns_t = torch.tensor(returns, dtype=torch.float32, device=device) baseline = returns_t.mean() adv = returns_t &#8211; baseline loss = -(torch.stack(log_probs) * adv).mean() optimizer.zero_grad() loss.backward() optimizer.step() return rewards, info We implement the heart of learning using the REINFORCE policy gradient algorithm. We run multi-step episodes, collect log-probabilities, accumulate rewards, and compute returns. As we execute this part, we watch the meta-controller adjust its strategy by reinforcing decisions that balance accuracy with cost. Check out the\u00a0FULL CODE NOTEBOOK. Copy CodeCopiedUse a different Browser print(&#8220;Training meta-cognitive controller&#8230;&#8221;) for ep in range(EPISODES): rewards, _ = run_episode(train=True) if (ep + 1) % 100 == 0: print(f&#8221; episode {ep+1:4d} | avg reward {np.mean(rewards):.3f}&#8221;) def evaluate(n_episodes=50): all_actions = {0: [0,0,0], 1: [0,0,0], 2: [0,0,0]} stats = {0: {&#8220;n&#8221;:0,&#8221;acc&#8221;:0,&#8221;cost&#8221;:0}, 1: {&#8220;n&#8221;:0,&#8221;acc&#8221;:0,&#8221;cost&#8221;:0}, 2: {&#8220;n&#8221;:0,&#8221;acc&#8221;:0,&#8221;cost&#8221;:0}} for _ in range(n_episodes): _, info = run_episode(train=False) for step in info: d = step[&#8220;difficulty&#8221;] a_idx = step[&#8220;action&#8221;] all_actions[d][a_idx] += 1 stats[d][&#8220;n&#8221;] += 1 stats[d][&#8220;acc&#8221;] += 1 if step[&#8220;correct&#8221;] else 0 stats[d][&#8220;cost&#8221;] += step[&#8220;cost&#8221;] for d in<\/p>","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"pmpro_default_level":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"_pvb_checkbox_block_on_post":false,"footnotes":""},"categories":[52,5,7,1],"tags":[],"class_list":["post-55405","post","type-post","status-publish","format-standard","hentry","category-ai-club","category-committee","category-news","category-uncategorized","pmpro-has-access"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to Build a Meta-Cognitive AI Agent That Dynamically Adjusts Its Own Reasoning Depth for Efficient Problem Solving - YouZum<\/title>\n<meta name=\"description\" content=\"\u0e01\u0e34\u0e08\u0e01\u0e23\u0e23\u0e21\u0e40\u0e01\u0e35\u0e48\u0e22\u0e27\u0e01\u0e31\u0e1a\u0e42\u0e14\u0e23\u0e19\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/youzum.net\/es\/how-to-build-a-meta-cognitive-ai-agent-that-dynamically-adjusts-its-own-reasoning-depth-for-efficient-problem-solving\/\" \/>\n<meta property=\"og:locale\" content=\"es_ES\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Build a Meta-Cognitive AI Agent That Dynamically Adjusts Its Own Reasoning Depth for Efficient Problem Solving - YouZum\" \/>\n<meta property=\"og:description\" content=\"\u0e01\u0e34\u0e08\u0e01\u0e23\u0e23\u0e21\u0e40\u0e01\u0e35\u0e48\u0e22\u0e27\u0e01\u0e31\u0e1a\u0e42\u0e14\u0e23\u0e19\" \/>\n<meta property=\"og:url\" content=\"https:\/\/youzum.net\/es\/how-to-build-a-meta-cognitive-ai-agent-that-dynamically-adjusts-its-own-reasoning-depth-for-efficient-problem-solving\/\" \/>\n<meta property=\"og:site_name\" content=\"YouZum\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DroneAssociationTH\/\" \/>\n<meta property=\"article:published_time\" content=\"2025-12-04T08:23:36+00:00\" \/>\n<meta name=\"author\" content=\"admin NU\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Escrito por\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin NU\" \/>\n\t<meta name=\"twitter:label2\" content=\"Tiempo de lectura\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutos\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/youzum.net\/how-to-build-a-meta-cognitive-ai-agent-that-dynamically-adjusts-its-own-reasoning-depth-for-efficient-problem-solving\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/youzum.net\/how-to-build-a-meta-cognitive-ai-agent-that-dynamically-adjusts-its-own-reasoning-depth-for-efficient-problem-solving\/\"},\"author\":{\"name\":\"admin NU\",\"@id\":\"https:\/\/yousum.gpucore.co\/#\/schema\/person\/97fa48242daf3908e4d9a5f26f4a059c\"},\"headline\":\"How to Build a Meta-Cognitive AI Agent That Dynamically Adjusts Its Own Reasoning Depth for Efficient Problem Solving\",\"datePublished\":\"2025-12-04T08:23:36+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/youzum.net\/how-to-build-a-meta-cognitive-ai-agent-that-dynamically-adjusts-its-own-reasoning-depth-for-efficient-problem-solving\/\"},\"wordCount\":604,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/yousum.gpucore.co\/#organization\"},\"articleSection\":[\"AI\",\"Committee\",\"News\",\"Uncategorized\"],\"inLanguage\":\"es\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/youzum.net\/how-to-build-a-meta-cognitive-ai-agent-that-dynamically-adjusts-its-own-reasoning-depth-for-efficient-problem-solving\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/youzum.net\/how-to-build-a-meta-cognitive-ai-agent-that-dynamically-adjusts-its-own-reasoning-depth-for-efficient-problem-solving\/\",\"url\":\"https:\/\/youzum.net\/how-to-build-a-meta-cognitive-ai-agent-that-dynamically-adjusts-its-own-reasoning-depth-for-efficient-problem-solving\/\",\"name\":\"How to Build a Meta-Cognitive AI Agent That Dynamically Adjusts Its Own Reasoning Depth for Efficient Problem Solving - YouZum\",\"isPartOf\":{\"@id\":\"https:\/\/yousum.gpucore.co\/#website\"},\"datePublished\":\"2025-12-04T08:23:36+00:00\",\"description\":\"\u0e01\u0e34\u0e08\u0e01\u0e23\u0e23\u0e21\u0e40\u0e01\u0e35\u0e48\u0e22\u0e27\u0e01\u0e31\u0e1a\u0e42\u0e14\u0e23\u0e19\",\"breadcrumb\":{\"@id\":\"https:\/\/youzum.net\/how-to-build-a-meta-cognitive-ai-agent-that-dynamically-adjusts-its-own-reasoning-depth-for-efficient-problem-solving\/#breadcrumb\"},\"inLanguage\":\"es\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/youzum.net\/how-to-build-a-meta-cognitive-ai-agent-that-dynamically-adjusts-its-own-reasoning-depth-for-efficient-problem-solving\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/youzum.net\/how-to-build-a-meta-cognitive-ai-agent-that-dynamically-adjusts-its-own-reasoning-depth-for-efficient-problem-solving\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/youzum.net\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Build a Meta-Cognitive AI Agent That Dynamically Adjusts Its Own Reasoning Depth for Efficient Problem Solving\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/yousum.gpucore.co\/#website\",\"url\":\"https:\/\/yousum.gpucore.co\/\",\"name\":\"YouSum\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/yousum.gpucore.co\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/yousum.gpucore.co\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"es\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/yousum.gpucore.co\/#organization\",\"name\":\"Drone Association Thailand\",\"url\":\"https:\/\/yousum.gpucore.co\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"es\",\"@id\":\"https:\/\/yousum.gpucore.co\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/youzum.net\/wp-content\/uploads\/2024\/11\/tranparent-logo.png\",\"contentUrl\":\"https:\/\/youzum.net\/wp-content\/uploads\/2024\/11\/tranparent-logo.png\",\"width\":300,\"height\":300,\"caption\":\"Drone Association Thailand\"},\"image\":{\"@id\":\"https:\/\/yousum.gpucore.co\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/DroneAssociationTH\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/yousum.gpucore.co\/#\/schema\/person\/97fa48242daf3908e4d9a5f26f4a059c\",\"name\":\"admin NU\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"es\",\"@id\":\"https:\/\/yousum.gpucore.co\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/youzum.net\/wp-content\/uploads\/avatars\/2\/1746849356-bpfull.png\",\"contentUrl\":\"https:\/\/youzum.net\/wp-content\/uploads\/avatars\/2\/1746849356-bpfull.png\",\"caption\":\"admin NU\"},\"url\":\"https:\/\/youzum.net\/es\/members\/adminnu\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Build a Meta-Cognitive AI Agent That Dynamically Adjusts Its Own Reasoning Depth for Efficient Problem Solving - YouZum","description":"\u0e01\u0e34\u0e08\u0e01\u0e23\u0e23\u0e21\u0e40\u0e01\u0e35\u0e48\u0e22\u0e27\u0e01\u0e31\u0e1a\u0e42\u0e14\u0e23\u0e19","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/youzum.net\/es\/how-to-build-a-meta-cognitive-ai-agent-that-dynamically-adjusts-its-own-reasoning-depth-for-efficient-problem-solving\/","og_locale":"es_ES","og_type":"article","og_title":"How to Build a Meta-Cognitive AI Agent That Dynamically Adjusts Its Own Reasoning Depth for Efficient Problem Solving - YouZum","og_description":"\u0e01\u0e34\u0e08\u0e01\u0e23\u0e23\u0e21\u0e40\u0e01\u0e35\u0e48\u0e22\u0e27\u0e01\u0e31\u0e1a\u0e42\u0e14\u0e23\u0e19","og_url":"https:\/\/youzum.net\/es\/how-to-build-a-meta-cognitive-ai-agent-that-dynamically-adjusts-its-own-reasoning-depth-for-efficient-problem-solving\/","og_site_name":"YouZum","article_publisher":"https:\/\/www.facebook.com\/DroneAssociationTH\/","article_published_time":"2025-12-04T08:23:36+00:00","author":"admin NU","twitter_card":"summary_large_image","twitter_misc":{"Escrito por":"admin NU","Tiempo de lectura":"7 minutos"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/youzum.net\/how-to-build-a-meta-cognitive-ai-agent-that-dynamically-adjusts-its-own-reasoning-depth-for-efficient-problem-solving\/#article","isPartOf":{"@id":"https:\/\/youzum.net\/how-to-build-a-meta-cognitive-ai-agent-that-dynamically-adjusts-its-own-reasoning-depth-for-efficient-problem-solving\/"},"author":{"name":"admin NU","@id":"https:\/\/yousum.gpucore.co\/#\/schema\/person\/97fa48242daf3908e4d9a5f26f4a059c"},"headline":"How to Build a Meta-Cognitive AI Agent That Dynamically Adjusts Its Own Reasoning Depth for Efficient Problem Solving","datePublished":"2025-12-04T08:23:36+00:00","mainEntityOfPage":{"@id":"https:\/\/youzum.net\/how-to-build-a-meta-cognitive-ai-agent-that-dynamically-adjusts-its-own-reasoning-depth-for-efficient-problem-solving\/"},"wordCount":604,"commentCount":0,"publisher":{"@id":"https:\/\/yousum.gpucore.co\/#organization"},"articleSection":["AI","Committee","News","Uncategorized"],"inLanguage":"es","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/youzum.net\/how-to-build-a-meta-cognitive-ai-agent-that-dynamically-adjusts-its-own-reasoning-depth-for-efficient-problem-solving\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/youzum.net\/how-to-build-a-meta-cognitive-ai-agent-that-dynamically-adjusts-its-own-reasoning-depth-for-efficient-problem-solving\/","url":"https:\/\/youzum.net\/how-to-build-a-meta-cognitive-ai-agent-that-dynamically-adjusts-its-own-reasoning-depth-for-efficient-problem-solving\/","name":"How to Build a Meta-Cognitive AI Agent That Dynamically Adjusts Its Own Reasoning Depth for Efficient Problem Solving - YouZum","isPartOf":{"@id":"https:\/\/yousum.gpucore.co\/#website"},"datePublished":"2025-12-04T08:23:36+00:00","description":"\u0e01\u0e34\u0e08\u0e01\u0e23\u0e23\u0e21\u0e40\u0e01\u0e35\u0e48\u0e22\u0e27\u0e01\u0e31\u0e1a\u0e42\u0e14\u0e23\u0e19","breadcrumb":{"@id":"https:\/\/youzum.net\/how-to-build-a-meta-cognitive-ai-agent-that-dynamically-adjusts-its-own-reasoning-depth-for-efficient-problem-solving\/#breadcrumb"},"inLanguage":"es","potentialAction":[{"@type":"ReadAction","target":["https:\/\/youzum.net\/how-to-build-a-meta-cognitive-ai-agent-that-dynamically-adjusts-its-own-reasoning-depth-for-efficient-problem-solving\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/youzum.net\/how-to-build-a-meta-cognitive-ai-agent-that-dynamically-adjusts-its-own-reasoning-depth-for-efficient-problem-solving\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/youzum.net\/"},{"@type":"ListItem","position":2,"name":"How to Build a Meta-Cognitive AI Agent That Dynamically Adjusts Its Own Reasoning Depth for Efficient Problem Solving"}]},{"@type":"WebSite","@id":"https:\/\/yousum.gpucore.co\/#website","url":"https:\/\/yousum.gpucore.co\/","name":"YouSum","description":"","publisher":{"@id":"https:\/\/yousum.gpucore.co\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/yousum.gpucore.co\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"es"},{"@type":"Organization","@id":"https:\/\/yousum.gpucore.co\/#organization","name":"Drone Association Thailand","url":"https:\/\/yousum.gpucore.co\/","logo":{"@type":"ImageObject","inLanguage":"es","@id":"https:\/\/yousum.gpucore.co\/#\/schema\/logo\/image\/","url":"https:\/\/youzum.net\/wp-content\/uploads\/2024\/11\/tranparent-logo.png","contentUrl":"https:\/\/youzum.net\/wp-content\/uploads\/2024\/11\/tranparent-logo.png","width":300,"height":300,"caption":"Drone Association Thailand"},"image":{"@id":"https:\/\/yousum.gpucore.co\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DroneAssociationTH\/"]},{"@type":"Person","@id":"https:\/\/yousum.gpucore.co\/#\/schema\/person\/97fa48242daf3908e4d9a5f26f4a059c","name":"admin NU","image":{"@type":"ImageObject","inLanguage":"es","@id":"https:\/\/yousum.gpucore.co\/#\/schema\/person\/image\/","url":"https:\/\/youzum.net\/wp-content\/uploads\/avatars\/2\/1746849356-bpfull.png","contentUrl":"https:\/\/youzum.net\/wp-content\/uploads\/avatars\/2\/1746849356-bpfull.png","caption":"admin NU"},"url":"https:\/\/youzum.net\/es\/members\/adminnu\/"}]}},"rttpg_featured_image_url":null,"rttpg_author":{"display_name":"admin NU","author_link":"https:\/\/youzum.net\/es\/members\/adminnu\/"},"rttpg_comment":0,"rttpg_category":"<a href=\"https:\/\/youzum.net\/es\/category\/ai-club\/\" rel=\"category tag\">AI<\/a> <a href=\"https:\/\/youzum.net\/es\/category\/committee\/\" rel=\"category tag\">Committee<\/a> <a href=\"https:\/\/youzum.net\/es\/category\/news\/\" rel=\"category tag\">News<\/a> <a href=\"https:\/\/youzum.net\/es\/category\/uncategorized\/\" rel=\"category tag\">Uncategorized<\/a>","rttpg_excerpt":"In this tutorial, we build an advanced meta-cognitive control agent that learns how to regulate its own depth of thinking. We treat reasoning as a spectrum, ranging from fast heuristics to deep chain-of-thought to precise tool-like solving, and we train a neural meta-controller to decide which mode to use for each task. By optimizing the&hellip;","_links":{"self":[{"href":"https:\/\/youzum.net\/es\/wp-json\/wp\/v2\/posts\/55405","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/youzum.net\/es\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/youzum.net\/es\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/youzum.net\/es\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/youzum.net\/es\/wp-json\/wp\/v2\/comments?post=55405"}],"version-history":[{"count":0,"href":"https:\/\/youzum.net\/es\/wp-json\/wp\/v2\/posts\/55405\/revisions"}],"wp:attachment":[{"href":"https:\/\/youzum.net\/es\/wp-json\/wp\/v2\/media?parent=55405"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/youzum.net\/es\/wp-json\/wp\/v2\/categories?post=55405"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/youzum.net\/es\/wp-json\/wp\/v2\/tags?post=55405"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}