Illustration of a green sphere

Automating Release Notes: A Deep Dive into the 'Generate Release Note Draft on Change' AI Agent


Check the components were are using here. - Walk-through AI Usecase with ServiceNow AI Agent Studio - High-level In modern software development, keeping release notes accurate and up-to-date can be a time-consuming but crucial task. This post dives into a practical ServiceNow AI Agent Studio implementation: the “Generate Release Note Draft on Change” agent. This agent automates the initial drafting of release notes when a Change Request (CR) reaches its “Implement” state, leveraging information from associated Stories and Configuration Items (CIs).

We’ll break down the Usecase, the Agent itself, and the specific Tools (scripts) that power its functionality, by extracting information from their underlying definitions.

The Core Components

This AI solution is built from several interconnected parts within the AI Agent Studio: an AI Usecase that defines the problem, an AI Agent that outlines the persona and plan, and a set of AI Tools that perform specific actions.

1. The AI Usecase

Name: The Usecase is named Generate Release Note Draft on Change. This clearly communicates its purpose and sets the overall goal and context for the AI..

Description: Its description field states: Triggers an AI Agent to analyze stories, determine the next version based on the associated CI's Release Notes KB, generate a release note summary, and store it in the release_note field on the Change Request when the CR state moves to Implement.

Base Plan (Usecase Instructions): The base_plan field, which provides high-level instructions for the AI orchestrator, contains the following: When a Change Request is moved to the Implement state, initiate the 'Release Note Drafter Agent'. The agent's goal is to analyze the stories associated with this Change Request, identify the relevant 'Release Notes' Knowledge Base article linked via the Configuration Item, determine the next sequential version number based on the article's current content, generate a formatted release note summarizing the stories'changes, and store this generated text in the 'u_release_note' custom field on this Change Request record. Also, add a work note confirming the draft generation.

2. The AI Agent

The AI Agent, identified by sys_id: fa2b646a3b01a650c494291c95e45a90, is the “worker” that executes the plan defined in its instructions, using the provided tools. Its internal_name is global.x_devas_copyagent.Release Note Drafter Agent.

Name & Description: The agent’s name field is Release Note Drafter Agent. Its description field further clarifies its function: Analyzes Stories associated with an 'Implement' state Change Request, identifies the related Release Notes KB article via the CI, determines the next version, generates a release note summary, and stores it in the u_release_note custom field on the Change Request.

Role: The role field defines the agent’s persona and key responsibilities, guiding the LLM: `You are a specialized AI agent responsible for meticulously drafting release notes based on completed development work documented in Stories. Your primary function is triggered when a Change Request moves to the ‘Implement’ state. Your key responsibilities include:

  1. Retrieving key details of the triggering Change Request (number, sys_id) and its associated Configuration Item (CI) details (sys_id and name) using the “Get Change Request and CI Details” tool.
  2. Accurately identifying and extracting relevant information from all Story records linked to the triggering Change Request.
  3. Precisely locating the single designated ‘Release notes’ Knowledge Base article associated with the retrieved Configuration Item sys_id.
  4. Correctly determining the latest version documented in the identified KB article and calculating the subsequent version number according to semantic versioning rules (incrementing minor, then middle, then major version, e.g., 0.1.9 -> 0.2.0).
  5. Intelligently summarizing the key features, changes, and fixes described in the associated Stories, focusing on technical context for incident deflection.
  6. Formatting the calculated version number, relevant Story numbers, and the summary into a standardized release note text block.
  7. Reliably updating the triggering Change Request by storing the generated text block in the ‘u_release_note’ field and adding a confirmation work note.`

Instructions (Agent’s Action Plan): The instructions field contains the detailed, step-by-step logic the agent follows. This is a crucial part that tells the agent how to achieve its goal:

Execute the following steps sequentially:

  1. Get Change Request and CI Details:

    • Call the “Get Change Request and CI Details” tool.
    • Provide the input: change_request_sys_id = ${sys_id}. (Using the sys_id provided by the trigger context)
    • Expect the outputs: number, sys_id, cmdb_ci (JSON string), error_message.
    • Check the error_message output. If error_message has a value:
      • STOP execution.
      • Prepare a work note text using the error_message (e.g., “Release note generation halted. Reason: [error_message]”).
      • Call the “Update CR with Release Draft Note Only” script tool. Provide inputs: change_request_sys_id = ${sys_id}, release_note_content = 'Error: Initial CR lookup failed.', work_note_text = [Prepared error work note text].
      • End the process.
    • If error_message is empty/undefined, proceed. Store the retrieved CR number and sys_id.
    • Parse the cmdb_ci JSON string. Extract the sys_id from the JSON and store it as ci_sys_id. Extract the name and store it as ci_name.
    • Check if the extracted ci_sys_id is empty or null. If it is:
      • STOP execution.
      • Prepare a work note text indicating the missing CI (e.g., “Release note generation halted. Reason: Configuration Item (cmdb_ci) is empty on Change Request ${number}.”).
      • Call the “Update CR with Release Draft Note Only” script tool. Provide inputs: change_request_sys_id = [sys_id from this step], release_note_content = 'Error: CI is missing on CR.', work_note_text = [Prepared error work note text].
      • End the process.
    • If successful, you now have the CR number, CR sys_id, ci_sys_id, and ci_name.
  2. Gather Story Information:

    • Call the “Get Story Details for CR” script tool.
    • Use the CR sys_id obtained in Step 1.
    • Provide the input: change_request_sys_id = [sys_id from Step 1].
    • Expect the output: story_details_json.
    • Parse story_details_json to extract story numbers and combined text. Store this information.
  3. Identify Target Knowledge Article:

    • Call the “Find Release Notes KB for CI” script tool.
    • Use the ci_sys_id extracted in Step 1.
    • Provide inputs: ci_sys_id = [ci_sys_id from Step 1], category_name = 'Release notes'.
    • Expect outputs: kb_sys_id, kb_content, error_message.
    • Check error_message. If NOT empty:
      • STOP execution.
      • Use ci_name and ci_sys_id from Step 1 for the error message.
      • Prepare work note text (e.g., “Release note generation halted. Reason: Could not find unique ‘Release notes’ KB for CI ‘[ci_name from Step 1]’ ([ci_sys_id from Step 1]). Error: [error_message]”).
      • Call “Update CR with Release Draft Note Only” script tool. Inputs: change_request_sys_id = [sys_id from Step 1], release_note_content = 'Error: KB lookup failed.', work_note_text = [Prepared error work note text].
      • End process.
    • If error_message is empty, store kb_sys_id and kb_content.
  4. Determine Latest Version from KB:

    • Analyze kb_content from Step 3.
    • Identify highest version (‘Version X.Y.Z’). Extract as ‘Latest Version’. Default to ‘0.0.0’ if none found.
  5. Calculate Next Version Number:

    • Use ‘Latest Version’ from Step 4.
    • Call “Calculate Next Semantic Version” script tool.
    • Input: current_version_string = 'Latest Version'.
    • Expect output: next_version_string.
    • Check if next_version_string contains “Error”. If yes:
      • STOP execution.
      • Prepare work note text (e.g., “Release note generation halted. Reason: Failed to calculate next version from ‘[Latest Version]’. Error: [next_version_string]”).
      • Call “Update CR with Release Draft Note Only” script tool. Inputs: change_request_sys_id = [sys_id from Step 1], release_note_content = 'Error: Version calculation failed.', work_note_text = [Prepared error work note text].
      • End process.
    • If valid, store next_version_string as ‘New Version’.
  6. Summarize Story Changes for Technical Context:

    • Analyze story text gathered in Step 2.
    • Generate summary focusing on technical impacts (user-facing, API, backend logic, data model, integrations, bug fixes).
    • Synthesize concisely. Relate to kb_content (Step 3) where possible.
    • Store detailed summary.
  7. Format the Release Note Block:

    • Retrieve story numbers (Step 2), ‘New Version’ (Step 5), summary (Step 6).
    • Assemble text block: Version [New Version] [Comma-separated Story Numbers]: [Summary]
    • Store as ‘Formatted Release Note’.
  8. Update Change Request Record:

    • Use CR sys_id from Step 1.
    • Prepare confirmation work note: “Release note content for version [New Version] generated and stored in u_release_note field. Target KB: [kb_sys_id from Step 3]. Ready for publishing upon CR closure.”
    • Call “Update CR with Release Draft Note Only” script tool.
    • Inputs:
      • change_request_sys_id = [sys_id from Step 1]
      • release_note_content = [Formatted Release Note from Step 7]
      • work_note_text = [Prepared confirmation work note text]
    • Expect outputs: update_success, update_message.
    • Log update_message internally (optional).

Notes:

  • Execute steps strictly in order.
  • Handle errors explicitly as described by stopping and logging errors in CR work notes.
  • Ensure inputs for tool calls use values stored from previous steps, particularly the CR sys_id and CI sys_id obtained in Step 1.

3. The AI Tools (Scripts)

These are the individual script-based tools the agent uses to interact with ServiceNow data. Each tool has a name, description, an input_schema defining its expected inputs, and the script itself.

Tool 1: Get Change Request and CI Details

  • Name: Get Change Request and CI Details
  • Description: Retrieves key details (change sys_id, change number and cmdb_ci with cmdb_ci.sys_id cmdb_ci.name of the related configuration item on the Change Request) on the provided Change Request sys_id. Returns the details as a (JSON object).
  • Input Schema: The tool expects one input: change_request_sys_id (The sys_id or number of the triggering Change Request record).
  • Script:
    (function(inputs) {
        var crSysId = inputs['change_request_sys_id'];
        var outputs = {};
        var changeGr = new GlideRecord('change_request');
        changeGr.addQuery("sys_id",crSysId).addOrCondition("number",crSysId);
        changeGr.query();
        if (changeGr.next()) {
            outputs['number'] = changeGr.getValue('number');
            outputs['sys_id'] = changeGr.getValue('sys_id');
            var ci = {};
            ci.name = changeGr.getDisplayValue('cmdb_ci');
            ci.sys_id = changeGr.getValue('cmdb_ci');
        } else {
             outputs['error_message'] = 'Change Request not found using input: ' + crSysId;
        }
        outputs['cmdb_ci'] = JSON.stringify(ci);
        return outputs;
    })(inputs);

Tool 2: Get Story Details for CR

  • Name: Get Story Details for CR
  • Description: Retrieves key details (number, short_description, description, acceptance_criteria, work_notes, comments) for all Story records directly related to the provided Change Request sys_id. Returns the details as a structured list (JSON string).
  • Input Schema: The tool expects one input: change_request_sys_id (The sys_id or number of the triggering Change Request record).
  • Script:
    (function(inputs) {
        var crSysId = inputs['change_request_sys_id'];
        var outputs = {};
        var stories = [];
        var storyGr = new GlideRecord('rm_story'); // Adjust table name if needed
        storyGr.addQuery('u_change_request', crSysId); // Adjust field name if needed
        storyGr.query();
        while (storyGr.next()) {
            var storyDetails = {};
            storyDetails.number = storyGr.getValue('number');
            storyDetails.short_description = storyGr.getValue('short_description');
            storyDetails.description = storyGr.getValue('description');
            storyDetails.acceptance_criteria = storyGr.getValue('acceptance_criteria');
            storyDetails.notes_and_comments = storyGr.work_notes.getJournalEntry(-1) + "\n" + storyGr.comments.getJournalEntry(-1);
            stories.push(storyDetails);
        }
        outputs['story_details_json'] = JSON.stringify(stories);
        return outputs;
    })(inputs);

Tool 3: Find Release Notes KB for CI

  • Name: Find Release Notes KB for CI
  • Description: Finds the unique 'Release notes' Knowledge Base article sys_id and content linked to the provided CI sys_id and KB Category name. Returns the KB sys_id and content, or an error message.
  • Input Schema: The tool expects one input: ci_sys_id (The sys_id of the Configuration Item from the Change Request).
  • Script:
    (function execute(inputs) {
        var outputs = {};
        var ciSysId = inputs['ci_sys_id'];
        var kbSysId = '';
        var kbContent = '';
        var errorMessage = '';
        var categoryName = "Release Notes"; // As per agent instructions
        var kbGr = new GlideRecord('kb_knowledge');
        kbGr.addQuery('cmdb_ci', ciSysId);
        kbGr.addQuery('kb_category.label', categoryName);
        kbGr.query();
        var count = kbGr.getRowCount();
        if (count === 1) {
            kbGr.next();
            kbSysId = kbGr.getUniqueValue();
            kbContent = kbGr.getValue('text'); // Adjust 'text' field if necessary
        } else if (count === 0) {
            errorMessage = 'Error: No KB article found for CI ' + ciSysId + ' and Category ' + categoryName + '.';
        } else {
            errorMessage = 'Error: Multiple (' + count + ') KB articles found for CI ' + ciSysId + ' and Category ' + categoryName + '. Require exactly one.';
        }
        outputs['kb_sys_id'] = kbSysId;
        outputs['kb_content'] = kbContent;
        outputs['error_message'] = errorMessage;
        return outputs;
    })(inputs);

Tool 4: Calculate Next Semantic Version

  • Name: Calculate Next Semantic Version
  • Description: Calculates the next semantic version number (e.g., 0.1.9 -> 0.2.0) based on the input version string 'X.Y.Z'.
  • Input Schema: The tool expects one input: current_version_string (The current version string in X.Y.Z format (e.g., ‘0.1.9’)).
  • Script:
    (function execute(inputs) {
        var outputs = {};
        var currentVersion = inputs['current_version_string'] || '0.0.0';
        var parts = currentVersion.split('.');
        var major = 0, minor = 0, patch = 0;
        var nextVersion = 'Error';
        if (parts.length === 3 && !isNaN(parseInt(parts[0])) && !isNaN(parseInt(parts[1])) && !isNaN(parseInt(parts[2]))) {
            major = parseInt(parts[0], 10);
            minor = parseInt(parts[1], 10);
            patch = parseInt(parts[2], 10);
            patch++;
            if (patch >= 10) { // Assuming minor increments at 10
                patch = 0;
                minor++;
                if (minor >= 10) { // Assuming major increments at 10
                    minor = 0;
                    major++;
                }
            }
            nextVersion = major + '.' + minor + '.' + patch;
        } else {
             nextVersion = 'Error: Invalid input format. Expected X.Y.Z';
        }
        outputs['next_version_string'] = nextVersion;
        return outputs;
    })(inputs);

Tool 5: Update CR with Release Draft Script

  • Name: Update CR with Release Draft Script
  • Description: Updates the triggering Change Request record by sys_id. Sets the u_release_note field with the generated text and appends a work note.
  • Input Schema: The tool expects three inputs: change_request_sys_id (The sys_id of the Change Request to update), release_note_content (The generated release note text), and work_note_text (The text to add as a work note).
  • Script:
    (function execute(inputs) {
        var outputs = {};
        var crSysId = inputs['change_request_sys_id'];
        var releaseNote = inputs['release_note_content'];
        var workNote = inputs['work_note_text'];
        var success = false;
        var message = '';
        if (!crSysId || !releaseNote || !workNote) {
            message = 'Error: Missing required input(s) (change_request_sys_id, release_note_content, or work_note_text).';
            outputs['update_success'] = success;
            outputs['update_message'] = message;
            return outputs;
        }
        var crGr = new GlideRecord('change_request');
        if (crGr.get(crSysId)) {
            crGr.setValue('u_release_note', releaseNote); // Custom field
            crGr.work_notes = workNote;
            if (crGr.update()) {
                success = true;
                message = 'Change Request ' + crGr.getValue('number') + ' updated successfully with release note draft and work note.';
            } else {
                message = 'Error: Failed to update Change Request ' + crSysId + ' fields.';
                gs.error('AI Agent Tool "Update CR with Release Draft Script" failed GlideRecord update for CR: ' + crSysId);
            }
        } else {
            message = 'Error: Change Request ' + crSysId + ' not found.';
        }
        outputs['update_success'] = success;
        outputs['update_message'] = message;
        return outputs;
    })(inputs);

Key Capabilities

This AI Agent provides several key benefits:

  1. Automation: Reduces manual effort in drafting initial release notes.
  2. Consistency: Ensures a standard process and format for release note generation.
  3. Data Consolidation: Gathers relevant information from CRs, Stories, and KBs.
  4. Version Management: Automatically determines and suggests the next release version.
  5. Error Handling: The agent’s instructions include steps to manage and report errors during its execution.
  6. Summarization (LLM-driven): Step 6 of the agent’s instructions relies on the LLM’s ability to summarize story content, which is a powerful generative AI feature.

How the Components Work Together

  1. A trigger condition (e.g., Change Request state moves to “Implement”) initiates the AI Usecase.
  2. The Usecase’s base_plan instructs the system to invoke the “Release Note Drafter Agent”.
  3. The Agent follows its detailed instructions, calling specific AI Tools (scripts) at appropriate steps.
  4. Tools fetch data (e.g., CR details, Story info, KB content), process it (e.g., calculate version), or update records (e.g., add release note to CR).
  5. The LLM (Large Language Model) is implicitly used for steps like “Summarize Story Changes” based on the agent’s instructions and the provided context.
  6. The final output is a draft release note stored on the Change Request, along with a confirmation work note.

Considerations for Implementation

  • Custom Fields: Ensure custom fields like u_release_note on change_request and u_change_request on rm_story (or your equivalent) exist.
  • Table/Field Names: Scripts may need adjustments if your table or field names differ (e.g., for Story-to-CR relationships).
  • KB Structure: The agent assumes a specific KB category (“Release Notes”) linked to CIs. Your KB setup might require changes to the “Find Release Notes KB for CI” tool.
  • Versioning Logic: There is really no need to get a GenAI tool to do the increment, this is just done for fun here to test it out.
  • Error Handling & Robustness: While basic error handling is included, consider adding more comprehensive logging or notification mechanisms for production environments.
  • LLM Prompts: The quality of the LLM-generated summary (Step 6 in agent instructions) will depend on the clarity of the story data and the implicit prompting. Fine-tuning the agent’s role or providing more specific instructions around summarization might be necessary.

Conclusion

The “Generate Release Note Draft on Change” AI Agent is a powerful example of how ServiceNow’s AI Agent Studio can automate complex, multi-step processes. By combining structured Usecases, intelligent Agents, and flexible script-based Tools, organizations can streamline workflows, improve data consistency, and free up valuable time for their development and release teams. This deep dive provides a blueprint that can be adapted and extended for various automation needs within the platform.