Skip to main content

Command Palette

Search for a command to run...

Explaining What is Agentic AI: Agents &Tools.

Updated
5 min read
Explaining What is Agentic AI: Agents &Tools.

Agentic AI differs significantly from traditional AI, as it has a specific goal and purpose to achieve. It can't do anything beyond its objective; it is mainly designed to fulfill its goal. In contrast, traditional AI models like ChatGPT and Gemini are more flexible. You can't limit them to a single topic, or you can set their boundaries, but with agentic AI, we can define these boundaries.

Now, let's move on to the second part: what are agents and tools in agentic AI? An agent in agentic AI is simply the AI system itself, where it maintains its environment, makes decisions, and takes actions to achieve its goal. Agents are the ones who do all the work. Tools are what agents use to perform their tasks. In technical terms, they are either API calls or function calls that help the agent achieve its goal.

Let's now understand why, in today's world, agentic AI models are more profitable than traditional AI models. Most of us know that traditional AI models work on pre-trained data, which might be outdated. So, if I want real-time data, it will mostly provide old information that isn't useful. This is where agentic AI comes in with its agents and tools. Suppose we want a real-time weather update for our area. The tool we would use is a weather API, which the agent calls when a user asks for it. Using this tool, the agent can provide a real-time weather update.

Now, let's look at an example where we want a weather update from our Agentic AI by following these steps:

  • For the first step, we need a tool to assist our agent. In this case, we will use a weather API.

      async function getWeatherDetailsByCity(cityname = "") {
        const url = `https://wttr.in/${cityname.toLowerCase()}?format=%C+%t`;
        const { data } = await axios.get(url, { responseType: "text" });
        return `The current weather of ${cityname} is ${data}`;
      }
    
  • Now we need a map to store all our tools.

      const TOOL_MAP = {
        getWeatherDetailsByCity: getWeatherDetailsByCity,
      };
    
  • Now, we will define our SYSTEM_PROMPT, which we will provide to our model to specify its role in calling the tool and presenting the result to the user in a clear and friendly manner.

      const SYSTEM_PROMPT = `
          You are an AI assistant who works on START, THINK and OUTPUT format.
          For a given user query first think and breakdown the problem into sub problems.
          You should always keep thinking and thinking before giving the actual output.
    
          Also, before outputing the final result to user you must check once if everything is correct.
          You also have list of available tools that you can call based on user query.
    
          For every tool call that you make, wait for the OBSERVATION from the tool which is the
          response from the tool that you called.
    
          Available Tools:
          - getWeatherDetailsByCity(cityname: string): Returns the current weather data of the city.
    
          Rules:
          - Strictly follow the output JSON format
          - Always follow the output in sequence that is START, THINK, OBSERVE and OUTPUT.
          - Always perform only one step at a time and wait for other step.
          - Alway make sure to do multiple steps of thinking before giving out output.
          - For every tool call always wait for the OBSERVE which contains the output from tool
    
          Output JSON Format:
          { "step": "START | THINK | OUTPUT | OBSERVE | TOOL" , "content": "string", "tool_name": "string", "input": "STRING" }
    
          Example:
          User: Hey, can you tell me weather of Patiala?
          ASSISTANT: { "step": "START", "content": "The user is intertested in the current weather details about Patiala" } 
          ASSISTANT: { "step": "THINK", "content": "Let me see if there is any available tool for this query" } 
          ASSISTANT: { "step": "THINK", "content": "I see that there is a tool available getWeatherDetailsByCity which returns current weather data" } 
          ASSISTANT: { "step": "THINK", "content": "I need to call getWeatherDetailsByCity for city patiala to get weather details" }
          ASSISTANT: { "step": "TOOL", "input": "patiala", "tool_name": "getWeatherDetailsByCity" }
          DEVELOPER: { "step": "OBSERVE", "content": "The weather of patiala is cloudy with 27 Cel" }
          ASSISTANT: { "step": "THINK", "content": "Great, I got the weather details of Patiala" }
          ASSISTANT: { "step": "OUTPUT", "content": "The weather in Patiala is 27 C with little cloud. Please make sure to carry an umbrella with you. ☔️" }
        `;
    
  • Now, we will ask our model to perform the task.

      async function main() {
    
        const client = new OpenAI({
        apiKey: process.env.OPENAI_API_KEY,
        });
    
        const messages = [
          {
            role: "system",
            content: SYSTEM_PROMPT,
          },
          {
            role: "user",
            content:
              "Hey can you clone https://code.visualstudio.com/ in drive D inside vsCode-clone folder?",
          },
        ];
    
        while (true) {
          const response = await client.chat.completions.create({
            model: "gpt-4.1-mini",
            messages: messages,
          });
    
          const rawContent = response.choices[0].message.content;
          const parsedContent = JSON.parse(rawContent);
    
          messages.push({
            role: "assistant",
            content: JSON.stringify(parsedContent),
          });
    
          if (parsedContent.step === "START") {
            console.log(`🔥`, parsedContent.content);
            continue;
          }
    
          if (parsedContent.step === "THINK") {
            console.log(`\t🧠`, parsedContent.content);
            continue;
          }
    
          if (parsedContent.step === "TOOL") {
            console.log(parsedContent);
            const toolToCall = parsedContent.tool_name;
            if (!TOOL_MAP[toolToCall]) {
              messages.push({
                role: "developer",
                content: `There is no such tool as ${toolToCall}`,
              });
              continue;
            }
    
            const responseFromTool = await TOOL_MAP[toolToCall](parsedContent.input);
            console.log(
              `🛠️: ${toolToCall}(${parsedContent.input}) = `,
              responseFromTool
            );
            messages.push({
              role: "developer",
              content: JSON.stringify({ step: "OBSERVE", content: responseFromTool }),
            });
            continue;
          }
    
          if (parsedContent.step === "OUTPUT") {
            console.log(`🤖`, parsedContent.content);
            break;
          }
        }
    
        console.log("Done...");
      }
    
      main();
    

This was my explanation of Agentic AI, its agents, and tools. I started by defining what they are and what they do, then I gave a brief example to help us understand it better.