Function createFetchInfo

Creates a fetch info handler that retrieves data for AI without modifying system state (READ pattern).

Execution flow:

  1. Checks if agent hasn't changed during execution
  2. Calls fetchContent with parameters (wrapped in trycatch)
    • If fetchContent throws: calls fallback handler (if provided) → passes error message to emptyContent → commits result
  3. If content exists: commits it as tool output
  4. If content is empty: calls emptyContent handler and commits result
  5. If this is the last tool call (isLast): executes executeForce (always with empty message for fetch)

If fetch, commit, or execution operations fail

// Fetch conversation history with error handling
const fetchHistory = createFetchInfo({
fallback: (error, clientId, agentName) => {
logger.error("Failed to fetch history", { error, clientId, agentName });
},
fetchContent: async (params, clientId, agentName) => {
const history = await historyService.getHistory(clientId);
return JSON.stringify(history);
},
emptyContent: (content) => content || "No history found",
});
// Usage: called internally by addFetchInfo
await fetchHistory("tool-789", "client-012", "HistoryAgent", "FetchHistory", {}, true);
  • Type Parameters

    • T = Record<string, any>

      The type of parameters expected by the fetch operation

    Parameters

    Returns (
        toolId: string,
        clientId: string,
        agentName: string,
        toolName: string,
        params: T,
        isLast: boolean,
    ) => Promise<void>

    Handler function that executes the fetch operation