Skip to content

Commit 378b38e

Browse files
committed
usecase change
1 parent be34fb2 commit 378b38e

File tree

5 files changed

+342
-250
lines changed

5 files changed

+342
-250
lines changed

supporting-blog-content/human-in-the-loop-with-langgraph-and-elasticsearch/README.md

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# LangGraph + Elasticsearch Human-in-the-Loop
22

3-
Flight search application using LangGraph for human-in-the-loop workflow and Elasticsearch for vector search.
3+
Flight search application using LangGraph for human-in-the-loop workflow and Elasticsearch for vector search. This is a supporting blog content for the article: [Building Human-in-the-Loop AI Agents with LangGraph and Elasticsearch](https://www.elastic.co/search-labs/blog/human-in-the-loop-with-langgraph-and-elasticsearch).
44

55
## Prerequisites
66

@@ -29,8 +29,8 @@ Create a `.env` file in the root directory:
2929

3030
```env
3131
ELASTICSEARCH_ENDPOINT=https://your-elasticsearch-instance.com
32-
ELASTICSEARCH_API_KEY=your-api-key
33-
OPENAI_API_KEY=your-openai-api-key
32+
ELASTICSEARCH_API_KEY="your-api-key"
33+
OPENAI_API_KEY="your-openai-api-key"
3434
```
3535

3636
## Usage
@@ -46,11 +46,3 @@ npm start
4646
- 👤 Human-in-the-loop workflow with LangGraph
4747
- 📊 Workflow visualization (generates `workflow_graph.png`)
4848

49-
## Workflow
50-
51-
1. **Retrieve Flights** - Search Elasticsearch with vector similarity
52-
2. **Evaluate Results** - Auto-select if 1 result, show options if multiple
53-
3. **Show Results** - Display flight options to user
54-
4. **Request User Choice** - Pause workflow for user input (HITL)
55-
5. **Disambiguate & Answer** - Use LLM to interpret selection and return final answer
56-

supporting-blog-content/human-in-the-loop-with-langgraph-and-elasticsearch/dataIngestion.ts

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,16 @@ import dotenv from "dotenv";
66

77
dotenv.config();
88

9-
const VECTOR_INDEX = "flights-offerings";
9+
const VECTOR_INDEX = "legal-precedents";
1010

1111
// Types
1212
export interface DocumentMetadata {
13-
from_city: string;
14-
to_city: string;
15-
airport_code: string;
16-
airport_name: string;
17-
country: string;
18-
airline: string;
19-
date: string;
20-
price: number;
21-
time_approx: string;
13+
caseId: string;
14+
contractType: string;
15+
delayPeriod: string;
16+
outcome: string;
17+
reasoning: string;
18+
keyTerms: string;
2219
title: string;
2320
}
2421

@@ -88,20 +85,17 @@ export async function ingestData(): Promise<void> {
8885
metadata: {
8986
type: "object",
9087
properties: {
91-
from_city: { type: "keyword" },
92-
to_city: { type: "keyword" },
93-
airport_code: { type: "keyword" },
94-
airport_name: {
88+
caseId: { type: "keyword" },
89+
contractType: { type: "keyword" },
90+
delayPeriod: {
9591
type: "text",
9692
fields: {
9793
keyword: { type: "keyword" },
9894
},
9995
},
100-
country: { type: "keyword" },
101-
airline: { type: "keyword" },
102-
date: { type: "date" },
103-
price: { type: "integer" },
104-
time_approx: { type: "keyword" },
96+
outcome: { type: "keyword" },
97+
reasoning: { type: "text" },
98+
keyTerms: { type: "text" },
10599
title: {
106100
type: "text",
107101
fields: {
Lines changed: 80 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -1,152 +1,122 @@
11
[
22
{
3-
"pageContent": "Ticket: Medellín (MDE) → Sao Paulo (GRU). 1 stop. Airline: AndeanSky.",
3+
"pageContent": "Legal precedent: Case A - Service delivery delay considered breach. A software development contract stipulated delivery within 'reasonable time'. A two-week delay significantly impacted the client's product launch, causing measurable financial harm. The court ruled this constituted material breach despite no explicit deadline.",
44
"metadata": {
5-
"from_city": "Medellín",
6-
"to_city": "Sao Paulo",
7-
"airport_code": "GRU",
8-
"airport_name": "Guarulhos International",
9-
"country": "Brazil",
10-
"airline": "AndeanSky",
11-
"date": "2025-10-10",
12-
"price": 480,
13-
"time_approx": "7h 30m",
14-
"title": "MDE → GRU (AndeanSky)"
5+
"caseId": "CASE-A-2023",
6+
"contractType": "service agreement",
7+
"delayPeriod": "two weeks",
8+
"outcome": "breach found",
9+
"reasoning": "delay affected operations and caused financial harm",
10+
"keyTerms": "reasonable time, material breach, timely delivery",
11+
"title": "Case A: Delay Breach with Operational Impact"
1512
}
1613
},
1714
{
18-
"pageContent": "Ticket: Medellín (MDE) → Sao Paulo (CGH). 1 stop. Airline: CoffeeAir.",
15+
"pageContent": "Legal precedent: Case B - Service delay not considered breach. A consulting contract used term 'timely delivery' without specific dates. A three-week delay occurred but contract lacked explicit schedule. Court ruled no breach as parties had not defined concrete timeline and delay did not cause demonstrable harm.",
1916
"metadata": {
20-
"from_city": "Medellín",
21-
"to_city": "Sao Paulo",
22-
"airport_code": "CGH",
23-
"airport_name": "Congonhas",
24-
"country": "Brazil",
25-
"airline": "CoffeeAir",
26-
"date": "2025-10-10",
27-
"price": 455,
28-
"time_approx": "8h 05m",
29-
"title": "MDE → CGH (CoffeeAir)"
17+
"caseId": "CASE-B-2022",
18+
"contractType": "consulting agreement",
19+
"delayPeriod": "three weeks",
20+
"outcome": "no breach found",
21+
"reasoning": "no explicit deadline defined, no demonstrable harm",
22+
"keyTerms": "timely delivery, open terms, schedule definition",
23+
"title": "Case B: Delay Without Explicit Schedule"
3024
}
3125
},
3226
{
33-
"pageContent": "Ticket: Medellín (MDE) → Tokyo (HND). 2 stops. Airline: CondorJet.",
27+
"pageContent": "Legal precedent: Case C - Delay permitted due to justified causes. A construction service contract had defined timeline but external regulatory approval delays prevented timely completion. Court found delay was justified and did not constitute breach when causes were beyond provider's control.",
3428
"metadata": {
35-
"from_city": "Medellín",
36-
"to_city": "Tokyo",
37-
"airport_code": "HND",
38-
"airport_name": "Haneda",
39-
"country": "Japan",
40-
"airline": "CondorJet",
41-
"date": "2025-11-05",
42-
"price": 1290,
43-
"time_approx": "22h 10m",
44-
"title": "MDE → HND (CondorJet)"
29+
"caseId": "CASE-C-2023",
30+
"contractType": "construction service",
31+
"delayPeriod": "one month",
32+
"outcome": "no breach found",
33+
"reasoning": "external factors beyond control, force majeure applied",
34+
"keyTerms": "justified causes, force majeure, regulatory delays",
35+
"title": "Case C: Justified Delay External Factors"
4536
}
4637
},
4738
{
48-
"pageContent": "Ticket: Medellín (MDE) → Tokyo (NRT). 1–2 stops. Airline: CaribeWings.",
39+
"pageContent": "Legal precedent: Case D - Interpretation of 'prompt delivery' term. Contract stated services must be provided 'promptly'. Court analyzed industry standards and prior dealings between parties to determine reasonableness. Ten-day delay was found acceptable given industry norms for similar services.",
4940
"metadata": {
50-
"from_city": "Medellín",
51-
"to_city": "Tokyo",
52-
"airport_code": "NRT",
53-
"airport_name": "Narita",
54-
"country": "Japan",
55-
"airline": "CaribeWings",
56-
"date": "2025-11-05",
57-
"price": 1215,
58-
"time_approx": "23h 30m",
59-
"title": "MDE → NRT (CaribeWings)"
41+
"caseId": "CASE-D-2021",
42+
"contractType": "service agreement",
43+
"delayPeriod": "ten days",
44+
"outcome": "no breach found",
45+
"reasoning": "industry standards applied, reasonable interpretation",
46+
"keyTerms": "prompt delivery, industry standards, reasonable time",
47+
"title": "Case D: Prompt Delivery Industry Standards"
6048
}
6149
},
6250
{
63-
"pageContent": "Ticket: Medellín (MDE) → New York (JFK). 1 stop. Airline: AndeanSky.",
51+
"pageContent": "Legal precedent: Case E - Material breach vs minor delay. Service contract had approximate delivery timeline. Five-day delay occurred but service was fully functional and met all quality specifications. Court ruled this was minor breach not justifying contract termination.",
6452
"metadata": {
65-
"from_city": "Medellín",
66-
"to_city": "New York",
67-
"airport_code": "JFK",
68-
"airport_name": "John F. Kennedy International",
69-
"country": "USA",
70-
"airline": "AndeanSky",
71-
"date": "2025-12-01",
72-
"price": 340,
73-
"time_approx": "6h 40m",
74-
"title": "MDE → JFK (AndeanSky)"
53+
"caseId": "CASE-E-2022",
54+
"contractType": "service agreement",
55+
"delayPeriod": "five days",
56+
"outcome": "minor breach only",
57+
"reasoning": "delay minimal, quality maintained, termination unjustified",
58+
"keyTerms": "material breach, substantial performance, termination rights",
59+
"title": "Case E: Minor Delay Quality Maintained"
7560
}
7661
},
7762
{
78-
"pageContent": "Ticket: Medellín (MDE) → New York (LGA). 1 stop. Airline: CoffeeAir.",
63+
"pageContent": "Legal precedent: Case F - Open-ended contract terms require good faith. Contract used 'timely manner' without definition. Provider took reasonable steps but faced unexpected technical issues causing delay. Court ruled parties must interpret open terms in good faith and delay was reasonable given circumstances.",
7964
"metadata": {
80-
"from_city": "Medellín",
81-
"to_city": "New York",
82-
"airport_code": "LGA",
83-
"airport_name": "LaGuardia",
84-
"country": "USA",
85-
"airline": "CoffeeAir",
86-
"date": "2025-12-01",
87-
"price": 325,
88-
"time_approx": "6h 55m",
89-
"title": "MDE → LGA (CoffeeAir)"
65+
"caseId": "CASE-F-2023",
66+
"contractType": "technology service",
67+
"delayPeriod": "two weeks",
68+
"outcome": "no breach found",
69+
"reasoning": "good faith interpretation, reasonable efforts demonstrated",
70+
"keyTerms": "timely manner, good faith, open terms interpretation",
71+
"title": "Case F: Good Faith Open Terms"
9072
}
9173
},
9274
{
93-
"pageContent": "Ticket: Medellín (MDE) → London (LHR). 1 stop. Airline: CondorJet.",
75+
"pageContent": "Legal precedent: Case G - Schedule linked to milestones. Service contract defined delivery as 'upon completion of client's approval process'. Delay occurred but was directly caused by client's slow approval. Court found provider not in breach as timeline was dependent on client actions.",
9476
"metadata": {
95-
"from_city": "Medellín",
96-
"to_city": "London",
97-
"airport_code": "LHR",
98-
"airport_name": "Heathrow",
99-
"country": "UK",
100-
"airline": "CondorJet",
101-
"date": "2026-01-15",
102-
"price": 890,
103-
"time_approx": "14h 30m",
104-
"title": "MDE → LHR (CondorJet)"
77+
"caseId": "CASE-G-2022",
78+
"contractType": "professional service",
79+
"delayPeriod": "variable",
80+
"outcome": "no breach found",
81+
"reasoning": "timeline dependent on client actions, conditional delivery",
82+
"keyTerms": "milestone delivery, conditional timeline, client obligations",
83+
"title": "Case G: Milestone Dependent Delivery"
10584
}
10685
},
10786
{
108-
"pageContent": "Ticket: Medellín (MDE) → London (LGW). 1–2 stops. Airline: CaribeWings.",
87+
"pageContent": "Legal precedent: Case H - Repeated delays pattern. Service provider had history of missing approximate deadlines across multiple deliverables. Court found pattern of delays constituted breach even when individual delays seemed minor, showing failure to meet contractual obligations consistently.",
10988
"metadata": {
110-
"from_city": "Medellín",
111-
"to_city": "London",
112-
"airport_code": "LGW",
113-
"airport_name": "Gatwick",
114-
"country": "UK",
115-
"airline": "CaribeWings",
116-
"date": "2026-01-15",
117-
"price": 760,
118-
"time_approx": "15h 10m",
119-
"title": "MDE → LGW (CaribeWings)"
89+
"caseId": "CASE-H-2021",
90+
"contractType": "ongoing service agreement",
91+
"delayPeriod": "multiple instances",
92+
"outcome": "breach found",
93+
"reasoning": "pattern demonstrated failure to perform, cumulative effect",
94+
"keyTerms": "repeated breach, pattern of conduct, consistent performance",
95+
"title": "Case H: Pattern of Repeated Delays"
12096
}
12197
},
12298
{
123-
"pageContent": "Ticket: Medellín (MDE) → Paris (CDG). 1 stop. Airline: CoffeeAir.",
99+
"pageContent": "Legal precedent: Case I - Contractual obligation interpretation. Contract required 'expeditious service delivery'. Court examined contract as whole, prior communications, and purpose of service to interpret meaning. Two-week delay found unreasonable given urgent nature stated in preliminary negotiations.",
124100
"metadata": {
125-
"from_city": "Medellín",
126-
"to_city": "Paris",
127-
"airport_code": "CDG",
128-
"airport_name": "Charles de Gaulle",
129-
"country": "France",
130-
"airline": "CoffeeAir",
131-
"date": "2025-10-22",
132-
"price": 720,
133-
"time_approx": "13h 50m",
134-
"title": "MDE → CDG (CoffeeAir)"
101+
"caseId": "CASE-I-2023",
102+
"contractType": "urgent service agreement",
103+
"delayPeriod": "two weeks",
104+
"outcome": "breach found",
105+
"reasoning": "context and preliminary negotiations showed urgency expectation",
106+
"keyTerms": "expeditious delivery, contract interpretation, preliminary negotiations",
107+
"title": "Case I: Urgent Service Context"
135108
}
136109
},
137110
{
138-
"pageContent": "Ticket: Medellín (MDE) → Paris (ORY). 1 stop. Airline: AndeanSky.",
111+
"pageContent": "Legal precedent: Case J - Provider notification obligations. Service contract had flexible timeline but required provider to notify of delays. Provider failed to communicate expected delay. Court found this failure to notify constituted breach regardless of whether delay itself was reasonable.",
139112
"metadata": {
140-
"from_city": "Medellín",
141-
"to_city": "Paris",
142-
"airport_code": "ORY",
143-
"airport_name": "Orly",
144-
"country": "France",
145-
"airline": "AndeanSky",
146-
"date": "2025-10-22",
147-
"price": 695,
148-
"time_approx": "13h 20m",
149-
"title": "MDE → ORY (AndeanSky)"
113+
"caseId": "CASE-J-2022",
114+
"contractType": "service agreement",
115+
"delayPeriod": "one week",
116+
"outcome": "breach found",
117+
"reasoning": "failure to notify violated contractual communication obligations",
118+
"keyTerms": "notification duty, communication obligations, transparency",
119+
"title": "Case J: Notification Failure Breach"
150120
}
151121
}
152122
]

0 commit comments

Comments
 (0)