← Back to Tutorials

5. Tools & Extensions

Custom Tools

Tools give agents the ability to perform actions beyond text generation. Each tool has a name, description, parameter schema, and handler function.

import { Tool } from "@microsoft/agents";

const calculatorTool = new Tool({
  name: "calculator",
  description: "Perform basic arithmetic operations",
  parameters: {
    operation: { type: "string", enum: ["add", "subtract", "multiply", "divide"] },
    a: { type: "number" },
    b: { type: "number" }
  },
  handler: async ({ operation, a, b }) => {
    switch (operation) {
      case "add": return a + b;
      case "subtract": return a - b;
      case "multiply": return a * b;
      case "divide": return a / b;
    }
  }
});

API Integration

Agents can call external REST APIs through tools.

const jiraTool = new Tool({
  name: "create_jira_ticket",
  description: "Create a Jira ticket",
  parameters: {
    summary: { type: "string" },
    description: { type: "string" },
    priority: { type: "string", enum: ["Low", "Medium", "High", "Critical"] }
  },
  handler: async (args) => {
    const token = await getAuthToken();
    const res = await fetch("https://your-domain.atlassian.net/rest/api/2/issue", {
      method: "POST",
      headers: { Authorization: `Bearer ${token}`, "Content-Type": "application/json" },
      body: JSON.stringify({
        fields: {
          project: { key: "PROJ" },
          summary: args.summary,
          description: args.description,
          priority: { name: args.priority }
        }
      })
    });
    return res.json();
  }
});

Data Connectors

MAF supports out-of-the-box connectors for common data sources:

Lab: Build a Tool Suite

  1. Create a weather tool (public API)
  2. Create a news summarization tool
  3. Create a math calculator tool
  4. Combine all three in one agent
  5. Test with: "What's the weather in Tokyo? Summarize AI news from today. Multiply 42 by 18."
✏️ Exercise: Build an agent that connects to a public REST API (e.g., GitHub, OpenWeather, or a mock API). The agent should be able to list resources, fetch details, and create new entries based on user commands.