Tool Orchestration: The Next Frontier in AI Agentic Systems

⏱️ 2 min read

Introduction

I have built a basic of basics of how Artificial Intelligence is used to take decisions and run actual code for a specific task on the server and server responses back to the LLM with chat history. This is a very basic example of how AI can be used to automate tasks and make decisions.

How is works

Tool Calling ER Diagram for tool orchestration

Tools

Here, there is only one tool get_current_weather which take city as argument and return the current weather of the city.

//weather-tool.ts
// tool for current weather
export default async function get_current_weather(city: string): Promise<object> {
    // console.log("weather tool called");
    const response = await fetch(`https://api.weatherapi.com/v1/current.json?q=${city}&aqi=no&pollen=no&lang=string&current_fields=string&key=<api_key>`, {
        method: "GET",
        headers: {
            "Content-Type": "application/json",
        }
    })
 
    const data = await response.json();
 
    // console.log(data);
 
    return data;
}

Google Gemini - a LLM Call

I have used Google Gemini 3 Flash Preview model for this task. It is a very powerful model and can be used for a variety of tasks. It can generate formated ouput like JSON object or JSON string used in this case.

//google.ts
import { GoogleGenAI } from "@google/genai";
 
const ai = new GoogleGenAI({ apiKey : ''});
 
export default async function main(content : string) : Promise<string> {
  const response = await ai.models.generateContent({
    model: "gemini-3-flash-preview",
    contents: `${content}`,
  });
 
  return response.text!
}

Orchestration

The most important part is Orchestration itself. It is the process of taking the output of one tool and passing it as input to another tool. In this case, we are taking the output of the get_current_weather tool and passing it as input to the main tool.

//index.ts
import get_current_weather from "./weather-tool.ts";
import main from "./google.ts";
 
 
const tools = {
    get_current_weather: get_current_weather
}
 
type ToolName = keyof typeof tools;
//orchestration
let query: string = "what is weather of varanasi";
 
let prompt: string = `
    you are an expert weather analyser.
    user question: ${query}
 
    Only respond with valid JSON object, nothing else; no markdown, no extra text.
    The object must be exactly:
    {"tool":{"name":"get_current_weather","args":"<city-name>"}}
 
    Example:
    {"tool":{"name":"get_current_weather","args":"varanasi"}}
`
 
let step = 1;
while (true) {
    let response = await main(prompt);
    // console.log("model response:", response);
 
    if (step === 1) {
        let parsed: any;
        try {
            parsed = JSON.parse(response);
        } catch (error) {
            console.error("cannot parse json from model response:", error);
            console.error("response was:", response);
            break;
        }
 
        if (parsed && parsed.tool && parsed.tool.name === "get_current_weather" && typeof parsed.tool.args === "string") {
            const tool_name: ToolName = parsed.tool.name;
            const args: string = parsed.tool.args;
            const weatherData = await tools[tool_name](args);
            const weatherDataJson = JSON.stringify(weatherData);
 
            prompt = `
                user requested weather for ${args}, and get_current_weather returned:
                ${weatherDataJson}
 
                Now provide a concise human-readable weather summary only (plain text). No JSON, no extra tags.
            `;
            step = 2;
            continue;
        }
 
        console.error("unexpected tool instruction parsed:", parsed);
        break;
    }
 
    // step 2: final answer
    console.log("final summary:", response.trim());
    break;
}

Conclusion

This is a very basic example of how AI can be used to automate tasks and make decisions. In a real-world scenario, you would have many more tools and the orchestration logic would be much more complex.

npm install @google/genai
node index.ts

Output

final summary: It is currently clear in Varanasi, India, with a temperature of 22.8°C or 73.1°F. The humidity is low at 21%, and there is a light southern breeze at 4.3 km/h.