Close Menu
  • Home
  • Opinion
  • Region
    • Africa
    • Asia
    • Europe
    • Middle East
    • North America
    • Oceania
    • South America
  • AI & Machine Learning
  • Robotics & Automation
  • Space & Deep Tech
  • Web3 & Digital Economies
  • Climate & Sustainability Tech
  • Biotech & Future Health
  • Mobility & Smart Cities
  • Global Tech Pulse
  • Cybersecurity & Digital Rights
  • Future of Work & Education
  • Trend Radar & Startup Watch
  • Creator Economy & Culture
What's Hot

Embedding compliance in AI adoption

March 24, 2026

Maker Builds Absolutely Working Challenge Hail Mary Management Panel from Trailer Footage Alone

March 24, 2026

MRTIS TechBio Secures Approval for Hong Kong IPO Submitting

March 24, 2026
Facebook X (Twitter) Instagram LinkedIn RSS
NextTech NewsNextTech News
Facebook X (Twitter) Instagram LinkedIn RSS
  • Home
  • Africa
  • Asia
  • Europe
  • Middle East
  • North America
  • Oceania
  • South America
  • Opinion
Trending
  • Embedding compliance in AI adoption
  • Maker Builds Absolutely Working Challenge Hail Mary Management Panel from Trailer Footage Alone
  • MRTIS TechBio Secures Approval for Hong Kong IPO Submitting
  • Rogers celebrates Blue Jays’ fiftieth anniversary with giveaways, new ‘proprietor’ place
  • GCC Electrical Car Tire Market Set for Fast Growth, Anticipated to Attain USD 997 Million by 2032 | MarkNtel Advisors
  • Historic Virginian constructing receives power effectivity improve
  • MTN begins shutdown of Ayoba because it shifts to unified digital platform
  • Info Companies Company wins big value goal increase at Raymond James
Tuesday, March 24
NextTech NewsNextTech News
Home - AI & Machine Learning - Learn how to Design a Manufacturing-Prepared AI Agent That Automates Google Colab Workflows Utilizing Colab-MCP, MCP Instruments, FastMCP, and Kernel Execution
AI & Machine Learning

Learn how to Design a Manufacturing-Prepared AI Agent That Automates Google Colab Workflows Utilizing Colab-MCP, MCP Instruments, FastMCP, and Kernel Execution

NextTechBy NextTechMarch 23, 2026No Comments6 Mins Read
Share Facebook Twitter Pinterest LinkedIn Tumblr Telegram Email Copy Link
Follow Us
Google News Flipboard
Learn how to Design a Manufacturing-Prepared AI Agent That Automates Google Colab Workflows Utilizing Colab-MCP, MCP Instruments, FastMCP, and Kernel Execution
Share
Facebook Twitter LinkedIn Pinterest Email


import asyncio
import json
import io
import contextlib
import re
from dataclasses import dataclass
from typing import Callable, Awaitable
import nest_asyncio
nest_asyncio.apply()


TOOL_DEFINITIONS = [
   {
       "name": "execute_code",
       "description": "Execute Python code in the Colab kernel. Returns stdout, results, or errors. State persists between calls."
       "parameters": {
           "type": "object",
           "properties": {
               "code": {"type": "string", "description": "Python code to execute"},
           },
           "required": ["code"],
       }
   },
   {
       "title": "add_code_cell",
       "description": "Add a code cell to the pocket book at a given index.",
       "parameters": {
           "sort": "object",
           "properties": {
               "cell_index": {"sort": "integer", "description": "Place to insert"},
               "code": {"sort": "string", "description": "Python code for the cell"},
           },
           "required": ["cell_index", "code"],
       }
   },
   {
       "title": "add_text_cell",
       "description": "Add a markdown documentation cell to the pocket book.",
       "parameters": {
           "sort": "object",
           "properties": {
               "cell_index": {"sort": "integer", "description": "Place to insert"},
               "content material": {"sort": "string", "description": "Markdown content material"},
           },
           "required": ["cell_index", "content"],
       }
   },
   {
       "title": "get_cells",
       "description": "Retrieve present pocket book cells and their outputs.",
       "parameters": {
           "sort": "object",
           "properties": {
               "cell_index_start": {"sort": "integer", "description": "Begin index", "default": 0},
               "include_outputs": {"sort": "boolean", "description": "Embrace cell outputs", "default": True},
           },
           "required": [],
       }
   },
]




class NotebookState:


   def __init__(self):
       self.cells: listing[dict] = []
       self.execution_ns: dict = {"__builtins__": __builtins__}


   def add_code_cell(self, index: int, code: str) -> dict:
       cell = {"sort": "code", "supply": code, "outputs": [], "executed": False}
       self.cells.insert(min(index, len(self.cells)), cell)
       return {"standing": "okay", "cell_count": len(self.cells)}


   def add_text_cell(self, index: int, content material: str) -> dict:
       cell = {"sort": "markdown", "supply": content material}
       self.cells.insert(min(index, len(self.cells)), cell)
       return {"standing": "okay", "cell_count": len(self.cells)}


   def execute_code(self, code: str) -> dict:
       stdout_buf = io.StringIO()
       attempt:
           with contextlib.redirect_stdout(stdout_buf):
               attempt:
                   end result = eval(code, self.execution_ns)
                   if end result just isn't None:
                       return {"outputs": [{"type": "result", "text": repr(result)}]}
               besides SyntaxError:
                   exec(code, self.execution_ns)
           out = stdout_buf.getvalue()
           return {"outputs": [{"type": "stdout", "text": out}] if out else []}
       besides Exception as e:
           return {"outputs": [{"type": "error", "text": f"{type(e).__name__}: {e}"}]}


   def get_cells(self, begin: int = 0, include_outputs: bool = True) -> dict:
       return {"cells": self.cells[start:], "whole": len(self.cells)}




class MCPAgentLoop:


   def __init__(self):
       self.pocket book = NotebookState()
       self.historical past: listing[dict] = []
       self.max_iterations = 10


   def _dispatch_tool(self, title: str, args: dict) -> dict:
       if title == "execute_code":
           return self.pocket book.execute_code(args["code"])
       elif title == "add_code_cell":
           return self.pocket book.add_code_cell(args["cell_index"], args["code"])
       elif title == "add_text_cell":
           return self.pocket book.add_text_cell(args["cell_index"], args["content"])
       elif title == "get_cells":
           return self.pocket book.get_cells(
               args.get("cell_index_start", 0),
               args.get("include_outputs", True),
           )
       else:
           return {"error": f"Unknown software: {title}"}


   def _plan(self, job: str, iteration: int, last_result: dict = None) -> listing[dict]:
       task_lower = job.decrease()


       if iteration == 0:
           return [
               {"tool": "add_text_cell", "args": {
                   "cell_index": 0,
                   "content": f"# AI-Generated Analysisnn**Task**: {task}nn"
                              f"*Generated by MCP Agent*"
               }},
           ]
       elif iteration == 1:
           return [
               {"tool": "add_code_cell", "args": {
                   "cell_index": 1,
                   "code": "import randomnimport mathnn"
                           "# Generate sample datan"
                           "random.seed(42)n"
                           "data = [random.gauss(100, 15) for _ in range(500)]n"
                           "print(f'Generated {len(knowledge)} knowledge factors')n"
                           "print(f'Pattern: {knowledge[:5]}')"
               }},
               {"software": "execute_code", "args": {
                   "code": "import randomnimport mathnn"
                           "random.seed(42)n"
                           "knowledge = [random.gauss(100, 15) for _ in range(500)]n"
                           "print(f'Generated {len(knowledge)} knowledge factors')n"
                           "print(f'Pattern: {[round(x,2) for x in data[:5]]}')"
               }},
           ]
       elif iteration == 2:
           return [
               {"tool": "add_code_cell", "args": {
                   "cell_index": 2,
                   "code": "# Statistical analysisn"
                           "mean = sum(data) / len(data)n"
                           "variance = sum((x - mean)**2 for x in data) / len(data)n"
                           "std = variance ** 0.5n"
                           "median = sorted(data)[len(data)//2]n"
                           "print(f'Imply: {imply:.2f}')n"
                           "print(f'Std Dev: {std:.2f}')n"
                           "print(f'Median: {median:.2f}')"
               }},
               {"software": "execute_code", "args": {
                   "code": "imply = sum(knowledge) / len(knowledge)n"
                           "variance = sum((x - imply)**2 for x in knowledge) / len(knowledge)n"
                           "std = variance ** 0.5n"
                           "median = sorted(knowledge)[len(data)//2]n"
                           "print(f'Imply: {imply:.2f}')n"
                           "print(f'Std Dev: {std:.2f}')n"
                           "print(f'Median: {median:.2f}')"
               }},
           ]
       elif iteration == 3:
           return [
               {"tool": "add_text_cell", "args": {
                   "cell_index": 3,
                   "content": "## Results Summarynn"
                              "The analysis is complete. Key findings are computed above."
                              "The data follows a normal distribution centered around 100."
               }},
           ]
       else:
           return []


   async def run(self, job: str):
       print(f"🤖 Agent Activity: {job}")
       print("=" * 60)


       for i in vary(self.max_iterations):
           plan = self._plan(job, i)
           if not deliberate:
               print(f"n🏁 Agent completed after {i} iterations")
               break


           print(f"n--- Iteration {i+1} ---")


           for step in plan:
               tool_name = step["tool"]
               tool_args = step["args"]


               print(f"  🔧 Calling: {tool_name}")
               end result = self._dispatch_tool(tool_name, tool_args)


               self.historical past.append({
                   "iteration": i,
                   "software": tool_name,
                   "end result": end result,
               })


               if "outputs" in end result:
                   for out in end result["outputs"]:
                       prefix = "📤" if out["type"] != "error" else "⚠️"
                       textual content = out["text"][:200]
                       print(f"     {prefix} {textual content}")
               elif "standing" in end result:
                   print(f"     ✅ {end result}")


       print(f"n📓 Closing Pocket book State:")
       print("=" * 60)
       for i, cell in enumerate(self.pocket book.cells):
           icon = "💻" if cell["type"] == "code" else "📝"
           supply = cell["source"][:60] + ("..." if len(cell["source"]) > 60 else "")
           print(f"  [{i}] {icon} {cell['type']:10s} | {supply}")




agent = MCPAgentLoop()
asyncio.run(agent.run("Analyze a dataset with descriptive statistics"))




INTEGRATION_TEMPLATE = '''
import anthropic
import json


shopper = anthropic.Anthropic()


instruments = [
   {
       "name": "colab-proxy-mcp_add_code_cell",
       "description": "Add a Python code cell to the connected Colab notebook",
       "input_schema": {
           "type": "object",
           "properties": {
               "cellIndex": {"type": "integer"},
               "code": {"type": "string"},
               "language": {"type": "string", "default": "python"},
           },
           "required": ["cellIndex", "code"],
       }
   },
   {
       "title": "colab-proxy-mcp_add_text_cell",
       "description": "Add a markdown cell to the linked Colab pocket book",
       "input_schema": {
           "sort": "object",
           "properties": {
               "cellIndex": {"sort": "integer"},
               "content material": {"sort": "string"},
           },
           "required": ["cellIndex", "content"],
       }
   },
   {
       "title": "colab-proxy-mcp_execute_cell",
       "description": "Execute a cell within the linked Colab pocket book",
       "input_schema": {
           "sort": "object",
           "properties": {
               "cellIndex": {"sort": "integer"},
           },
           "required": ["cellIndex"],
       }
   },
   {
       "title": "colab-proxy-mcp_get_cells",
       "description": "Get cells from the linked Colab pocket book",
       "input_schema": {
           "sort": "object",
           "properties": {
               "cellIndexStart": {"sort": "integer", "default": 0},
               "includeOutputs": {"sort": "boolean", "default": True},
           },
       }
   },
   {
       "title": "runtime_execute_code",
       "description": "Execute Python code instantly within the Colab kernel (Runtime Mode)",
       "input_schema": {
           "sort": "object",
           "properties": {
               "code": {"sort": "string"},
           },
           "required": ["code"],
       }
   },
]




def run_agent(job: str, max_turns: int = 15):
   messages = [{"role": "user", "content": task}]


   for flip in vary(max_turns):
       response = shopper.messages.create(
           mannequin="claude-sonnet-4-20250514",
           max_tokens=4096,
           instruments=instruments,
           messages=messages,
           system="You're an AI assistant with entry to a Google Colab pocket book."
                  "through MCP instruments. Construct notebooks step-by-step: add markdown cells "
                  "For documentation, add code cells, then execute them. "
                  "Examine outputs and repair errors iteratively."
       )


       assistant_content = response.content material
       messages.append({"position": "assistant", "content material": assistant_content})


       if response.stop_reason == "end_turn":
           print("Agent completed.")
           break


       tool_results = []
       for block in assistant_content:
           if block.sort == "tool_use":
               print(f"Instrument name: {block.title}({json.dumps(block.enter)[:100]})")


               end result = dispatch_to_mcp_server(block.title, block.enter)


               tool_results.append({
                   "sort": "tool_result",
                   "tool_use_id": block.id,
                   "content material": json.dumps(end result),
               })


       if tool_results:
           messages.append({"position": "person", "content material": tool_results})
       else:
           break




def dispatch_to_mcp_server(tool_name: str, tool_input: dict) -> dict:
   increase NotImplementedError("Use the MCP SDK for actual software dispatch")
'''


print(INTEGRATION_TEMPLATE)
print("n" + "=" * 60)
print("💡 The template above reveals how one can join an actual LLM to colab-mcp.")
print("   For Claude Code: simply add the MCP config and begin chatting!")
print("   For customized brokers: use the Anthropic SDK with tool_use.")

Elevate your perspective with NextTech Information, the place innovation meets perception.
Uncover the most recent breakthroughs, get unique updates, and join with a world community of future-focused thinkers.
Unlock tomorrow’s traits at the moment: learn extra, subscribe to our e-newsletter, and develop into a part of the NextTech neighborhood at NextTech-news.com

Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
NextTech
  • Website

Related Posts

Yann LeCun’s New LeWorldModel (LeWM) Analysis Targets JEPA Collapse in Pixel-Based mostly Predictive World Modeling

March 24, 2026

Meta AI’s New Hyperagents Don’t Simply Resolve Duties—They Rewrite the Guidelines of How They Study

March 24, 2026

Luma Labs Launches Uni-1: The Autoregressive Transformer Mannequin that Causes via Intentions Earlier than Producing Pictures

March 24, 2026
Add A Comment
Leave A Reply Cancel Reply

Economy News

Embedding compliance in AI adoption

By NextTechMarch 24, 2026

Kyndryl’s Ismail Amla discusses the corporate’s new coverage as code course of, and the way…

Maker Builds Absolutely Working Challenge Hail Mary Management Panel from Trailer Footage Alone

March 24, 2026

MRTIS TechBio Secures Approval for Hong Kong IPO Submitting

March 24, 2026
Top Trending

Embedding compliance in AI adoption

By NextTechMarch 24, 2026

Kyndryl’s Ismail Amla discusses the corporate’s new coverage as code course of,…

Maker Builds Absolutely Working Challenge Hail Mary Management Panel from Trailer Footage Alone

By NextTechMarch 24, 2026

Matt from Inventive Geekery knew from the second he noticed the cockpit…

MRTIS TechBio Secures Approval for Hong Kong IPO Submitting

By NextTechMarch 24, 2026

MRTIS TechBio (Beijing) Co., Ltd., an AI-driven nanomedicine firm, has obtained regulatory…

Subscribe to News

Get the latest sports news from NewsSite about world, sports and politics.

NEXTTECH-LOGO
Facebook X (Twitter) Instagram YouTube

AI & Machine Learning

Robotics & Automation

Space & Deep Tech

Web3 & Digital Economies

Climate & Sustainability Tech

Biotech & Future Health

Mobility & Smart Cities

Global Tech Pulse

Cybersecurity & Digital Rights

Future of Work & Education

Creator Economy & Culture

Trend Radar & Startup Watch

News By Region

Africa

Asia

Europe

Middle East

North America

Oceania

South America

2025 © NextTech-News. All Rights Reserved
  • About Us
  • Contact Us
  • Privacy Policy
  • Terms Of Service
  • Advertise With Us
  • Write For Us
  • Submit Article & Press Release

Type above and press Enter to search. Press Esc to cancel.

Subscribe For Latest Updates

Sign up to best of Tech news, informed analysis and opinions on what matters to you.

Invalid email address
 We respect your inbox and never send spam. You can unsubscribe from our newsletter at any time.     
Thanks for subscribing!