liveBook · Manning

Chapter 15: Building a QA agent with LangGraph

What you will learn in chapter 15 of Knowledge Graphs and LLMs in Action

The introduction previews an application that will combine chapter 14’s knowledge-graph querying techniques into a LangGraph pipeline with a Streamlit interface.

After this chapter you will be able to

What it builds on

Section by section

Introduction

The introduction previews an application that will combine chapter 14’s knowledge-graph querying techniques into a LangGraph pipeline with a Streamlit interface.

15.1 Building the LangGraph pipeline

The section introduces LangGraph’s shared-state and directed-graph model for coordinating the stages of a knowledge-graph question-answering pipeline.

Key terms: shared state, document retrieval, answer generation, directed graphs, nodes, edges, dynamic edge resolution, coherent state, flexibility in flow control, expert-emulating architecture

15.1.1 System architecture overview

This section maps the KG question-answering process onto a LangGraph workflow and explains how providers and a processing interface support it.

Key terms: LangGraph workflow, agent function, workflow state, configuration provider, schema provider, prompt templates, database schema, question processing interface, event stream, state updates

15.1.2 Configuring pipeline components

This section explains how a centralized configuration component stores the QA pipeline’s guidance and prompt references while exposing templates and annotations through a clean interface.

Key terms: configuration component, prompt templates, KG annotations, separation of concerns, operational notes, examples, prompt template references, query generation, Jinja2, ChainConfiguration

15.1.3 Schema translation service

The section explains how a schema provider turns a Neo4j technical schema into a business-oriented schema that LLMs can use to generate queries.

Key terms: conceptual schema, technical schema, schema provider, skip list, description section, YAML, business-level descriptions, apoc.meta.schema, get_schema, apply_configuration

15.1.4 State management design

This section explains how a shared LangGraph state carries information between pipeline agents and records what the pipeline needs to route work and handle errors.

Key terms: state object, shared memory space, chain of responsibility, question, output_type, schema, query, results_error, summary

15.1.5 Pipeline agent implementation

This section shows how specialized LangGraph agents update shared state, execute and route a KG query, and form a question-answering workflow.

Key terms: intent detection agent, output_type, output_reason, schema extraction agent, Neo4jSchema, retries, text-to-Cypher agent, annotations, selection state, query

15.1.6 Pipeline integration layer

This section explains how a question-processing interface turns LangGraph pipeline execution into frontend-friendly events that provide progress feedback while keeping presentation separate.

Key terms: invoke mode, stream execution mode, interface layer, generator function, initial configuration and state, intent detection, pipeline stage, response type, response payload, current state

15.2 Streamlit application

This section explains why a Streamlit interface fits the LangGraph question-answering pipeline’s interaction, feedback, and prototyping needs.

Key terms: interactive graph visualization, chat-like interface, real-time feedback, state information, Streamlit, session state, automatic UI updating, Python-first approach, custom components, prototyping

15.2.1 Application overview

The section explains how the application interface supports graph exploration, context-aware questions, and visible, multiformat answers.

Key terms: graph canvas, question input area, KG, Selection column, context-awareness, visual context, query generation, history area, interactive maps, tables

15.2.2 LangGraph integration

This section explains how Streamlit displays LangGraph pipeline progress immediately while preserving a complete, rendered conversation history.

Key terms: event-driven pattern, question processing interface, LangGraph pipeline, Streamlit placeholders, MessageHistory, END event, permanent conversation history, message dictionaries, update method, display_message

15.3 Expert-emulating investigation

Introduces the knowledge-graph connections that support an investigation across crimes, surveillance sightings, vehicles, and people.

Key terms: Crime, ANPRCamera, CameraEvent, Vehicle, Person, COMMITTED

15.3.1 Identifying the initial case

An initial crime query shows how the QA agent selects an active case, presents it as a graph node, and surfaces details for the investigation.

Key terms: explicit constraints, implicit expectations, graph visualization, Cypher query, criminal trespass, narrative, chat interface, summary

15.3.2 Spatial analysis of surveillance coverage

The section shows how a selection-aware spatial query finds a nearby ANPR camera and uses graph and map views to make its investigative value apparent.

Key terms: crime node, ANPR camera, selected crime, spatial query processing, graph visualization, interactive map, adaptive response

15.3.3 Vehicle pattern detection

This section shows how an investigator combines a selected ANPR camera with incident details to find and inspect matching vehicles.

Key terms: ANPR camera, current selection, temporal constraint, property matching, vehicle nodes, detection events, potential suspects

15.3.4 Context-aware request refinement

This section shows how a request grounded in a selected crime node and an investigator’s intent can return the same vehicles while producing a more useful analysis of their detection times.

Key terms: selected crime node, node properties, constraints, investigative context, summarization, temporal patterns

15.3.5 Historical record analysis

The section shows how adding vehicle owners’ criminal histories to an ongoing investigation can reveal a relevant connection and help the agent present it as an investigative lead.

Key terms: ownership relationships, criminal records, criminal trespass, query refinements, spatial, temporal, and historical, summary agent

15.4 Future directions and enhancements

This section explains why the QA agent is a foundation for improvement: its visible decisions support feedback, and its expert-emulating design guides changes.

Key terms: transparency, observability, feedback, expert emulation, schema context, reasoned steps

15.4.1 Learning from use

This section explains how data from actual use could guide improvements to the QA agent.

Key terms: comprehensive observability, actual use patterns, complaint-like questions, LLM-based analysis, pain points, chain of reasoning, example database, clusters of similar queries, specialized handling, schema

15.4.2 Enhancing core capabilities

The section proposes two ways to make a KG question-answering agent handle schemas more like a human expert: enriching them from data patterns and organizing them at multiple levels of detail.

Key terms: schema enrichment agents, base schema, data patterns, multilayer schema management, domain-focused views, levels of abstraction

15.4.3 Advanced evolution paths

This section argues that fine-tuned, KG-aware components could address the scaling limits of prompt-based schema understanding without replacing the system’s expert-emulating pipeline.

Key terms: in-context learning, fine-tuning, schema, KG-aware agents, expert-emulating architecture, in-context learning components, observable pipeline structure, step-by-step reasoning

15.5 Summary

Concepts explained in this chapter

← Chapter 14: Asking a KG questions with natural language

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.