--- title: "JUDIAgent: a scientific coding agent for JUDI workflows in wave-equation imaging" author: - name: Haoyun Li - name: Abhinav Prakash Gahlot - name: Felix J. Herrmann abstract: | We present JUDIAgent, a scientific coding assistant for JUDI.jl, an open-source Julia framework for wave-equation-based seismic modeling, imaging, and inversion. In seismic experimentation, the practical difficulty is not only writing executable code, but assembling a complete seismic workflow with the required physical model, acquisition geometry, modeling or migration operator, and saved outputs needed for inspection. JUDIAgent addresses this problem by retrieving JUDI examples, generating Julia code, running the code in the target environment, and checking whether the generated script contains the requested workflow pieces and outputs, such as acquisition geometry and saved figures. We demonstrate the system with validated 2D forward-modeling and reverse-time migration (RTM) examples. These case studies show that, for JUDI-based seismic scripts, domain-aware validation can turn a lightweight user request into a more complete experimental workflow by detecting missing workflow steps that are not captured by runtime correctness alone and by making the resulting scripts easier to inspect and revise. bibliography: abstract.bib crossref: fig-prefix: Figure eq-prefix: Equation format: html: page-layout: full sidebar: false lightbox: true crossrefs-hover: true pdf: template: IMAGEAbstractTemplate.latex csl: apa.csl cite-method: natbib keep-tex: true pdf-engine: pdflatex execute: echo: false --- # Introduction Running a seismic experiment usually requires more than calling a single modeling or imaging operator. The user must still construct a workflow that specifies the physical model, acquisition geometry, source wavelet, operator sequence, and saved outputs needed for inspection and reruns. In this paper, those workflows are constructed in JUDI.jl, a Julia environment for wave-equation-based seismic modeling, imaging, and inversion [@witte2019judi; @herrmann2019judi], with Devito providing the underlying finite-difference wave-equation solves and stencil generation [@louboutin2019devito; @luporini2020devito]. JUDIAgent targets that workflow-construction step. Given a natural-language request, the system retrieves relevant JUDI examples and documentation, writes Julia code, runs it, and checks whether the generated script contains the workflow pieces and outputs requested in the prompt. The paper describes a domain-specific coding assistant that lowers the barrier to running seismic experiments by making JUDI-based modeling and imaging workflows easier to generate, validate, and inspect. ::: {.content-visible when-format="html"} More broadly, recent coding-agent work has shown that retrieval, tool use, and iterative repair can improve performance on software tasks [@lewis2020rag; @yao2023react; @yang2024sweagent]. We use those ideas in a geophysical setting. Here retrieval-augmented generation means that code is not produced from the prompt alone: the system first looks up relevant JUDI examples and documentation, passes that material into generation, and then uses failures from execution or workflow review to guide the next repair step. Figure 1 summarizes this loop. ::: ::: {.content-visible when-format="pdf"} More broadly, recent coding-agent work has shown that retrieval, tool use, and iterative repair can improve performance on software tasks [@lewis2020rag; @yao2023react; @yang2024sweagent]. We use those ideas in a geophysical setting. Here retrieval-augmented generation means that code is not produced from the prompt alone: the system first looks up relevant JUDI examples and documentation, passes that material into generation, and then uses failures from execution or workflow review to guide the next repair step. \hyperlink{fig-iterative-anchor}{Figure~1} summarizes this loop. ::: The implementation was developed for JUDI-based seismic workflows, but it also benefited from the broader idea that agent tooling can be paired with scientific simulators. The open-source JutulGPT project provided a reference point for agent-oriented scientific software design in another physics domain [@jutulgpt2026], while recent work on scientific workflows, benchmark design, and simulator-centered decision pipelines helped frame the evaluation [@li2024digitaltwin; @li2025seisflowbench; @stodden2014best]. The paper focuses on forward-modeling and imaging tasks in JUDI. Its main contribution is a workflow-oriented coding assistant that combines code generation with runtime checking and with task-specific review, where the validation checklist changes with the seismic task named in the prompt. # Benchmark specification The system is easiest to understand through one benchmark task and the rules that define what the generated script must contain. JUDIAgent is paired with a benchmark catalog that covers multiple seismic tasks, including forward modeling and RTM, together with task-specific workspace rules that supply defaults a user would otherwise need to state manually. One RTM prompt can therefore stay short: ```{=latex} \begin{quote}\small \texttt{Write a basic RTM example using JUDI.jl and save one RTM figure and one migrated image.} \end{quote} ``` ::: {.content-visible when-format="html"} ```text Write a basic RTM example using JUDI.jl and save one RTM figure and one migrated image. ``` ::: The short prompt is possible because the task-specific rules and prompt engineering were prepared in advance. For RTM, the benchmark rules require the generated script to distinguish the model used to generate the synthetic data from the migration-velocity model, construct Jacobian-adjoint imaging, save the requested migrated image, and follow plotting conventions taken from retrieved JUDI examples. The same rules also specify gray colormaps, the plotted spatial extent of the migrated image, symmetric clipping chosen from image magnitude, and muting used to suppress shallow and early-time acquisition artifacts. This design reduces how much domain knowledge the user must spell out while still keeping the generated experiment aligned with expert expectations. JUDIAgent retrieves JUDI examples and then returns Julia code such as: ```{=latex} \begin{quote}\small\ttfamily using JUDI, PythonPlot\\ model\_true = Model(n, d, o, m\_true)\\ model\_mig = Model(n, d, o, m\_mig)\\ xsrc = 150f0 .+ 300f0 .* (0:4); \; xrec = 0f0 .+ 12f0 .* (0:99)\\ src\_geometry = Geometry(xsrc, ysrc, zsrc; dt=dt\_src, t=t\_src); \; rec\_geometry = Geometry(xrec, yrec, zrec; dt=dt, t=tn, nsrc=nsrc)\\ F\_true = judiModeling(model\_true, src\_geometry, rec\_geometry); \; d\_obs = F\_true * q\\ F\_mig = judiModeling(model\_mig, src\_geometry, rec\_geometry); \; d\_residual = d\_obs - F\_mig * q\\ J = judiJacobian(F\_mig, q)\\ rtm\_image\_raw = reshape(adjoint(J) * d\_residual, n)\\ rtm\_image\_muted[:, 1:mute\_rows] .= 0f0 \end{quote} ``` ::: {.content-visible when-format="html"} ```julia using JUDI, PythonPlot model_true = Model(n, d, o, m_true) model_mig = Model(n, d, o, m_mig) xsrc = 150f0 .+ 300f0 .* (0:4); xrec = 0f0 .+ 12f0 .* (0:99) src_geometry = Geometry(xsrc, ysrc, zsrc; dt=dt_src, t=t_src) rec_geometry = Geometry(xrec, yrec, zrec; dt=dt, t=tn, nsrc=nsrc) F_true = judiModeling(model_true, src_geometry, rec_geometry); d_obs = F_true * q F_mig = judiModeling(model_mig, src_geometry, rec_geometry); d_residual = d_obs - F_mig * q J = judiJacobian(F_mig, q) rtm_image_raw = reshape(adjoint(J) * d_residual, n) rtm_image_muted[:, 1:mute_rows] .= 0f0 ``` ::: This example shows how the user-facing prompt stays lightweight while the benchmark rules carry much of the task specification. The RTM imaging workflow and its saved outputs are constrained before generation starts, so the produced script can be checked against task requirements rather than against runtime success alone. # Validation ::: {.content-visible when-format="html"} Validation in JUDIAgent has two layers. The first establishes whether the generated Julia script runs in the target environment. The second establishes whether the requested seismic workflow was produced. We refer to that second layer as task-specific review because its checklist changes with the seismic task named in the prompt. For forward modeling, the review checks for a model, acquisition geometry, a source wavelet, a forward operator, saved synthetic data, and saved figures. For reverse-time migration (RTM), it additionally checks for a migration-velocity model, synthetic observed data, Jacobian-adjoint imaging, and a saved migrated image [@baysal1983reverse; @virieux2009overview]. Figure 1 summarizes this loop from prompt to generated code, execution, review, and repair. ::: ::: {.content-visible when-format="pdf"} Validation in JUDIAgent has two layers. The first establishes whether the generated Julia script runs in the target environment. The second establishes whether the requested seismic workflow was produced. We refer to that second layer as task-specific review because its checklist changes with the seismic task named in the prompt. For forward modeling, the review checks for a model, acquisition geometry, a source wavelet, a forward operator, saved synthetic data, and saved figures. For reverse-time migration (RTM), it additionally checks for a migration-velocity model, synthetic observed data, Jacobian-adjoint imaging, and a saved migrated image [@baysal1983reverse; @virieux2009overview]. \hyperlink{fig-iterative-anchor}{Figure~1} summarizes this loop from prompt to generated code, execution, review, and repair. ::: The difference between these two layers matters because passing a runtime check is not the same as producing a complete seismic workflow. A script may execute but fail to save the requested data, omit the migration model, or never produce the image named in the prompt. In those cases JUDIAgent returns a concrete reason for failure and asks the model to repair the script rather than treating runtime success alone as enough. ```{=latex} \begin{figure*}[t] \centering \hypertarget{fig-iterative-anchor}{} \includegraphics[width=0.94\textwidth]{figs/paper_iterative_workflow.png} \caption{Iterative JUDIAgent validation loop. A user request is matched with retrieved JUDI examples and documentation, translated into Julia code, executed in the target environment, and then checked for task-required workflow pieces and outputs before either passing or returning repair feedback.} \label{fig-iterative} \end{figure*} ``` ::: {.content-visible when-format="html"}