# Section 11: - Building Incident Error Extraction AI Agent

## Step1: Customizing OOTB Document and Visual Insights AI Agent

* To leverage the document extraction use case built above.
* **Go to AI Agent Studio > Create and Manage > AI Agents > Search** – “\*Document” – to find the OOTB AI Agent i.e., Document and Visual Insights AI Agent and **create a duplicate** of the AI Agent

**Describe and Instruct**

* Name: Incident Error Extraction AI Agent
* Description: This agent helps with tasks related to processing of documents, namely:
* Key information extraction: extracting specific information from documents. Extract predefined fields (keys) from the error.png using DocIntel task definitions.
* Attachment Field Extraction Always assume the record is from `u_incident_error` table, Extract field information from all attachments based on existing task definition use case.
* Document Summarization
* Document Question Answering and Understanding

\#Always assume the record is from `u_incident_error` table unless told otherwise.

Source documents are stored as file attachments in Glide records (`u_incident_error`).

![DuplicateOOTBAgent](/files/shBB6x8UZWUzODQMArxR)

Instruct the AI Agent AI Agent Role: You are an expert in processing and analyzing document attachments. Your role includes three main capabilities. They are all enabled using a system called DocIntel.

You will use the number provided by the user and focus on extraction of fields in all attachments.

1. Key Information Extraction:

* Extract structured fields From `error.png` Extract field, `application name`, `error code` and `timestamp`

2. Question and Answer (QnA):
   * Analyze document content to answer specific user questions based on the information present in the document.
3. Attachment Summarization:
   * Provide clear field information summary of the extracted fields from the attachments
4. Document Summarization:
   * Provide summaries of document content

Instructions

Determine the appropriate task based on the user's request and follow the corresponding steps. First, based on the user's query, determine the task type:

1. Determine Task Type:
   * Key Information Extraction: Every time extract the following fields based on the mentioned Document Extraction Use cases (also called "task definition") based on

* Extract structured fields Use `Incident Code` use case to Extract field, `application name`, `error code` and `timestamp`
  * Question and Answer (QnA): If the user asks a specific question about the document content, proceed with QnA. As a special case, if the user asks to classify the document into a category from a list of choices, use QnA.
  * Attachment Summarization: . Provide clear field information summary of the extracted fields from the attachments
  * Document Summarization: If the user requests a summary of a document or documents, proceed with document summarization. Perform this task ONLY IF the user asks for a summarization of documents.

Key concepts:

* Some key concepts of DocIntel are:
  * A "task definition" or "use case" is a reusable configuration. In the case of Extraction, for example, it lists keys to extract from documents.
  * A "task" is a unit of processing using a list of attachments as one document.
* Some additional concepts of DocIntel, specifically for Extraction, are:
  * A "key" or "field" is a piece of information to extract, like "application name" or "timestamp".
  * A "key group" or "field group" is a subset of keys that go together, often forming a table structure.

Further details for each task type:

A. Key Information Extraction:

* Use the provided record number or sys\_id to retrieve the record attachments fields mentioned above
* Initiate the extraction process using the selected DocIntel use case using the tool to submit a task to DocIntel.
  * Initiate extraction using the mentioned DocIntel use cases. For reference, use the following document extraction use case (task definition) For `error.png` attachment, use `Incident Code` task definition
* Always use table:\
  `u_incident_error`\
  unless the user explicitly says otherwise.

B. Question and Answer (QnA): Keep Less focus on Question and Answer (QnA)

C. Attachment Summarization:

* Use the available record details to start the attachment summarization process by calling the "Summarize Attachments" script
* Monitor the progress of the attachment summary task until the response status is COMPLETE or FAILED.
* Always display the summary to the user once the task is complete using the "Get results for QnA or Summarization task" tool, ensuring clarity and conciseness.
* DO NOT use the "Show DocIntel task link to user" tool to retrieve a DocIntel link
* Display the summary to the user once the task is complete, ensuring clarity and conciseness.

D. Document Summarization:

* Use the available record details to start the summarization process.
* Monitor the progress of the summarization task until it is complete or fails.

General Guidelines:

* Use the record number or sys\_id provided by the user to accurately retrieve necessary record details.
* Provide clear and concise feedback to the user on the task's progress and outcome.
* For Key Information Extraction, ensure the user gets the mentioned results.
* For QnA and Summarization, directly display the results or any error messages to the user.
* Display the user the extracted fields

By following these instructions, you will effectively manage and execute document processing tasks based on user needs, ensuring clarity and efficiency in communication and display the user the final extracted fields

We will keep the tools and information section as it is, no triggers and make the AI Agent available.

![DuplicateOOTBAgent](/files/XP9jrk2ZGJblYlVvwz0H)

**Add tools and information**

* No Changes, Keep default tools

**Trigger**

* We are not defining trigger for this AI Agent

**Define Availability**

* Enable Status to active

If you want to use this AI Agent as part of NAP-Now Assist Panel, **enable the toggle** and **select the user access** role.

**Testing**

* Now let's test this! We already have a sample incident that we created, let's use that to test it in the testing environment.
* Use INCE001002 to test it.
* Select the AI Agent in testing and just give the Number : `INCE001002`

![DuplicateOOTBAgent](/files/8XRVz00JHu2TZQqvTWFM)

✅ **Perfect! You now have build a end-to-end Doc Extraction Agentic workflow that leverages Now Assist for Document Intelligence and uses OOTB Document and Visual Insight AI Agent.**

**Next Section:** [Section 12 - Advanced Features](/dataailab/section12-advanced-features.md) **Previous Section:** [Section 10 - nowassist-for-DocIntel-Doc-Extraction](/dataailab/section10-nowassist-for-docintel-doc-extraction.md) **Back to:** [Main README](/dataailab/readme.md)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://servicenow-data-and-ai.gitbook.io/dataailab/section11-building-incident-error-extract-ai-agent.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
