-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
350 lines (340 loc) · 11.8 KB
/
Copy pathmain.py
File metadata and controls
350 lines (340 loc) · 11.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
from __future__ import annotations
import argparse
from agents.report_agent import ReportAgent
from models import InspectionReport
from workflows.inspection_graph import run_inspection_graph
def build_parser() -> argparse.ArgumentParser:
parser = argparse.ArgumentParser(
description="Run the infrastructure inspection multi-agent prototype."
)
parser.add_argument("--asset-id", default="A-100")
parser.add_argument("--asset-type", default="bridge")
parser.add_argument("--asset-name", default="Demo Overpass")
parser.add_argument("--location", default="North service corridor")
parser.add_argument(
"--latitude",
type=float,
default=None,
help="Asset latitude used by live weather, traffic, and event context tools.",
)
parser.add_argument(
"--longitude",
type=float,
default=None,
help="Asset longitude used by live weather, traffic, and event context tools.",
)
parser.add_argument(
"--criticality",
choices=["low", "medium", "high", "critical"],
default="high",
)
parser.add_argument(
"--notes",
default=(
"Inspection found spalling near an expansion joint with loose concrete "
"and exposed substrate. No immediate closure is in place."
),
)
parser.add_argument(
"--image",
action="append",
default=[],
help="Path to an inspection image. Can be provided multiple times.",
)
parser.add_argument(
"--video",
action="append",
default=[],
help="Path to an inspection video. Can be provided multiple times.",
)
parser.add_argument(
"--image-analyzer",
choices=["heuristic", "metadata", "openai", "roboflow"],
default="heuristic",
help="Image analyzer backend. Defaults to offline heuristic mode.",
)
parser.add_argument(
"--image-annotations",
default="data/bridge_image/annotations.csv",
help="CSV annotation path used by --image-analyzer metadata.",
)
parser.add_argument(
"--image-prompt-profile",
default=None,
help=(
"OpenAI image prompt profile. Defaults to OPENAI_IMAGE_PROMPT_PROFILE "
"or bridge_defect_v1."
),
)
parser.add_argument(
"--image-detail",
choices=["auto", "low", "high"],
default=None,
help="OpenAI image detail setting. Defaults to OPENAI_IMAGE_DETAIL or high.",
)
parser.add_argument(
"--image-tiling",
choices=["none", "grid-2x2"],
default="none",
help="Optional OpenAI image tiling mode. grid-2x2 sends full image plus quadrant crops.",
)
parser.add_argument(
"--roboflow-confidence-threshold",
type=float,
default=0.25,
help="Minimum Roboflow prediction confidence to convert into an observation.",
)
parser.add_argument(
"--roboflow-backend",
choices=["auto", "inference", "http"],
default=None,
help="Roboflow inference backend. Defaults to ROBOFLOW_BACKEND or auto.",
)
parser.add_argument(
"--roboflow-class-mapping-profile",
choices=["default", "bridge_dataset"],
default=None,
help=(
"Roboflow label normalization profile. bridge_dataset maps labels to "
"the local bridge annotation taxonomy."
),
)
parser.add_argument(
"--roboflow-tiling",
choices=["none", "grid-2x2"],
default="none",
help="Optional Roboflow crop tiling mode. grid-2x2 runs full image plus quadrant crops.",
)
parser.add_argument(
"--roboflow-class-thresholds",
default=None,
help=(
"Comma-separated per-defect thresholds, for example "
"'spalling=0.1,exposed_rebar=0.1,corrosion=0.75'."
),
)
parser.add_argument(
"--roboflow-inference-confidence",
type=float,
default=None,
help=(
"Model-level Roboflow confidence passed to the inference backend. "
"Defaults to the observation confidence threshold."
),
)
parser.add_argument(
"--roboflow-inference-iou-threshold",
type=float,
default=None,
help="Model-level Roboflow NMS IoU threshold. Defaults to 0.3.",
)
parser.add_argument(
"--vision-verifier",
choices=["none", "openai"],
default="none",
help=(
"Optional second-pass vision verifier for ambiguous detector results. "
"Use openai to verify low-confidence or crack/spalling-ambiguous images."
),
)
parser.add_argument(
"--verification-confidence-threshold",
type=float,
default=0.55,
help="Minimum verifier confidence required to add a verified image finding.",
)
parser.add_argument(
"--verifier-prompt-profile",
default=None,
help=(
"OpenAI prompt profile for --vision-verifier openai. Defaults to "
"bridge_defect_v2_strict."
),
)
parser.add_argument(
"--video-sampler",
choices=["mock", "opencv"],
default="mock",
help="Video frame sampler backend. Defaults to deterministic mock sampling.",
)
parser.add_argument(
"--video-frame-interval",
type=float,
default=4.6,
help="Seconds between sampled video frames when using OpenCV sampling.",
)
parser.add_argument(
"--video-max-frames",
type=int,
default=3,
help="Maximum number of frames to sample from each video.",
)
parser.add_argument(
"--rag-backend",
choices=["chroma", "local"],
default="chroma",
help="Knowledge retrieval backend. Defaults to LangChain Chroma.",
)
parser.add_argument(
"--embedding-backend",
choices=["fake", "openai"],
default="openai",
help="Embedding backend for Chroma RAG. Defaults to OpenAI embeddings.",
)
parser.add_argument(
"--embedding-model",
default=None,
help=(
"OpenAI embedding model. Defaults to OPENAI_EMBEDDING_MODEL "
"or text-embedding-3-small."
),
)
parser.add_argument(
"--chroma-persist-dir",
default="artifacts/chroma",
help="Persistent Chroma database directory.",
)
parser.add_argument(
"--rebuild-rag-index",
action="store_true",
help="Rebuild the persistent Chroma collection before running.",
)
parser.add_argument(
"--knowledge-corpus",
choices=["sample", "bridge", "merged"],
default="merged",
help="Knowledge corpus for RAG. Defaults to sample docs plus bridge dataset.",
)
parser.add_argument(
"--planning-mode",
choices=["deterministic", "llm"],
default="llm",
help="Maintenance planning strategy. Defaults to LLM-assisted mode.",
)
parser.add_argument(
"--scheduling-mode",
choices=["deterministic", "llm"],
default="llm",
help="Repair scheduling strategy. Defaults to LLM-assisted mode with deterministic validation.",
)
parser.add_argument(
"--schedule-context-mode",
choices=["mock", "live"],
default="mock",
help=(
"Scheduling context source. mock uses deterministic fixtures; live uses "
"OpenWeather and TomTom, plus the selected event provider."
),
)
parser.add_argument(
"--event-provider",
choices=["mock", "ticketmaster"],
default="mock",
help="City event provider for scheduling context. Defaults to deterministic mock data.",
)
parser.add_argument(
"--severity-mode",
choices=["deterministic", "llm"],
default="llm",
help="Severity rationale strategy. Deterministic rules still decide severity.",
)
parser.add_argument(
"--report-mode",
choices=["deterministic", "llm"],
default="llm",
help="Final report rendering strategy. Defaults to LLM-polished mode.",
)
parser.add_argument(
"--llm-max-retries",
type=int,
default=4,
help="Maximum LLM planning attempts before fallback or failure.",
)
parser.add_argument(
"--llm-failure-mode",
choices=["fallback", "fail"],
default="fallback",
help="How LLM planning behaves after retries are exhausted.",
)
parser.add_argument(
"--checkpoint-backend",
choices=["memory", "sqlite", "none"],
default=None,
help=(
"LangGraph checkpoint backend. Defaults to "
"LANGGRAPH_CHECKPOINT_BACKEND or memory."
),
)
parser.add_argument(
"--checkpoint-sqlite-path",
default=None,
help=(
"SQLite checkpoint database path when using --checkpoint-backend sqlite. "
"Defaults to LANGGRAPH_CHECKPOINT_SQLITE_PATH or artifacts/langgraph_checkpoints.sqlite."
),
)
parser.add_argument("--reason", default="routine")
return parser
def run_pipeline(args: argparse.Namespace) -> InspectionReport:
asset_metadata = {
key: value
for key, value in {
"latitude": args.latitude,
"longitude": args.longitude,
}.items()
if value is not None
}
return run_inspection_graph(
{
"asset_id": args.asset_id,
"asset_type": args.asset_type,
"asset_name": args.asset_name,
"location": args.location,
"criticality": args.criticality,
"asset_metadata": asset_metadata,
"notes": args.notes,
"image_paths": args.image,
"video_paths": args.video,
"reason": args.reason,
},
image_analyzer_mode=args.image_analyzer,
image_annotations_path=args.image_annotations,
image_prompt_profile=args.image_prompt_profile,
image_detail=args.image_detail,
image_tiling=args.image_tiling,
roboflow_confidence_threshold=args.roboflow_confidence_threshold,
roboflow_backend=args.roboflow_backend,
roboflow_class_mapping_profile=args.roboflow_class_mapping_profile,
roboflow_tiling=args.roboflow_tiling,
roboflow_class_thresholds=args.roboflow_class_thresholds,
roboflow_inference_confidence=args.roboflow_inference_confidence,
roboflow_inference_iou_threshold=args.roboflow_inference_iou_threshold,
vision_verifier=args.vision_verifier,
verification_confidence_threshold=args.verification_confidence_threshold,
verifier_prompt_profile=args.verifier_prompt_profile,
video_sampler_mode=args.video_sampler,
video_frame_interval_seconds=args.video_frame_interval,
video_max_frames=args.video_max_frames,
severity_mode=args.severity_mode,
planning_mode=args.planning_mode,
scheduling_mode=args.scheduling_mode,
schedule_context_mode=args.schedule_context_mode,
event_provider=args.event_provider,
report_mode=args.report_mode,
llm_max_retries=args.llm_max_retries,
llm_failure_mode=args.llm_failure_mode,
rag_backend=args.rag_backend,
embedding_backend=args.embedding_backend,
embedding_model=args.embedding_model,
chroma_persist_dir=args.chroma_persist_dir,
rebuild_rag_index=args.rebuild_rag_index,
knowledge_corpus=args.knowledge_corpus,
checkpoint_backend=args.checkpoint_backend,
checkpoint_sqlite_path=args.checkpoint_sqlite_path,
)
def main() -> None:
parser = build_parser()
report = run_pipeline(parser.parse_args())
print(report.rendered_report or ReportAgent().render(report))
if __name__ == "__main__":
main()