Friday, December 19, 2025

Tool Calling in AI: Turning Language Models into Action-Driven Agents

Large language models (LLMs) have transformed how humans interact with machines. However, the real breakthrough comes when these models stop being passive responders and start becoming active problem solvers. This transition is powered by a capability known as tool calling.

In this blog, we will explore what tool calling is, why it matters, how it works internally, and how it enables agentic AI systems capable of real-world action.

What Is Tool Calling?

At its core, tool calling refers to an AI model’s ability to interact with external tools, APIs, databases, or systems to extend its native capabilities.

Traditional LLMs operate purely on pretrained knowledge. They generate answers based on patterns learned during training. But, this approach has a hard limit:

they cannot access real-time data, perform live computations, or take direct actions.

Tool calling removes this limitation.

With tool calling enabled, an AI system can:

  • Query live databases

  • Fetch real-time information (weather, stock prices, system status)

  • Execute functions or scripts

  • Trigger workflows and automation

  • Interact with enterprise systems

This capability is sometimes called function calling, and it is one of the foundational pillars of agentic AI.

Instead of merely answering questions, LLMs with tool calling can decide, act, and iterate—much like a digital agent.

NOTE:  Agent is a system with an LLM at its core that is able to make decisions on what actions to take as it works to answer the prompt it received. The most common actions LLM agents can be built to take are: sending text or other media to the user, calling a tool to help answer the user, and calling another agent to help answer the user. Generally speaking, an LLM agent will also have a system prompt explaining what its role is and giving it some rules over when to call tools and/or reply to the user. For most Agents, the control flow can be shown as follows:


source

Why is Tool Calling Important 

Limits if static knowledge: Even the most advanced LLMs are constrained by:

  • Training data cutoffs

  • Lack of real-time awareness

  • Inability to perform live computations

  • No direct access to user-specific systems

Early models such as GPT-2 were entirely static. They produced impressive text but had no concept of now.
Ask them about today’s weather or current stock prices, and they simply could not answer accurately.

The Need for Real-World Interaction

As AI moved into production systems—finance, healthcare, DevOps, customer support—the need for:

  • Live data

  • External computation

  • User-specific actions

became unavoidable.

This led to the introduction of tool calling, where models are trained to:

  1. Recognize when external help is needed

  2. Select the correct tool

  3. Generate structured requests

  4. Interpret structured responses

Critically, tools often expect strict input schemas, not free-form text. Tool calling ensures model outputs conform to these schemas, making AI-system integration reliable and safe.

How Does Tool Calling Work?

Modern LLMs such as Claude, Llama 3, Mistral, and IBM Granite - all support tool calling, though implementation details may vary.

At a high level, the process involves six steps.

Step 1: Recognizing the Need for a Tool

Imagine a user asks:

“What’s the weather in San Francisco right now?”

The model immediately understands:

  • This requires real-time data

  • The answer cannot come from its static training set

At this point, the model decides to invoke a tool.
A unique tool call ID is generated to track the request and its eventual response.

Step 2: Selecting the Right Tool

Next, the model chooses the most appropriate tool—perhaps a weather API.

Each tool is described using metadata, including:

  • Tool (or function) name

  • Description

  • Input parameters

  • Input and output data types

This metadata allows the model to reason about:

  • Which tool to use

  • What arguments it must provide

Tool selection is not random—it is a learned decision based on context.

Step 3: Preparing the Arguments (Args)

Once the tool is selected, the model constructs structured arguments (often called args).

For example:

  • City: San Francisco

  • Units: Celsius

  • Timestamp: current

These arguments must strictly match the tool’s expected schema.

To ensure consistency, developers often use templates or structured prompts that guide the model on:

  • Which tool to call

  • What arguments to pass

This is where tool calling differs from free-form prompting—it is contract-driven.

Tool Calling + RAG: A Powerful Combination

Tool calling becomes even more effective when combined with Retrieval Augmented Generation (RAG).

With RAG:

  • The model retrieves relevant structured and unstructured data

  • Then uses that data to generate a grounded response

Benefits include:

  • Higher contextual accuracy

  • Reduced hallucinations

  • Lower API overhead

  • Greater flexibility across domains

Unlike rigid tool calls, RAG allows more fluid reasoning by blending retrieved knowledge with generation.

Step 4: Making the API Call

Each tool is backed by an API, documented via:

  • Endpoints

  • HTTP methods

  • Request/response formats

Many APIs require authentication via an API key.

Once arguments are prepared, the model (or orchestration layer) sends an HTTP request to the external system.

Step 5: Receiving and Processing the Response

The external tool returns structured data—commonly in JSON format.

For a weather API, this might include:

  • Temperature

  • Humidity

  • Wind speed

The AI then:

  • Parses the response

  • Filters relevant fields

  • Transforms raw data into a human-friendly explanation

Step 6: Acting or Responding

Finally, the AI either:

  • Presents the information to the user, or

  • Confirms an action (e.g., “Your reminder has been scheduled.”)

If the user asks follow-up questions, the model can repeat the cycle with refined parameters—enabling iterative reasoning.


How Do LLMs Call Tools?

For an LLM (Large Language Model) to call a tool, it needs a structured way to specify which tool it wants to use and what arguments to pass. Since an LLM outputs plain text tokens, an external system must parse this output and execute the tool call. This means the LLM should produce structured or semi-structured data consistently.

Different APIs implement this differently, but the concept is the same across platforms. Let’s look at how the OpenAI Chat API handles this.

When using the OpenAI Chat API, you provide a list of tools the LLM can access. Each tool is defined with:

  • Name of the tool
  • Description of what it does
  • Parameters (including type, description, and whether they are required)

Here’s an example tool definition:

{
    "type": "function",
    "function": {
        "name": "calculate_distance",
        "description": "Calculate the distance between two cities",
        "parameters": {
            "type": "object",
            "properties": {
                "city_a": {
                    "type": "string",
                    "description": "Name of the first city, e.g., New York"
                },
                "city_b": {
                    "type": "string",
                    "description": "Name of the second city, e.g., Los Angeles"
                },
                "unit": {
                    "type": "string",
                    "enum": ["kilometers", "miles"]
                }
            },
            "required": ["city_a", "city_b"]
        }
    }

}

This JSON would be included in the API call so the LLM knows it can use calculate_distance. If you don’t include it, the LLM won’t know the tool exists.

How Does the LLM Decide to Call a Tool?

When the LLM responds, you check the tool_calls property in the response. For example, in Python:

response_message = response.choices[0].message
tool_calls = response_message.tool_calls

tool_calls will contain an array of tools the LLM wants to invoke, along with the arguments. Your system then executes the corresponding function or method with those arguments.This approach allows the LLM to reason about when to use a tool and provide structured arguments, while your application handles the actual execution

source

Agent Workflow as described below :

  1. Receive the Query
    The agent gets a natural-language request or task from the user or an external system.

  2. Discover Available Tools
    It looks up internal metadata or a tool registry to find relevant tools, schemas, and capabilities.

  3. Select and Invoke the Right Tool
    The LLM processes the query along with tool metadata (such as function names, input types, and descriptions).
    It chooses the most appropriate tool, prepares the input arguments, and generates a structured function call.

  4. Execute the Tool
    The agent shell or tool runner runs the selected function and retrieves the output (e.g., API response, database value, or computation result).

  5. Return the Final Response
    The LLM incorporates the tool’s result into its prompt and produces a natural-language answer for the user
    .

    =====================================

    Key Capabilities :

  • Dynamic Tool Selection
    Automatically picks the right tool based on the context of the task.

  • Schema-Aware Prompting
    Supports structured interfaces like OpenAPI, JSON Schema, and AWS function definitions for precise interactions.

  • Intelligent Output Handling
    Interprets results and chains outputs into logical reasoning for complex workflows.

  • Flexible Execution Modes
    Works in both stateless and session-aware environments.


Common Use Cases :

  • Virtual Assistants with External Data Access
    Enhance assistants by connecting them to APIs and real-time data sources.

  • Financial Calculators and Estimators
    Perform dynamic computations and provide accurate projections.

  • API-Driven Knowledge Workers
    Automate tasks that require pulling and processing data from multiple services.

  • LLM-Powered Integrations
    Invoke AWS Lambda, Amazon SageMaker endpoints, and SaaS tools for advanced functionality.

==================================================

LangChain and Tool Calling

LangChain is one of the most widely used frameworks for implementing tool calling.

It provides:

  • Tool registration

  • Argument parsing

  • Context-aware routing

  • Memory across multiple interactions

Unlike basic tool calling, LangChain can:

  • Chain multiple tools together

  • Store previous tool outputs

  • Enable complex, multi-step agent workflows

For example:

  1. Call a weather API

  2. Use results to trigger a clothing recommendation tool

  3. Generate a final personalized response

This is a practical implementation of agentic AI.

Common Types of Tool Calling Use Cases

While possibilities are endless, most applications fall into a few major categories.

1. Information Retrieval and Search

AI pulls real-time data from:

  • Web search engines

  • Financial markets

  • Academic databases

  • News sources

Example: Fetching live stock prices or breaking news inside a chatbot.

2. Code Execution and Computation

AI executes:

  • Mathematical calculations

  • Simulations

  • Scripts via Python or engines like Wolfram Alpha

Useful for analytics, engineering, and scientific domains.

3. Process Automation

AI automates workflows by integrating with:

  • Calendars

  • Email systems

  • CRM tools (Salesforce)

  • Finance platforms (QuickBooks)

This enables AI-driven business operations.

4. Smart Devices and IoT Control

Agentic systems can monitor and control:

  • Smart homes

  • Industrial sensors

  • Robotics platforms

This opens the door to fully autonomous, end-to-end workflows.


Final Thoughts

Tool calling is not just a feature, it is a paradigm shift.

It allows LLMs to:

  • Know when they don’t know

  • Reach outside themselves

  • Act in the real world

  • Continuously refine outcomes

As AI systems evolve, tool calling will be the foundation that turns language models into true digital agents—capable of reasoning, acting, and collaborating across complex environments.If language is intelligence, tool calling is agency.

--------------------------------------BACKUP INFO-------------------------------

Sample code:

Below is a complete Python example that shows:

  1. Defining tools
  2. Making a chat completion request
  3. Reading tool_calls and parsing JSON arguments
  4. Executing your local functions
  5. Returning tool outputs back to the model for a final answer
# pip install openai
from openai import OpenAI
import json

# Initialize client
client = OpenAI(api_key="YOUR_API_KEY")

# Define one tool
tools = [
    {
        "type": "function",
        "function": {
            "name": "get_city_coordinates",
            "description": "Return approximate latitude and longitude for a city",
            "parameters": {
                "type": "object",
                "properties": {
                    "city": {"type": "string", "description": "City name"}
                },
                "required": ["city"]
            }
        }
    }
]

# Local function to execute
def get_city_coordinates(city):
    # Hardcoded example
    coords = {
        "New York": (40.7128, -74.0060),
        "Los Angeles": (34.0522, -118.2437),
        "Bangalore": (12.9716, 77.5946)
    }
    lat, lon = coords.get(city, (None, None))
    return {"city": city, "latitude": lat, "longitude": lon}

# User message
messages = [{"role": "user", "content": "Give me the coordinates of Bangalore"}]

# First call: model decides if it needs the tool
resp = client.chat.completions.create(
    model="gpt-4o-mini",  # Use a tool-capable model
    messages=messages,
    tools=tools,
    tool_choice="auto"
)

# Check if model requested a tool
tool_calls = resp.choices[0].message.tool_calls or []
tool_msgs = []
for call in tool_calls:
    # Parse JSON arguments
    args = json.loads(call.function.arguments)
    result = get_city_coordinates(args["city"])
    # Send tool result back to model
    tool_msgs.append({
        "role": "tool",
        "tool_call_id": call.id,
        "content": json.dumps(result)
    })

# Second call: model uses tool result to finish answer
finalfinal = client.chat.completions.create(
    model="gpt-4o-mini",
    messages=messages + [resp.choices[0].message] + tool_msgs
)

How It Works

  1. tools: Defines the schema so the model knows what arguments to provide.
  2. First API call: Model decides if it needs the tool and returns tool_calls.
  3. Parse arguments: call.function.arguments is a JSON string → json.loads().
  4. Execute local function: get_city_coordinates(city).
  5. Send result back: Add a message with role="tool" and tool_call_id.
  6. Second API call: Model uses the tool output to generate the final answer.
============================
EXAMPLE 2: How to add functions ?


# pip install openai
from openai import OpenAI
import json

client = OpenAI(api_key="YOUR_API_KEY")

# 1) Define your tool schema. The model uses this to learn how to call your functions.
tools = [
    {
        "type": "function",
        "function": {
            "name": "calculate_distance",
            "description": "Calculate great-circle distance between two cities",
            "parameters": {
                "type": "object",
                "properties": {
                    "city_a": {"type": "string", "description": "First city, e.g., New York"},
                    "city_b": {"type": "string", "description": "Second city, e.g., Los Angeles"},
                    "unit": {
                        "type": "string",
                        "enum": ["kilometers", "miles"],
                        "description": "Distance unit"
                    }
                },
                "required": ["city_a", "city_b"]
            }
        }
    },
    {
        "type": "function",
        "function": {
            "name": "get_city_coordinates",
            "description": "Return approximate latitude and longitude for a city",
            "parameters": {
                "type": "object",
                "properties": {
                    "city": {"type": "string", "description": "City name"}
                },
                "required": ["city"]
            }
        }
    }
]

# 2) Implement the actual Python functions the model can call.
# In production, replace these with real logic (DB lookup, API calls, etc.)
CITY_DB = {
    "New York": (40.7128, -74.0060),
    "Los Angeles": (34.0522, -118.2437),
    "San Francisco": (37.7749, -122.4194),
    "Bangalore": (12.9716, 77.5946),
}

from math import radians, sin, cos, sqrt, atan2

def get_city_coordinates(city: str):
    if city not in CITY_DB:
        raise ValueError(f"Unknown city: {city}")
    lat, lon = CITY_DB[city]
    return {"city": city, "latitude": lat, "longitude": lon}

def calculate_distance(city_a: str, city_b: str, unit: str = "kilometers"):
    # Get coords
    lat1, lon1 = CITY_DB.get(city_a, (None, None))
    lat2, lon2 = CITY_DB.get(city_b, (None, None))
    if lat1 is None or lat2 is None:
        raise ValueError("One or both cities unknown")

    # Haversine
    R_km = 6371.0
    R_mi = 3958.8

    phi1, phi2 = radians(lat1), radians(lat2)
    dphi = radians(lat2 - lat1)
    dlambda = radians(lon2 - lon1)

    a = sin(dphi / 2) ** 2 + cos(phi1) * cos(phi2) * sin(dlambda / 2) ** 2
    c = 2 * atan2(sqrt(a), sqrt(1 - a))
    d_km = R_km * c
    d_mi = R_mi * c

    if unit == "miles":
        return {"city_a": city_a, "city_b": city_b, "distance": round(d_mi, 2), "unit": "miles"}
    else:
        return {"city_a": city_a, "city_b": city_b, "distance": round(d_km, 2), "unit": "kilometers"}

# 3) Start the conversation. The user asks something that likely requires tools.
messages = [
    {"role": "system", "content": "You are a helpful assistant."},
    {
        "role": "user",
        "content": "What is the distance between New York and Los Angeles in miles? Also share coordinates for Los Angeles."
    },
]

# 4) First model call with tools listed. The model may decide to call one or more tools.
first_response = client.chat.completions.create(
    model="gpt-4o-mini",   # Choose a tool-capable model
    messages=messages,
    tools=tools,
    tool_choice="auto"      # Let the model decide whether and which tools to call
)

# 5) Check if the model wants to call tools.
# This is where the JSON arguments live: tool_call.function.arguments is a JSON string.
tool_calls = first_response.choices[0].message.tool_calls or []

# If there are tool calls, execute them and gather results.
tool_results_messages = []
for call in tool_calls:
    tool_name = call.function.name
    # The arguments come as a JSON string. Parse it to a dict.
    args = json.loads(call.function.arguments)

    try:
        if tool_name == "calculate_distance":
            result = calculate_distance(
                city_a=args.get("city_a"),
                city_b=args.get("city_b"),
                unit=args.get("unit", "kilometers"),
            )
        elif tool_name == "get_city_coordinates":
            result = get_city_coordinates(args.get("city"))
        else:
            result = {"error": f"Unknown tool {tool_name}"}
    except Exception as e:
        result = {"error": str(e)}

    # Add a tool result message. The role must be "tool" and the tool_call_id must match.
    tool_results_messages.append({
        "role": "tool",
        "tool_call_id": call.id,
        "content": json.dumps(result)
    })

# 6) Send the tool outputs back to the model to let it finish the answer.
final_messages = messages + [first_response.choices[0].message] + tool_results_messages


final_response = client.chat.completions.create(
    model="gpt-4o-mini",
    messages=final_messages
)

Key points to notice :

  • Where do the JSON input args go?
    The model returns them in tool_calls[i].function.arguments as a JSON string. You must json.loads(...) that string to get a Python dict to call your function.

  • Returning tool outputs back to the model
    You send a new message with role="tool", include the tool_call_id from the original call, and put your tool’s output in content(commonly JSON).

  • Finalization step
    After you add the tool result messages, call the model again so it can synthesize a natural language answer using the tool outputs.

====================

Example 3 : Minimal example showing a remote API call as the “execute locally” step

workflow: 

define tools → let the model decide → parse arguments → execute locally → return results → finalize answer

NOTE: execute locally = execute in your code. Where your code reaches out is your choice.Local code that calls external systems, code makes a request to a remote DB or API.Your code enqueues a job to a worker or serverless function

from openai import OpenAI
import json
import requests  # pip install requests

client = OpenAI(api_key="YOUR_API_KEY")

# Tool schema that asks the model to provide a username
tools = [
    {
        "type": "function",
        "function": {
            "name": "get_user_profile",
            "description": "Fetch a user's profile from a remote service",
            "parameters": {
                "type": "object",
                "properties": {
                    "username": {"type": "string", "description": "Login name"}
                },
                "required": ["username"]
            }
        }
    }
]

# Local function that calls an external API
def get_user_profile(username):
    try:
        # External call. This is the execute locally step in your app.
        resp = requests.get(
            f"https://api.example.com/users/{username}",
            timeout=5
        )
        resp.raise_for_status()
        data = resp.json()
        # Always return a JSON-serializable object
        return {
            "username": data.get("username"),
            "full_name": data.get("full_name"),
            "email": data.get("email"),
            "status": "ok"
        }
    except requests.exceptions.Timeout:
        return {"error": "timeout", "status": "failed"}
    except requests.exceptions.HTTPError as e:
        return {"error": f"http {e.response.status_code}", "status": "failed"}
    except Exception as e:
        return {"error": str(e), "status": "failed"}

messages = [{"role": "user", "content": "Show the profile for user alice"}]

# First call: model decides to call the tool and provides JSON args
first = client.chat.completions.create(
    model="gpt-4o-mini",
    messages=messages,
    tools=tools,
    tool_choice="auto"
)

tool_calls = first.choices[0].message.tool_calls or []
tool_messages = []

for call in tool_calls:
    args = json.loads(call.function.arguments)
    result = get_user_profile(args["username"])
    tool_messages.append({
        "role": "tool",
        "tool_call_id": call.id,
        "content": json.dumps(result)
    })

# Second call: model reads tool outputs and finalizes the answer
final_messages = messages + [first.choices[0].message] + tool_messages

final = client.chat.completions.create(
    model="gpt-4o-mini",
    messages=final_messages
)

Example 4: Multi-agent setup with orchestration demonstrates a two-agent workflow using tool calls. It shows:
  • Agent 1 (DataAgent) calculates distance between two cities using tools
  • Agent 2 (ReportAgent) formats the result using its own tool
  • An orchestrator glues the two agents together

# pip install openai
from openai import OpenAI
import json
from math import radians, sin, cos, sqrt, atan2

# Initialize OpenAI client
client = OpenAI(api_key="YOUR_API_KEY")

# ---------------------------------------------
# Shared data for tools
# ---------------------------------------------
CITY_DB = {
    "Bangalore": (12.9716, 77.5946),
    "Los Angeles": (34.0522, -118.2437),
    "New York": (40.7128, -74.0060),
    "San Francisco": (37.7749, -122.4194),
}

# ---------------------------------------------
# Local tool implementations for Agent 1
# ---------------------------------------------
def get_city_coordinates(city: str):
    if city not in CITY_DB:
        raise ValueError(f"Unknown city: {city}")
    lat, lon = CITY_DB[city]
    return {"city": city, "latitude": lat, "longitude": lon}

def calculate_distance(city_a: str, city_b: str, unit: str = "kilometers"):
    lat1, lon1 = CITY_DB.get(city_a, (None, None))
    lat2, lon2 = CITY_DB.get(city_b, (None, None))
    if lat1 is None or lat2 is None:
        raise ValueError("One or both cities unknown")

    # Haversine formula
    R_km = 6371.0
    R_mi = 3958.8

    phi1, phi2 = radians(lat1), radians(lat2)
    dphi = radians(lat2 - lat1)
    dlambda = radians(lon2 - lon1)

    a = sin(dphi / 2) ** 2 + cos(phi1) * cos(phi2) * sin(dlambda / 2) ** 2
    c = 2 * atan2(sqrt(a), sqrt(1 - a))
    d_km = R_km * c
    d_mi = R_mi * c

    if unit == "miles":
        return {"city_a": city_a, "city_b": city_b, "distance": round(d_mi, 2), "unit": "miles"}
    else:
        return {"city_a": city_a, "city_b": city_b, "distance": round(d_km, 2), "unit": "kilometers"}

# ---------------------------------------------
# Local tool implementations for Agent 2
# ---------------------------------------------
def format_summary(city_a: str, city_b: str, distance: float, unit: str):
    bullets = [
        f"Route: {city_a} to {city_b}",
        f"Distance: {distance} {unit}",
        "Method: Great circle approximation",
        "Use case: Travel planning and logistics"
    ]
    conclusion = f"In summary, the distance between {city_a} and {city_b} is {distance} {unit}."
    return {"bullets": bullets, "conclusion": conclusion}

# ---------------------------------------------
# Tool schemas
# ---------------------------------------------
DATA_AGENT_TOOLS = [
    {
        "type": "function",
        "function": {
            "name": "get_city_coordinates",
            "description": "Return latitude and longitude for a known city",
            "parameters": {
                "type": "object",
                "properties": {
                    "city": {"type": "string", "description": "City name"}
                },
                "required": ["city"]
            }
        }
    },
    {
        "type": "function",
        "function": {
            "name": "calculate_distance",
            "description": "Calculate great circle distance between two cities",
            "parameters": {
                "type": "object",
                "properties": {
                    "city_a": {"type": "string"},
                    "city_b": {"type": "string"},
                    "unit": {"type": "string", "enum": ["kilometers", "miles"]}
                },
                "required": ["city_a", "city_b"]
            }
        }
    }
]

REPORT_AGENT_TOOLS = [
    {
        "type": "function",
        "function": {
            "name": "format_summary",
            "description": "Create a short bullet list and conclusion from computed distance",
            "parameters": {
                "type": "object",
                "properties": {
                    "city_a": {"type": "string"},
                    "city_b": {"type": "string"},
                    "distance": {"type": "number"},
                    "unit": {"type": "string"}
                },
                "required": ["city_a", "city_b", "distance", "unit"]
            }
        }
    }
]

# ---------------------------------------------
# Agent class: runs a single tool-capable turn
# ---------------------------------------------
class Agent:
    def __init__(self, name: str, system_prompt: str, tools: list, tool_impls: dict):
        self.name = name
        self.system_prompt = system_prompt
        self.tools = tools
        self.tool_impls = tool_impls

    def run_turn(self, user_or_context_messages: list, model: str = "gpt-4o-mini"):
        """
        Takes incoming messages, lets the model decide tool calls,
        executes tools locally, returns final assistant text and the tool results.
        """
        # First call: let model decide whether to call tools
        first = client.chat.completions.create(
            model=model,
            messages=[{"role": "system", "content": self.system_prompt}] + user_or_context_messages,
            tools=self.tools,
            tool_choice="auto"
        )

        assistant_msg = first.choices[0].message
        tool_calls = assistant_msg.tool_calls or []
        tool_result_messages = []
        collected_results = []  # Keep structured results for orchestration

        # Execute each requested tool
        for call in tool_calls:
            fn_name = call.function.name
            args = json.loads(call.function.arguments)

            try:
                fn = self.tool_impls.get(fn_name)
                if fn is None:
                    result = {"error": f"Unknown tool {fn_name}"}
                else:
                    result = fn(**args)
            except Exception as e:
                result = {"error": str(e)}

            # Store the structured result for the orchestrator
            collected_results.append({"name": fn_name, "args": args, "result": result})

            # Return result to the model using role="tool" with matching tool_call_id
            tool_result_messages.append({
                "role": "tool",
                "tool_call_id": call.id,
                "content": json.dumps(result)
            })

        # Second call: model reads tool outputs and produces a final assistant message
        final_messages = [{"role": "system", "content": self.system_prompt}] + user_or_context_messages +[assistant_msg] + tool_result_messages
        final = client.chat.completions.create(model=model, messages=final_messages)
        final_text = final.choices[0].message.content

        return final_text, collected_results

# ---------------------------------------------
# Instantiate two agents
# ---------------------------------------------
data_agent = Agent(
    name="DataAgent",
    system_prompt=(
        "You are a precise data agent. Use tools to compute distances and coordinates. "
        "Answer concisely and include structured context if helpful."
    ),
    tools=DATA_AGENT_TOOLS,
    tool_impls={
        "get_city_coordinates": get_city_coordinates,
        "calculate_distance": calculate_distance
    }
)

report_agent = Agent(
    name="ReportAgent",
    system_prompt=(
        "You are a clear technical writer. Format results with helpful bullets and a concise conclusion. "
        "Prefer calling the formatting tool when raw values are given."
    ),
    tools=REPORT_AGENT_TOOLS,
    tool_impls={
        "format_summary": format_summary
    }
)

# ---------------------------------------------
# Orchestration: two agent workflow
# ---------------------------------------------
def run_two_agent_workflow(city_a: str, city_b: str, unit: str = "miles"):
    # Step 1: User asks for a report that requires computation
    user_message = {
        "role": "user",
        "content": f"Compute the distance between {city_a} and {city_b} in {unit}. Then present a short professional report."
    }

    # Step 2: DataAgent computes using its tools
    data_text, data_results = data_agent.run_turn([user_message])

    # Extract the distance result from DataAgent tool outputs
    # We search for calculate_distance result
    distance_payload = None
    for item in data_results:
        if item["name"] == "calculate_distance" and "result" in item:
            distance_payload = item["result"]
            break

    if distance_payload is None:
        # Fallback if model did not call the tool
        # In a production system you would retry or ask the model to call the tool explicitly
        raise RuntimeError("DataAgent did not produce a distance result")

    # Step 3: Prepare input for ReportAgent
    # We provide both the narrative from DataAgent and the structured JSON payload
    report_messages = [
        {"role": "user", "content": "Create a short professional report from the following computed data."},
        {"role": "user", "content": json.dumps(distance_payload)}
    ]

    # Step 4: ReportAgent formats the result using its tool
    report_text, _ = report_agent.run_turn(report_messages)

    # Step 5: Return final report to the caller
    return {
        "data_agent_answer": data_text,
        "report_agent_answer": report_text,
        "distance_payload": distance_payload
    }

# ---------------------------------------------
# Demo run
# ---------------------------------------------
if __name__ == "__main__":
    result = run_two_agent_workflow("Bangalore", "Los Angeles", unit="miles")
    print("\n=== DataAgent output ===\n")
    print(result["data_agent_answer"])
    print("\n=== ReportAgent final report ===\n")
    print(result["report_agent_answer"])
    print("\n=== Raw computed payload ===\n")

How this works

  1. Each agent has its own system prompt, tool schema, and Python functions.
  2. For each agent, we make a first call with tools=... and tool_choice="auto".
  3. We parse assistant_msg.tool_calls[i].function.arguments which is a JSON string.
  4. We execute the requested local function and return a tool message with role="tool" and tool_call_id.
  5. We make a second call for the agent to finalize the answer.
  6. The orchestrator passes the computed JSON payload from Agent 1 to Agent 2, which formats the report via its own tool.
NOTE: This is a minimal synchronous pattern. In production you might add retries, timeouts, logging, and guardrails.
-------------------------------------------------

AI Agents : Systems that act autonomously to achieve goals using reasoning , memory and tools. Build on top of LLM with planning and execution loops

Types:
1) Reactive  Agent. : Respond instantly  example chatbots 
2) Planning agent : reason , plan  and execute Muti step tasks 
3) collaborative agent : coordinate with other Agents or Humans

Agent Architecture :

1) Planner : Decides next actions 
2) Executor: Performs action via tools or APIs
3) Memory: short term memory(chat context) and log-term (Vector store)
4) Reasoner : Evaluates progress and adapts plan
5) Interface : connects with user or system

-----------------------------------------

Understanding RAG: How Retrieval-Augmented Generation Works

RAG is a powerful technique that combines search and generation to make AI responses accurate, grounded, and up-to-date. Instead of relying only on what a language model learned during training, RAG allows it to pull in fresh, private, or domain-specific data on the fly.

Let’s break it down into four key stages:

1. Indexing – Preparing Your Knowledge Base

Before AI can answer questions using your documents, those documents need to be transformed into a searchable format.

How it works:

  • Start with raw content: PDFs, Word files, notes, web pages, etc.
  • Extract text: Pull plain text from these sources.
  • Chunking: Split long text into smaller, manageable pieces. This matters because LLMs can’t process huge blocks efficiently.
  • Vectorization: Convert each chunk into a numerical representation called a vector, which captures the meaning of the text.
  • Embedding model: A specialized model performs this text-to-vector conversion.
  • Store in a vector database: All vectors are saved in a database optimized for similarity search.

2. Retrieval – Finding Relevant Information

When a user asks a question, the system fetches the most relevant chunks from the indexed data.

Steps:

  • User submits a query: Example: “What does the contract say about termination?”
  • Convert query to a vector: Using the same embedding model as before.
  • Similarity search: Compare the query vector with stored document vectors.
  • Return top matches: The system outputs the most relevant text chunks.

3. Augmentation – Building Context for the Model

The retrieved chunks are combined with the user’s question to create a rich, context-aware prompt.

Process:

  • Gather relevant chunks.
  • Merge them into a clean context block.
  • Construct a new prompt that includes:
    1. The original question
    2. The retrieved context
  • This augmented prompt gives the LLM the background knowledge it needs.

4. Generation – Producing a Grounded Answer

Finally, the enriched prompt is sent to the language model.

What happens:

  • The LLM reads both the question and the retrieved context.
  • It generates a response based on actual data, not guesses.
  • The output is accurate, explainable, and tied to your documents.

---------------------

Why RAG Matters

  • Standard LLMs rely only on their training data.
  • RAG enables models to use your private or latest information.
  • Updating knowledge is as simple as updating your indexed documents.

 This approach is widely used in enterprise search, chatbots, legal document analysis, and customer support systems.

-----------------------------
How LLM Agents Combine Memory, Planning, and Tools for Intelligent Task Execution


  1. Receive query and fetch memory

    • The agent takes the user query.
    • It retrieves relevant session memory or long-term memory (for user preferences, past decisions, cached results).
  2. Discover tools via MCP

    • The agent searches the MCP Tools Registry for available tools, schemas, and capabilities.
    • Examples: OpenAPI specs, JSON Schema, AWS Lambda functions, SageMaker endpoints, SaaS connectors.
  3. Planning, reflection, and tool choice

    • The LLM plans steps, decomposes goals, validates arguments, and routes the query.
    • Uses self-critique to ensure correct tool selection and schema compliance.
    • Planning references memory to avoid redundant calls and to personalize results.
  4. Execute tools and collect observations

    • The MCP Tool Runner executes the chosen function.
    • The agent receives tool outputs, checks units, ranges, and business rules.
    • If errors occur, planning adapts, retries, or switches tools.
  5. Respond and update memory

    • The LLM synthesizes a natural-language answer.
    • Optionally writes key facts or decisions back to memory for future use.

=======================================================

 Role of Memory in Tool Calling

Memory acts as the context backbone for the agent. It ensures that the LLM doesn’t operate in isolation but instead uses relevant historical and contextual data to make better decisions during planning and tool invocation.

Types of Memory

  1. Short-Term Memory (Session Memory)

    • Tracks the current conversation flow and intermediate steps.
    • Example: If the user asks, “Add a new test case for DAWR,” and later says, “Make it similar to the last one,” short-term memory recalls what “last one” refers to.
    • Stored in the agent’s working context (like a conversation buffer).
  2. Long-Term Memory

    • Stores persistent knowledge across sessions.
    • Example: Past tool calls, user preferences, previous bug reports, or test harness details.
    • Typically implemented using vector databases (e.g., Pinecone, Weaviate, FAISS) for semantic search.
    • Enables retrieval of relevant references during planning or content generation.

Where Memory Fits in the Flow

Referencing your diagram and updated version:

  • Step 1 (Receive Query):
    Memory is accessed immediately to enrich the query with historical context.
    Example: “User often works on Linux RAS components → prioritize related tools.”

  • Step 3 (Planning & Tool Choice):
    Memory helps the LLM plan better by recalling previous tool usage patterns, schema details, and user-specific constraints.
    Example: “Last time, the user preferred JSON schema-based prompts → use that format.”

  • Step 4 (Tool Execution):
    Memory can store execution results for future reuse.
    Example: Cache API responses or computed estimates to avoid redundant calls.

  • Step 5 (Response):
    Memory updates with new facts, decisions, and tool outputs for long-term learning.

Why Memory Matters

  • Personalization: Tailors responses based on user history.
  • Efficiency: Avoids repeated tool calls by caching results.
  • Accuracy: Provides richer context for reasoning and planning.
  • Scalability: Enables complex workflows by chaining past knowledge.

Practical Implementation

  • Short-Term: Conversation buffer in the agent shell.
  • Long-Term:
    • Vector DB for semantic retrieval.
    • Store tool metadata, execution logs, and user preferences.
    • Use embeddings to link queries with relevant past interactions.

================================

n8n is an open-source workflow automation platform that helps you connect different apps, services, and APIs without writing a lot of custom code. It’s similar to tools like Zapier or Integromat, but with more flexibility and self-hosting options.

Here’s what makes n8n special:

  • Visual Workflow Builder: You can create workflows using a drag-and-drop interface.
  • Integrations: It supports hundreds of apps and APIs (Slack, GitHub, Google Sheets, etc.).
  • Custom Logic: You can add JavaScript code snippets for advanced logic.
  • Self-Hosting: Unlike many SaaS automation tools, you can run n8n on your own server for full control.
  • Event-Driven Automation: Trigger workflows based on events (e.g., new email, webhook, database update)
======== Five Single AI Agent Architectures================

1. AI Agent Using Tools

  • The agent receives a chat message and plans its actions.
  • It can access contacts, send emails, or send invitations using integrated tools.

2. AI Agent Mixing Tools with MCP Servers

  • Triggered by another app through a webhook.
  • Uses an MCP (Model Context Protocol) server for specialized integrations (e.g., Atlassian).
  • Combines ready-to-use tools for other interactions.

3. Agentic Workflow with a Router

  • A router acts as a conditional decision-maker.
  • The agent routes tasks based on conditions (e.g., if X happens, do Y).

4. AI Agent with a Human in the Loop

  • The agent pauses for human approval before proceeding.
  • Example: Asking for Slack approval before executing an action.

5. Dynamically Calling Other Agents

  • The agent autonomously decides whether to call another AI agent.
  • Option 1: Subagent via an AI Agent Tool node.
  • Option 2: Subagent or another agent via a Workflow Tool node.
====================================

Understanding AI Agent Protocols: The Backbone of Agentic AI

As AI evolves from single models to agentic architectures (systems where multiple AI agents work together), one question becomes critical:

How do these agents talk to each other and coordinate tasks?

That’s where AI Agent Protocols come in. Think of them as the “rules of communication” that allow agents to share information, collaborate, and connect with external tools. Without these protocols, agentic AI would be chaotic and unreliable.

Here are the most important protocols you should know—explained simply:

1. MCP — Model Context Protocol (by Anthropic)

  • What it does: Helps AI agents manage context and connect to external tools like Slack, GitHub, or APIs.
  • How it works: Uses a client-server setup with JSON-RPC for communication.
  • Example: Imagine an AI assistant in Slack that can also pull data from GitHub and update project status automatically.

2. A2A — Agent-to-Agent Protocol (by Google)

  • What it does: Allows multiple AI agents to collaborate and share tasks.
  • How it works: Agents talk directly (peer-to-peer) or through a central coordinator.
  • Example: Two AI agents—one handling API calls and another managing database queries—working together to complete a workflow in Vertex AI.

3. SLIM — Structured Language Interaction Model (by OpenAI)

  • What it does: Makes sure agents exchange messages in a structured, predictable way.
  • Why it matters: Prevents confusion when agents use tools or execute tasks.
  • Example: An agent asking another agent for a tool response in a clear format, so nothing gets lost in translation.

4. ACP — Agent Communication Protocol (by IBM)

  • What it does: Handles discovery of helper agents, status updates, and message routing.
  • Where it’s used: Large enterprise systems with multiple agents and services.
  • Example: Orchestrating a complex workflow where one agent monitors servers, another handles alerts, and a third updates dashboards.

Why This Matters

These protocols are the foundation of agentic AI. They enable:

  • Coordination between agents
  • Scalability for large systems
  • Real-world execution beyond simple prompts

As we move toward multi-agent, autonomous systems, understanding these protocols is essential for building reliable AI solutions.

Pro Tip for Beginners: Start by experimenting with one protocol (like MCP) in a simple project—such as connecting an AI chatbot to an external API. Once you see how communication works, scaling to multi-agent systems becomes much easier.

=========================

  • Conclusion :

    LLMs can dynamically decide when to use a tool, pass the right arguments, and incorporate the results into their final response. This approach transforms LLMs from passive text generators into active problem-solvers that can query APIs, run computations, or fetch real-time data.

    Understanding this workflow—define tools → let the model decide → parse arguments → execute locally → return results → finalize answer—is key to building powerful AI-driven applications. Whether you’re integrating with APIs, automating workflows, or creating intelligent assistants, tool calling is the foundation for making LLMs truly useful in real-world scenarios.


Sunday, December 7, 2025

Model Context Protocol and MCP's Three Core Interaction Types

LLMs can chat like humans, write blogs, and even book meetings—but scaling them is a nightmare. Every new tool traditionally needs its own custom setup and code, creating a web of fragile bridges. The world of artificial intelligence is moving fast. Every week, it seems like there’s a new tool, framework, or model that promises to make AI better. But as developers build more AI applications, one big problem keeps showing up: the lack of context. Each tool works on its own. Each model has its own memory, its own data, and its own way of understanding the world. This makes it hard for different parts of an AI system to talk to each other. MCP solves this by acting as a central hub: one protocol, many tools. It is a new standard for how AI tools share context and communicate. It allows large language models and AI agents to connect with external data sources, apps, and tools in a structured way.

The Problem with Disconnected AI Tools : Imagine you’re building a customer support chatbot using a large language model like GPT. It can generate great responses—but it knows nothing about your actual customers. To make it useful, you connect it to your CRM (Customer Relationship Management) i. e Salesforce, Microsoft dynamics 365, HubSpot, and Zoho-CRM for customer records. Then you link it to your ticketing system for open cases. Maybe you add a knowledge base for reference.

Each integration is a separate job: writing custom API calls, formatting data, managing authentication, and handling errors. Every new data source means more glue code. The LLM doesn’t naturally know how to talk to these systems. Now scale that up. You have five or ten tools—an AI assistant, a search engine, a summarization tool, and automation scripts. Each stores information differently. None of them share context. If one model learns something about a user’s intent, the others can’t use it. You end up with isolated pockets of intelligence instead of a connected ecosystem. This is exactly the problem MCP was designed to solve.

Model Context Protocol is an open standard from Anthropic that lets AI applications connect to external tools and data through a single, consistent client‑server protocol. MCP exposes capabilities as tools, resources, and prompts, discovered and invoked over a standardized interface so models can act on real systems without custom one‑off connectors. Under the hood MCP uses JSON‑RPC 2.0 for message exchange, with transports like stdio for local servers and HTTP or SSE for remote ones.Enterprise‑grade authorization for HTTP transports follows OAuth 2.1 style flows, including authorization code and client credentials, so agents can act with least‑privilege tokens.

Instead of building a separate connector for every service, MCP gives the model a universal way to interact. For example, if you say, “Book a meeting with Ram,” the model knows it needs a calendar tool. It sends the request to the MCP client, which forwards it to the right server. The server books the meeting and returns the result, which the client passes back to the model. 

With MCP, it’s not just easier to build—it’s easier to trust, scale, and grow. One standard means faster integrations, stronger security, and a future-proof foundation for enterprise AI.

If the tool runs on your computer, MCP connects directly (like plugging in a cable). If the tool is online, it uses standard web methods like HTTP or Server-Sent Events. To keep things secure, MCP follows OAuth 2.1, the same system trusted by big tech platforms, so the AI only gets the exact permissions it needs—nothing more. This means safer, controlled access without exposing sensitive data.


                                                               AI ↔ MCP Client ↔ MCP Server --->Tools



  • LLM at the top
  • MCP Client as the orchestrator
  • Three MCP Servers each linked to different icons (flight booking, calendar, and database)
  • Local tools: If the tool runs on your computer, MCP connects directly using stdio (like plugging in a cable).
  • Remote tools: If the tool is online, MCP uses standard web methods like HTTP or Server-Sent Events (SSE).
How it works
HTTP: The client sends a request, the server sends back a response, and the connection usually ends.Good for one-time actions like “search flights” or “get pricing.”

SSE :The client opens a single HTTP connection, and the server can keep sending updates over time without the client asking again.Perfect for real-time updates like “flight price changes,” “order status,” or “chat messages.”

This diagram breaks down the Model Context Protocol (MCP) workflow, showing how the Client, MCP Server, LLM, and External Data Source interact.
1. The Client (e.g., Claude Desktop) requests available tools from the MCP Server.
2. The Client sends the user’s query and tool info to the LLM (e.g., Claude). If external data is needed, the LLM suggests a tool.
3. The Client asks the MCP Server to run the tool, which retrieves data from an External Data Source (e.g., GitHub API).
4. The retrieved data is sent back to the Client, which forwards it to the LLM for the final response.

This structured flow ensures the LLM has the right context to generate accurate answers

How MCP Organizes Capabilities

The Model Context Protocol (MCP) changes the way AI applications connect to external systems. Instead of hardcoding integrations, MCP provides a standard interface that exposes three types of capabilities:

  • Tools – Actions the AI can perform, like search flights, book a ticket, or send a message.
  • Resources – Data the AI can access, such as a calendar file, PDF document, or database entry.
  • Prompts – Predefined templates or instructions, for example summarize a document or generate an email.



Above mentioned  three primitives work together to create richer, more reliable experiences. Tools handle actions, resources provide information, and prompts guide the AI’s behavior. By understanding when to use each, developers gain more control and flexibility when building AI-powered applications.


This diagram above  shows that MCP acts as a central hub where three types of capabilities connect

  • Prompts (user-driven),
  • Resources (application-driven), and
  • Tools (model-driven).

All of these flow through the MCP Server, which then interacts with external systems like APIs, databases, and services.

------

Solving the M×N Integration Challenge

source


Let’s understand the core integration problem that MCP addresses.

When building AI applications that need access to multiple organizational data sources, you encounter the M×N problem:
For M different AI applications connecting to N different data sources, you must create and maintain M×N custom integrations.

This results in a complex integration matrix that becomes unmanageable as your organization scales. Every new application or data source multiplies the integration effort, leading to duplicated work across teams.

MCP simplifies this equation. Instead of M×N integrations, MCP reduces the complexity to M+N:

  • Build M clients for your AI applications
  • Build N servers for your data sources

With MCP, you only need M+N implementations, dramatically reducing development overhead and enabling scalable, standardized integration.


How Prompt Works in MCP :

  1. User invokes a prompt
    The user asks the system to run a predefined prompt, for example:
    “Analyze project.”

  2. Client sends a prompt request to MCP Server
    The client calls the MCP Server using prompts/get to retrieve the prompt definition and any dynamic content.

  3. MCP Server fetches live data from external systems
    If the prompt requires context (like logs, code, or metrics), the MCP Server queries an external API or data source.

  4. External API returns current data
    The external system sends back the requested information to the MCP Server.

  5. MCP Server generates a dynamic prompt
    Using the fetched data, the MCP Server builds a formatted prompt message that includes real-time context.

  6. Client adds the prompt to the AI model’s context
    The client injects this dynamic prompt into the model’s input so the AI can reason with updated information.

  7. AI model produces the final response
    The client displays the AI’s answer to the user.

How Tool Works in MCP :

  • User asks: “Calculate the sum of 100 and 50.”
  • Client sends the request to the MCP Server.
  • AI Model decides which tool to use (e.g., calculator_tool).
  • MCP Server invokes the tool and interacts with the External System if needed(if the tool is not available locally-internal).
  • Tool performs the calculation and returns the result.
  • AI Model generates the final response: “The sum is 150.”

How Resource Works in MCP :

Step 1: MCP Server exposes resources

The MCP Server acts as the central hub. It makes different types of resources available to the AI application. These resources are structured pieces of data or services that the model can use.

Step 2: Resource types and their roles

The diagram shows four common resource categories:

  1. RAG System (Build embeddings)

    • The server provides access to a Retrieval-Augmented Generation (RAG) system.
    • This resource helps the AI build embeddings and retrieve relevant context from large datasets.
  2. Cache Layer (Store frequently used data)

    • A resource that stores commonly accessed data for quick retrieval.
    • This improves performance and reduces repeated calls to external systems.
  3. Analytics (Transform & analyze)

    • A resource that processes raw data into insights.
    • For example, analyzing logs or metrics before sending them to the model.
  4. Integration (Combine multiple sources)

    • A resource that aggregates data from different APIs or databases.
    • This gives the AI a unified view of information from multiple systems.

Step 3: How the AI uses these resources

  • When the AI needs context (e.g., logs, historical data, or combined insights), the MCP Client requests these resources from the MCP Server.
  • The server fetches or generates the resource and returns it in a structured format.
  • The AI then uses this resource to improve its reasoning and generate accurate responses.

----------------------------------------

How MCP works

  1. User request arrives at the LLM. The host application passes the user’s intent to the model and supplies the catalog of available MCP tools and resources from connected servers.
  2. MCP client maintains connections. The host spins up one MCP client per server, performs initialization, and negotiates capabilities.
  3. Tool selection and invocation. The LLM chooses a tool based on descriptions and schemas, then asks the client to call it with structured parameters. 
  4. Server executes and returns results. The MCP server performs the action or fetches data and returns structured output via JSON‑RPC. 
  5. LLM composes the final answer. The model uses results to respond or to continue a multi‑step workflow, optionally calling more tools until the task is complete. 
  6. Optional authorization. If the server requires auth, the client follows the specified OAuth flow and receives scoped tokens before tool calls

Example : How MCP connects an LLM to flight booking tools

High level

  • LLM receives the user request.
  • MCP Client brokers tool calls.
  • MCP Servers expose tools and data over the Model Context Protocol.
  • Results flow back to the LLM, which composes the final answer for the user.

Typical servers for air booking

  • Flight Search Server - route availability, schedules, fares
  • Pricing Server - fare rules, taxes, ancillaries
  • Booking Server - PNR creation, seat selection
  • Payment Server - tokenize card, 3DS, capture
  • Loyalty Server - miles accrual, status rules
  • Notifications Server - email or SMS itinerary
  • Calendar Server - add travel to calendar
  • Data Store Server - cache, user profile, past trips

Step by step booking flow

  1. User: “Book BLR to SFO next Friday, return Tuesday, aisle seat, use miles if cheaper.”
  2. LLM interprets intent and constraints.
  3. MCP Client orchestrates calls:
    • Flight Search Server: search BLR ↔ SFO, date constraints
    • Pricing Server: evaluate fares, fare families, baggage, refundability
    • Loyalty Server: compare miles redemption vs cash
  4. LLM ranks options and asks user to confirm.
  5. On confirmation:
    • Booking Server: create PNR, select seats
    • Payment Server: charge or redeem miles
    • Notifications Server: send ticket and receipt
    • Calendar Server: add flights to calendar
  6. MCP Client returns structured results to LLM.
  7. LLM produces the final answer with itinerary details.

Why MCP works well  in this scenerio 

  • Standard protocol for tool discovery and capabilities
  • Secure, isolated tool execution with clear inputs and outputs
  • Composable servers so you can add or swap providers without changing the LLM logic

Why MCP is Required for Scaling LLMs

When LLMs grow in size and capability, they need to interact with more tools, data sources, and systems. Without a standard protocol, every integration becomes a custom job, which is hard to maintain and slows down scaling. MCP solves this by:

  • Standardizing communication: Instead of building one-off connectors for each tool, MCP provides a universal protocol (JSON-RPC) for all tools.
  • Dynamic capability discovery: LLMs can automatically learn what tools are available and what they can do, without hardcoding.
  • Secure and controlled access: OAuth-based authorization ensures least-privilege access, which is critical when scaling across enterprise environments.
  • Local and remote flexibility: MCP supports both local tools (via stdio) and remote services (via HTTP/SSE), making it easy to scale from desktop to cloud.

How MCP Enables Scaling

  • Plug-and-play architecture: Add new servers without changing the LLM logic.
  • Reduced context overhead: Instead of dumping thousands of tool definitions into the model’s prompt, MCP lets the client manage them efficiently.
  • Ecosystem growth: As more MCP servers are built, LLMs can instantly leverage them—accelerating feature expansion.

Why MCP is better than ad‑hoc tool wrappers

  • One protocol. Fewer integrations. MCP reduces the N×M mess of per‑service connectors to a single standard that any client can speak and any server can implement. 
  • Clear capability discovery. Clients list server tools and resources using uniform schema so the LLM can reason about what to call and with which parameters. 
  • Vendor‑neutral ecosystem. MCP is open, with SDKs and many reference servers, and is used by multiple apps, which avoids lock‑in and speeds reuse.
  • Secure by design. Standardized auth and transport guidance, plus emerging enterprise controls that monitor MCP traffic and enforce least‑privilege access.
  • Operational efficiency. New techniques like MCP code‑execution patterns reduce token overhead compared to dumping thousands of tool definitions into context.
  • Usable locally. Desktop extensions package local MCP servers for one‑click install, which makes private data integrations accessible without complex setup

How MCP Integrates with AWS and Amazon Bedrock

MCP enhances AWS services by enabling secure, context-aware AI applications that can access organizational data and tools. A key integration point is Amazon Bedrock, which provides a robust foundation for enterprise AI.

Amazon Bedrock and Language Models

Amazon Bedrock is AWS’s fully managed service for foundation models (FMs), offering a unified API to leading models such as:

  • Anthropic Claude
  • Meta Llama
  • Amazon Titan and Amazon Nova

Bedrock stands out for enterprise use because it leverages AWS’s security and compliance ecosystem, including IAM for access controland CloudWatch for monitoring.

The Converse API and Tool Use

At the core of Bedrock’s flexibility is the Converse API, which supports multi-turn conversations and introduces “tool use.” This allows models to:

  • Detect when external data is needed
  • Request that data via structured function calls
  • Incorporate the retrieved information into responses

MCP with  Bedrock: Seamless Integration

MCP’s standardized protocol for accessing external systems aligns perfectly with Bedrock’s tool-use capability. Together, they create an architecture where Bedrock models can request data through the Converse API, and MCP fulfills those requests securely and efficiently.

NOTE: Amazon Titan and Amazon Nova are AWS-developed foundation model (FM) families available through Amazon Bedrock, each designed for specific AI use cases and enterprise needs.
  • Titan is ideal for traditional text and embedding uses, focusing on enterprise readiness.
  • Nova is designed for advanced, multimodal reasoning with high performance and customization flexibility.

  • Conclusion :  MCP is still new, but the idea behind it is powerful. By creating a shared protocol for context, it lowers the barrier for innovation. Developers can focus on what their AI does, not how it connects. Companies can build products that play well with others instead of locking users into closed systems. The goal is not just smarter AI, but simpler AI. AI that understands what’s happening around it, reacts in real time, and works naturally with the tools you already use. Model Context Protocol is a big step toward that future. It’s the bridge between intelligence and context, and it’s what will make tomorrow’s AI systems faster, more reliable, and far more human in how they understand the world.

    If your roadmap includes broader agent capabilities, more systems, and stronger guardrails, MCP is the foundation that turns one‑off integrations into an extensible platform. It gives LLMs a clear, secure, and efficient way to access the real world, which is exactly what you need to scale from prototypes to production

    Friday, December 5, 2025

    CVEs in Enterprise Linux: How Red Hat and SUSE Handle Security Vulnerabilities

    Introduction

    In today’s enterprise IT landscape, security is paramount. Organizations running Linux distributions like Red Hat Enterprise Linux (RHEL) and SUSE Linux Enterprise Server (SLES) rely on these platforms for mission-critical workloads. But with the growing complexity of software, vulnerabilities are inevitable. This is where CVEs (Common Vulnerabilities and Exposures) come into play. CVEs provide a standardized way to identify and track security flaws, enabling vendors and customers to respond quickly and effectively. In this blog, we’ll explore what CVEs are, why they matter, and how RHEL and SLES integrate CVE management into their kernel update strategies.



    1. What is a CVE? [Common Vulnerabilities and Exposures]?

      A CVE is a unique identifier for a publicly known cybersecurity vulnerability.

      Example: CVE-2025-12345

      2025 → Year the CVE was assigned

      12345 → Sequential ID number

    1. Why CVEs Matter for Enterprise Linux

      • Compliance and risk management.
      • Security patching and lifecycle.
      • Impact on mission-critical workloads.
    2. How Red Hat Handles CVEs

      • RHEL kernel update process.
      • Example: RHEL 9.6 kernel update fixing CVE-2025-38724 (NFSd UAF) and others.
      • Integration with Red Hat Security Advisories (RHSA).
    3. How SUSE Handles CVEs

      • SLES kernel update process.
      • Example: SLES 15 SP6 fixing CVE-2025-23145 (MPTCP NULL pointer) and others.
      • SUSE Security Announcements and patching strategy.
    4. Enterprise Strategy

      • Why vendors stick to specific kernel versions (stability, certification, compliance).
      • Backporting fixes vs. upgrading kernels.


    Purpose of CVEs

    • Provide a common reference for security professionals, vendors, and customers.
    • Helps organizations track, prioritize, and patch vulnerabilities consistently.
    • Used by tools like Vulnerability Scanners, Patch Management Systems, and Security Advisories.

    How a CVE is created (high‑level lifecycle)

    The CVE process is standardized and managed by MITRE, with help from CNAs (CVE Numbering Authorities) like Red Hat, IBM, Google, etc. 

    Typical flow

    1. Discovery
      • A security researcher, developer, or vendor finds a vulnerability
    2. Private reporting
      • Reported responsibly to a vendor or CNA
    3. CVE ID assignment
      • CNA assigns an ID like CVE-2026-XXXX
    4. Embargo (often)
      • Details kept private until a fix exists
    5. Public disclosure
      • CVE is published on cve.org and NVD

    Important point:

    A CVE ID is just an identifier.
    It does not contain the fix itself


    How CVEs Work

    1. A vulnerability is discovered in software (e.g., Linux kernel, OpenSSL).
    2. It is reported to a CVE Numbering Authority (CNA) (e.g., Red Hat, SUSE, MITRE).
    3. The CNA assigns a CVE ID and publishes details:
      • Description of the vulnerability
      • Severity score (CVSS)
      • Affected versions
      • Fix or mitigation steps

    Why Important for RHEL and SLES

    • Both RHEL and SLES maintain security advisories tied to CVEs.
    • Customers rely on CVE tracking for:
      • Compliance (e.g., PCI-DSS, HIPAA)
      • Risk management
      • Patch planning
    • Example:
      • RHEL 9 kernel update might fix CVE-2024-1234 (privilege escalation bug).
      • SLES 15 SP6 update might address CVE-2025-5678 (memory corruption issue).
    Here’s how CVEs (Common Vulnerabilities and Exposures) are directly linked to kernel updates in RHEL and SLES, with recent critical examples:

     RHEL Kernel Updates and CVEs

    Recent Red Hat advisories show kernel updates fixing multiple CVEs. For example:

    • RHEL 9.6 (Kernel 5.14.0-570) update fixed:
      • CVE-2025-38724: nfsd – Handle get_client_locked() failure in nfsd4_setclientid_confirm() (Use-After-Free risk)
      • CVE-2025-39864: wifi: cfg80211 – Fix use-after-free in cmp_bss()
      • CVE-2025-39883: mm/memory-failure – Fix VM_BUG_ON_PAGE when unpoison memory
      • CVE-2025-39881: kernfs – Fix UAF in polling when open file is released
      • CVE-2025-39918: wifi: mt76 – Fix linked list corruption
      • CVE-2025-39955: tcp – Clear fastopen_rsk in tcp_disconnect()
      • CVE-2025-40186: tcp – Avoid calling reqsk_fastopen_remove() in tcp_conn_request() 

    Older RHEL 8.6 update fixed:

    • CVE-2025-21764: ndisc – Use RCU protection in ndisc_alloc_skb() 

    SLES Kernel Updates and CVEs

    SUSE advisories also tie kernel updates to CVEs:

    • SLES 15 SP6 (Kernel 6.4.0) update fixed:

      • CVE-2025-23145: mptcp – Fix NULL pointer in can_accept_new_subflow
      • CVE-2025-38500: xfrm – Fix use-after-free after changing collect_md xfrm interface
      • CVE-2025-38616: tls – Handle data disappearing under TLS ULP 
    • SLES 15 SP5 (Kernel 5.14.21) update fixed:

      • CVE-2024-36904: tcp – Use refcount_inc_not_zero() in tcp_twsk_unique()
      • CVE-2024-43861: Fix memory leak for non-IP packets
      • CVE-2024-35949: btrfs – Ensure WRITTEN flag on metadata blocks 
    • SLES 15 SP6 (Kernel 6.4) also addressed:

      • CVE-2024-40956: dmaengine: idxd – Fix possible Use-After-Free in IRQ processing
      • CVE-2024-53104: media: uvcvideo – Skip parsing undefined frame types 

    Why This Matters

    • Each kernel update bundles fixes for multiple CVEs.
    • Customers track CVEs for risk assessment and compliance.
    • Vendors provide CVSS scores and patch instructions in advisories.

    -------------------------------------------------------------------------------------------------------------------------

    From Upstream to Enterprise: Kernel Version in RHEL and SLES




    Above diagram showing the relationship between Stable upstream Linux kernel and enterprise distributions across versions:
  • Latest Stable: 6.18 (Released Nov 30, 2025)
  • Current Preview: 6.18-rc6 (Mainline development)
  • LTS Kernels:
    • 6.12 (Released Nov 2024, supported until Dec 2036)
    • 6.1 (Released Dec 2022, supported until Dec 2027)
    NOTE: RHEL 10 and SLES 16 will likely stick to 6.12 LTS for stability and certification, even though 6.18 is the latest mainline.Vendors prefer LTS kernels because they offer long-term maintenance and predictable patching.
  • Red Hat Enterprise Linux

    • RHEL 8 → 4.18. Chosen for stability and maturity during 2019 launch. 
    • RHEL 9 → 5.14. Needed for modern hardware enablement and performance improvements.
    • RHEL 10 → 6.12.x.  Aligns with upstream LTS and cloud-native workloads.

    SUSE Linux Enterprise Server

    • SLES 15 SP4 and SP5 → 5.14.x. Matches RHEL 9 for hardware parity.
    • SLES 15 SP6 and SP7 → 6.4.x. Early adoption of newer kernel for HPC and AI workloads.
    • SLES 16 → 6.12.x.  Future-proof for next-gen enterprise and cloud environments

    Note: Enterprise distros generally track LTS lines for stability. RHEL 10 and SLES 16 are on the 6.12 LTS family, even though upstream’s latest stable is 6.18


    Why Customers Choose a Particular Kernel Version

    1. Stability and Long-Term Support

    • Enterprise customers prioritize predictable, stable kernels over bleeding-edge features.
    • RHEL and SLES pick a kernel version and backport critical fixes and features rather than upgrading to every new upstream kernel.
    • Example: RHEL 8 stayed on 4.18 for years, even though upstream Linux moved to 5.x and 6.x, because 4.18 was proven stable and certified.

    2. Hardware Enablement

    • New kernels bring support for new CPUs, GPUs, storage, and networking hardware.
    • RHEL 9 moved to 5.14 because it enabled next-gen AMD EPYC, Intel Sapphire Rapids, and PCIe Gen5.
    • SLES 15 SP6/SP7 jumped to 6.4 for AI/ML accelerators and modern NVMe improvements.

    3. Security and Compliance

    • Enterprise kernels integrate SELinux/AppArmor, FIPS, and CVE patches.
    • Vendors backport security fixes from newer kernels into their chosen LTS kernel.
    • This ensures compliance with government and industry standards without breaking stability.

    4. Ecosystem and Certification

    • ISVs (Independent Software Vendors) and OEMs certify their apps/drivers on specific kernels.
    • Customers stick to those versions for SAP, Oracle DB, VMware, and cloud certifications.

    5. Performance and Feature Balance

    • RHEL 10 and SLES 16 adopt 6.12 because it brings:
      • Improved scalability for large NUMA systems
      • Better BPF and eBPF observability
      • Enhanced container performance


    ______________________________________________________________________________________________

    RHEL kernel families:

    • RHEL 8.x → Kernel 4.18.x
    • RHEL 9.x → Kernel 5.14.x
    • RHEL 10.x → Kernel 6.12.x

    RHEL 8.x → Kernel Versions (4.18 series)

    • RHEL 8.0 → 4.18.0-80
    • RHEL 8.1 → 4.18.0-147
    • RHEL 8.2 → 4.18.0-193
    • RHEL 8.3 → 4.18.0-240
    • RHEL 8.4 → 4.18.0-305
    • RHEL 8.5 → 4.18.0-348
    • RHEL 8.6 → 4.18.0-372
    • RHEL 8.7 → 4.18.0-425
    • RHEL 8.8 → 4.18.0-477
    • RHEL 8.9 → 4.18.0-513
    • RHEL 8.10 → 4.18.0-553

    The  Linux 5.14 kernel is available in Red Hat Enterprise Linux 9 series. Specifically:

    • RHEL 9.0 (released May 17, 2022) introduced kernel 5.14.0-70.
    • All subsequent RHEL 9 minor releases (9.1 through 9.7) continue to use the 5.14 kernel with incremental updates:
      • RHEL 9.1 → 5.14.0-162
      • RHEL 9.2 → 5.14.0-284
      • RHEL 9.3 → 5.14.0-362
      • RHEL 9.4 → 5.14.0-427
      • RHEL 9.5 → 5.14.0-503
      • RHEL 9.6 → 5.14.0-570
      • RHEL 9.7 → 5.14.0-611
      • RHEL 9.8 → 5.14.0-636


    RHEL 10.x → Kernel Versions (6.12 series)

    • RHEL 10.0 → 6.12.0-55
    • RHEL 10.1 → 6.12.0-124
      (Future minor releases will continue with 6.12.x updates) 


    If you need Linux 5.14, you should use RHEL 9.x  . RHEL 8 uses kernel 4.18, and  RHEL 10 moves to kernel 6.x.

    -------------------------------------------------------

    SLES kernel families:

    • SLES 15 SP4 & SP5 → Kernel 5.14.x
    • SLES 15 SP6 & SP7 → Kernel 6.4.x
    • SLES 16 → Kernel 6.12.x

    SLES 15.x Series

    • SLES 15 SP4 → 5.14.21-150400.24.184.1
    • SLES 15 SP5 → 5.14.21-150500.55.124.1
    • SLES 15 SP6 → 6.4.0-150600.23.78.1
    • SLES 15 SP7 → 6.4.0-150700.53.22.1 

    SLES 16.x Series

    • SLES 16.0 → 6.12.0-160000.5.1 (initial release)
    • Later updates in SLES 16 continue with 6.12.x kernel family
    =============
    In the upstream Linux kernel (maintained at kernel.org), development is organized into several branches, each serving a specific purpose:

    1. Mainline (Development)

    • Branch: master
    • Maintained by Linus Torvalds.
    • Contains the latest development code.
    • New features and major changes are merged here during the merge window.
    • Example: 6.18-rc6 is the current release candidate for the next stable version.

    2. Stable

    • Maintained by Greg Kroah-Hartman and others.
    • Each stable branch corresponds to a released kernel version (e.g., linux-6.18.y).
    • Only bug fixes and security patches are applied.
    • No new features.

    3. Long-Term Support (LTS)

    • Maintained for years (2–6+ years).
    • Examples:
      • 6.12 LTS (supported until Dec 2036)
      • 6.1 LTS (supported until Dec 2027)
    • Used by enterprise distros like RHEL and SLES for stability.

    4. Next (linux-next)

    • Integration branch for testing patches before they go into mainline.
    • Acts as a staging area for subsystem maintainers.

    5. Architecture/Subsystem Trees

    • Maintainers for specific areas (e.g., networking, filesystems, drivers) have their own branches.
    • These feed into linux-next, then mainline.

    Example :  Mainline → Stable → LTS → Enterprise distros

    • Mainline (Development) – features merged here.
    • Stable series – short‑term maintenance, e.g. 6.18.
    • Long‑Term Support (LTS) – multi‑year maintenance, e.g. 6.12.
    • Flow into Enterprise distros:
      • RHEL typically tracks an LTS line (RHEL 10 → 6.12.x).
      • SLES also tracks an LTS line (SLES 16 → 6.12.x).

    Conclusion

    Security is not optional—it’s a continuous process. CVEs provide a transparent and standardized way to manage vulnerabilities across the Linux ecosystem. Both Red Hat and SUSE have robust mechanisms to track, patch, and communicate CVE fixes, ensuring enterprise customers can maintain compliance and minimize risk without sacrificing stability. Understanding CVEs and their role in kernel updates empowers IT teams to make informed decisions about patching and lifecycle management.



    Friday, October 3, 2025

    The Geek Way: How Companies Win in the 21st Century with a Radical Mindset

    Andrew McAfee, MIT Sloan researcher and bestselling author, argues that the companies thriving today are not following the old industrial-era playbook instead they’re embracing what he calls The Geek Way.

    Andrew McAfee’s book The Geek Way introduces a new cultural playbook for running companies in times of rapid technological change and uncertainty. Rather than following industrial-era management practices, McAfee highlights what he calls the “geek norms” — Science, Ownership, Speed, and Openness — that define how modern high-performing companies operate.

    At its core, a geek is not just a computer whiz/Computer Nerd. McAfee defines a geek as an “obsessive maverick” — someone who gets fixated on a hard problem and embraces unconventional solutions. Think Maria Montessori in education, or Reed Hastings at Netflix in business  who dives fearlessly and unconventionally into hard problems, cares little for the status quo, and pushes until they find a better solution.

    What Makes Geeks Different?

    1. Depth of Obsession – Geeks go deep, working from first principles and chasing root causes until they land on a breakthrough.
    2. Unconventional Thinking – They’re unafraid to challenge norms, even if it means being misunderstood for long stretches (think Jeff Bezos or ex-NASA scientist Will Marshall, who founded Planet).

    This mindset, when embedded into organisations, produces cheaper, faster, better solutions that traditional corporate cultures struggle to match.

    The Geek Way Culture

    Instead of rigid hierarchy and bureaucracy, geek-driven organisations thrive on:

    1. Science – Evidence-driven decision-making, balancing data and judgment.
    2. Ownership – Empowering people at every level to act, not just top executives.
    3. Speed – Moving fast, learning quickly, and iterating.
    4. Openness – Welcoming debate, dissent, and unconventional ideas.

    Why It Matters : The “industrial era” model often created delay, silence, and red tape. The Geek Way, by contrast, unlocks human cooperation and innovation at scale. For leaders, this means one hard truth: In a tech-driven world, you’re not just competing with companies, you’re competing with geeks. McAfee’s call is clear: throw away the old management playbook. The future belongs to organizations that think and act like geeks.



    1. Science: Settling Arguments with Evidence

    1. Geeks don’t rely on hierarchy or gut instincts; they rely on evidence.
    2. Decisions are made through experiments, A/B tests, and demos rather than endless debates.
    3. Netflix thrives because it balances data-driven algorithms (70%) with human judgment (30%).
    4. Apple, despite Steve Jobs’ initial resistance, embraced evidence-based demos to guide product choices (e.g., the App Store, camera features).
    5. Takeaway: In geek culture, evidence is “queen.” Arguments end when experiments give answers.


    2. Ownership: Authority Pushed Downward

    1. Instead of power concentrated at the top, geek companies distribute decision-making broadly.
    2. Satya Nadella banned “owning digital resources” at Microsoft — no team can act as a gatekeeper to data or code.
    3. This reduces bureaucracy, speeds innovation, and empowers teams.
    4. The norm is: if you see a problem, you own solving it.
    5. Takeaway: Ownership is not about control, but responsibility.

    3. Speed: Iterate, Don’t Over-Plan

    1. Geeks reject slow-moving corporate bureaucracy.
    2. They build, test, fail, learn, and pivot quickly.
    3. Jeff Bezos at Amazon openly embraced “multi-billion-dollar failures” as necessary for innovation (e.g., Alexa).
    4. SpaceX launches rockets knowing some will explode — because progress requires speed and risk-taking.
    5. Takeaway: Speed matters more than perfection. Fast feedback loops beat slow planning.

    4. Openness: Admitting When You’re Wrong

    1. Geek companies create cultures where leaders and employees can admit mistakes.
    2. Reed Hastings (Netflix) built mechanisms so the company could correct him when he was wrong.
    3. Satya Nadella transformed Microsoft into a less defensive, more open culture where being wrong or vulnerable was acceptable.
    4. Leaders like Yamini Rangan (HubSpot) model openness by sharing their own performance feedback with teams.
    5. Takeaway: Openness makes organizations resilient, adaptive, and honest.

    Geek vs. Non-Geek Companies

    • Geek companies (Netflix, Microsoft under Nadella, Amazon, SpaceX) thrive by embracing these norms.
    • Non-geek failures (like Quibi or Theranos) ignored them — relying on ego, secrecy, or rigid hierarchies.

    Why The Geek Way Matters

    • It’s not about Silicon Valley geography — it’s about cultural evolution.
    • Geeks create evidence-driven, fast-moving, egalitarian workplaces.
    • LinkedIn surveys show these cultures are among the most attractive to employees worldwide.
    • McAfee ties this to human history: just as cultural evolution made humans the only “spaceship-building species,” applying rapid cultural evolution inside companies can unlock long-term advantage.

    Conclusion:

    The Geek Way is not about being digital — it’s about being cultural. It’s about obsessing over tough problems, embracing evidence, sharing responsibility, moving fast, and staying open to being wrong. In McAfee’s words, it’s about building companies that don’t just survive rapid change — they evolve with it.

    Thursday, October 2, 2025

    Rethinking AI Communication: MCP vs API in the Age of Intelligent Agents

    Introduction

    In the world of software engineering, APIs have long been the standard for enabling communication between systems. But as AI systems evolve — especially with the rise of intelligent agents, IDE integrations, and large language models (LLMs) — a new protocol is emerging: Model Context Protocol (MCP). This blog explores what MCP is, how it differs from traditional APIs, and where it fits best in the AI development journey.

    Section 1: What is an API?

    Definition: An Application Programming Interface (API) is a set of rules that allows software applications to communicate with each other.

    Usage: Widely used in web services, microservices, and client-server architectures.

    Characteristics:

    1. Requires external documentation for discovery.
    2. Comes in various standards: REST, GraphQL, gRPC.
    3. Designed for deterministic, structured communication.

    Section 2: Introducing MCP — Model Context Protocol

    Imagine you're talking to a super-smart assistant (like an AI agent or chatbot). To help it understand what you want, you usually give it instructions or ask questions. But for it to do something useful — like book a ticket, write code, or analyze data — it needs to know what tools are available, how to use them, and what context it's working in. That’s where MCP comes in.

    Definition: MCP is an AI-native protocol designed to facilitate context-rich communication between clients (like agents, IDEs, and LLMs) and servers.

    Key Features:

    1. Self-describing: No need for external documentation; the protocol itself carries context.
    2. Uniformity: One protocol for accessing tools, resources, and prompts.
    3. Contextual Awareness: Built to handle dynamic, evolving context — ideal for AI workflows.

    Section 3: MCP vs API — A Comparative View

    Section 4: Why MCP Matters in AI Development

    Agents and LLMs need context to perform tasks effectively. MCP allows them to access tools and resources without rigid API contracts.

    IDE Integrations benefit from MCP’s ability to dynamically describe available tools and prompts.

    Prompt Engineering becomes more powerful when the protocol itself understands and adapts to context.

    Section 5: Where MCP Shines

    AI Agents: Autonomous systems that need to discover and use tools dynamically.

    Developer Tools: IDEs that integrate with AI models for code suggestions, refactoring, etc.

    LLM Orchestration: Managing multiple models and tools in a unified, context-aware environment.

    Conclusion

    While APIs will continue to play a vital role in traditional software systems, MCP represents a paradigm shift tailored for the AI era. Its self-describing nature and context-awareness make it a powerful tool for building intelligent, adaptive systems.