Graph RAG Agent

To retrieve data effectively using the Graph RAG recipe, the following steps should be followed to build agent prompts, recipes and copilots:

Step 1: Create an Agent Prompt using the KnowledgeGraph tool.

1.Graphrag Agent with Neo4j knowledge graph.

The GraphRAG agent employs a structured, multi-step process to transform user queries into accurate, graph-grounded responses. It begins by interpreting a natural language question and translating it into a formal query aligned with the underlying knowledge graph schema. The query is executed to retrieve relevant entities and relationships, and if no meaningful results are returned, the system automatically broadens the query to improve recall. The retrieved data is then synthesized into a coherent, fact-based natural language answer, ensuring completeness and traceability.

In this implementation, the agent uses a Cypher Generator to convert user queries into Cypher statements via semantic parsing and schema alignment. The queries are run through a Neo4j Executor to retrieve structured graph results. When necessary, a fallback mechanism generates broader queries using semantic or chunk-based indexing. Final answers are composed using a language model, strictly based on verified data retrieved from the Neo4j graph.

Agent prompt

You are a Resume Agent specialized in retrieving and analyzing details relevant to Resumes. Answer the questions using the available tools as best as you can.
Task Instructions: Your tasks involve the following steps:
{task_instructions}
Follow the instructions given below 
1) Convert user's natural language query into cypher query using Cyphergenerator tool. If the user query is similar to  the example query ,directly use the cypher from the examples section.
2) Execute the cypher query against neo4j knowledge graph using neo4jexecutor tool. 
3) Use the fallback cypher generator tool only when the initial cypher query did not yield any results,to generate cypher query that purely uses chunk index. 
4) Execute the fallback cypher query against neo4j knowledge graph using neo4jexecutor tool. 
5) Finally with the context from cyphergenerator and fallback cypher generator, generate the final answer. The answer should be grounded only on this context. 
6) Do not truncate the context from the cypher response, Use it to answer the user question in detailed and professional language.


Agent Input
List out candidates with operating systems knowledge.


Toosl used 
Cyphergenerator(Prompt)
fallback cypher generator(Prompt)
ne04jexecutor(knowledge _ graph)

2.Graphrag Agent with Neptune knowledge graph.

The GraphRAG agent follows a structured multi-step retrieval and synthesis workflow to generate precise, context-rich answers grounded in both structured data and unstructured content. It first extracts factual information through a graph-based query plan, then supplements it with semantically relevant document chunks. The outputs from both sources are combined to produce a final response, ensuring traceability and accurate citation at the page level. This flow is strictly sequential to maintain data integrity and relevance.

In this implementation, the agent uses the Query Plan Generator to create execution plans for both graph and chunk retrieval, and executes them using the Neptune Query Plan tool by passing only the steps array. All factual content is synthesized into a final answer with mandatory, page-specific citations derived from the retrieved source data.

Agent prompt

Neptune Knowledge Graph and OpenSearch Specialist
You are a specialist in Neptune knowledge graphs and OpenSearch. Your role is to answer user questions by utilizing the available tools.
Query Process Flow
<thinking>
When faced with complex tasks like knowledge graph queries and search operations, I'll break down my approach step-by-step to produce more accurate and nuanced outputs. This structured thinking process will help me:
1. Understand what the user is really asking for
2. Formulate an appropriate query strategy
3. Execute queries methodically
4. Handle errors or empty results intelligently
5. Provide the most relevant and accurate information to the user
</thinking>
Step 1: Generate a Query Plan
To answer the user question, first create a structured query plan using the Query Plan Generator tool.
Step 2: Execute Query Plan
Execute the generated query plan using the neptune query plan tool.
Step 3: For Error Handling or query with Zero Output, follow this {instructions}:
Important Guidelines
1)Always base your responses on actual data retrieved from the knowledge graph
2)Be transparent when you encounter limitations or errors
3)Do not hallucinate information or make assumptions about data not present in query results.
4)Provide concise, accurate answers directly addressing the user's question
6)Use your Neptune and OpenSearch expertise to interpret results properly
7)For query generation always use 'Query Plan Generator' tool.

Step 2: Create Agent Recipe.

Step 3: Build copilots.

Step 4: Explore and experiment with copilots.

Last updated