• Creates and registers a fetch info tool for AI to retrieve data (READ pattern). This implements the READ side of the command pattern - AI calls tool to get information without modifying state.

    Flow:

    1. AI calls tool with parameters
    2. validateParams runs (if provided) - validates parameters structure. Returns true if valid, false if invalid
    3. If validation fails (returns false), tool execution is blocked
    4. If validation passes, fetchContent executes - retrieves data
    5. AI receives fetched content as tool output
    6. If content is empty, emptyContent handler is called

    Type Parameters

    • T = Record<string, any>

      The type of parameters expected by the fetch operation

    Parameters

    • params: IFetchInfoToolParams<T>

      Configuration object for the fetch tool

    Returns string

    The registered agent tool schema

    addFetchInfo

    // Fetch user data with parameter validation and error handling
    addFetchInfo({
    toolName: "fetch_user_data",
    function: {
    name: "fetch_user_data",
    description: "Fetch user data by user ID",
    parameters: {
    type: "object",
    properties: {
    userId: { type: "string", description: "User ID to fetch" },
    },
    required: ["userId"],
    },
    },
    fallback: (error, clientId, agentName) => {
    logger.error("Failed to fetch user data", { error, clientId, agentName });
    },
    validateParams: async ({ params, clientId, agentName, toolCalls }) => {
    // Returns true if valid, false if invalid
    return !!params.userId;
    },
    fetchContent: async (params, clientId) => {
    const userData = await getUserData(params.userId);
    return JSON.stringify(userData);
    },
    emptyContent: (content) => content || "User not found",
    });