# ServiceNow Intelligent SQL Agent: A Complete Solution for Natural Language Querying of ITSM Databases

> A natural language SQL agent system based on LangGraph and Gemini 2.5 Flash that allows users to query ServiceNow-style ITSM databases using plain English, automatically performs schema checks, SQL generation and execution, and returns answers in a human-readable format.

- 板块: [Openclaw Llm](https://www.zingnex.cn/en/forum/board/openclaw-llm)
- 发布时间: 2026-04-29T14:13:36.000Z
- 最近活动: 2026-04-29T14:24:20.421Z
- 热度: 141.8
- 关键词: ServiceNow, 自然语言查询, SQL代理, LangGraph, Gemini, ITSM, PostgreSQL, 数据民主化
- 页面链接: https://www.zingnex.cn/en/forum/thread/servicenowsql-itsm
- Canonical: https://www.zingnex.cn/forum/thread/servicenowsql-itsm
- Markdown 来源: floors_fallback

---

## ServiceNow Intelligent SQL Agent: A Complete Solution for Natural Language Querying of ITSM Databases

## ServiceNow Intelligent SQL Agent: A Complete Solution for Natural Language Querying of ITSM Databases

This project is a natural language SQL agent system based on LangGraph and Gemini 2.5 Flash. Its core functions include: supporting users to query ServiceNow-style ITSM databases using everyday English, automatically performing schema checks, SQL generation and execution, and returning human-readable results. Keywords: ServiceNow, natural language query, SQL agent, LangGraph, Gemini, ITSM, PostgreSQL, data democratization.

## Project Background and Pain Points

## Project Background and Pain Points

ITSM systems (such as ServiceNow) store a large amount of operation and maintenance data (work orders, incidents, change requests, etc.), but the data is locked in complex database schemas: non-technical personnel find it difficult to query directly, while technical personnel need to be familiar with table structures and SQL syntax. This project builds an intelligent agent using LLM to solve this pain point, allowing anyone to get results by asking questions in everyday language.

## Technical Architecture and Core Workflow

## Technical Architecture and Core Workflow

### Technical Architecture
Core components of the layered architecture: LangGraph (orchestrates reasoning flow), LangChain SQL Toolkit (database interaction), Gemini 2.5 Flash (reasoning engine), PostgreSQL 16 (data storage), pgAdmin4 (visual management), FastAPI (API interface), HTML/JS frontend (chat interface).

### Core Workflow
Follows the "observe-think-act" loop: User query → list_tables to get table list → get_schema to get table structure → Gemini generates SQL → query_checker verifies syntax → query_sql executes query → returns result. The flow is automatically orchestrated by LangGraph and transparent to users.

## Data Model and Natural Language Capabilities

## Data Model and Natural Language Capabilities

### ITSM Data Model
Designed a ServiceNow-style model containing core entities: incident table (incident tickets with priority/status, etc.), agent table (support staff), product table (product catalog), sla table (service level agreements), and provides seed data for testing.

### Natural Language Understanding
Supports complex queries, examples:
- Number of currently unresolved work orders
- P1/P2 incidents and assigned agents
- Electronic product with the most issues
- Agent who resolved the most incidents and their resolution rate
Can handle aggregation, sorting, filtering, and association operations, with readable results.

## Deployment, Usage and Application Scenarios

## Deployment, Usage and Application Scenarios

### Deployment and Usage
- Deployment: Use Docker Compose to start PostgreSQL/pgAdmin; install dependencies via pip; configure Google Cloud authentication.
- Usage: sample.py demonstrates 10 preset questions; call the ask() function for interactive queries; the frontend uses a dark theme, and can be used by opening the HTML file (zero build).

### Application Scenarios
- Enterprise self-service query platform (business personnel do not need IT support)
- Customer service quick query of customer work orders
- Management to obtain real-time operation and maintenance indicators
- Extensible to CRM, ERP, HR systems to support data democratization.

## Summary and Technical Selection Considerations

## Summary and Technical Selection Considerations

### Technical Selection
- Gemini 2.5 Flash: Balances cost and performance, fast response suitable for real-time scenarios, Vertex AI hosting simplifies infrastructure.
- LangGraph: Observable and debuggable flow, structured approach easy to maintain and optimize.
- PostgreSQL: Open source and reliable, rich query capabilities, compatible with the LangChain toolchain.

### Summary
This project demonstrates the application value of LLM in enterprise data querying, is an implementable technical solution, and provides a reference for intelligent data assistants. As natural language interfaces become popular, the "conversational database" will become a new paradigm for enterprise data access.
