Software workflows · Research feature

Designing Collaborative AI-Driven Workflows for Scientific Software Engineering

A study evaluates collaborative AI workflows in translating scientific code, showing a simpler human-AI loop matches multi-agent performance at lower cost.

Adapted from research by Akash Dhruv, Max Knobbe, Pedro Machado and colleagues.

arXiv preprint revision · 2026-10-13 · Attribution & reuse
In this article
Editorial illustration of linked workflow.

Editor’s introduction

The researchers assessed AI-driven workflows for translating scientific software, specifically the MCFM high-energy physics application from Fortran to C++. They compared different orchestration patterns, including a basic author-reviewer loop and multi-agent systems, measuring completion rates and cost per file. The author-reviewer loop, with enforced limits and human review at each stage, completed a comparable number of files to the multi-agent approach at about one-third the cost. This suggests that structured, human-in-the-loop collaboration can achieve efficiency without full automation.

Introduction

Scientific software is a research instrument whose development is chronically under-resourced. A numerical code can usually only be modified safely by someone who understands the science it encodes, and such expertise is scarce. The codes are long-lived and carry decades of modifications and domain knowledge that is rarely documented in the published literature. Previous work in research software engineering has argued that investment in software practice is an investment in science, and that long-lived applications need continuous maintenance to remain correct and usable. Any substantial change to a scientific codebase, such as adding features, refactoring, porting to new hardware, or translating it to another language, is therefore necessary but limited by available developer time. Modernizing legacy code is a common example, where the aim is to preserve the encoded domain knowledge and keep the code usable.

Large language models (LLMs) are now widely used as coding assistants, and agentic tools place them inside loops in which they read files, run commands, and revise their work based on feedback. This can lower the cost of software development and maintenance, but an agent’s output is not guaranteed to be correct and its behavior over long tasks is difficult to control. Because agentic systems require human supervision, unconstrained agent behavior directly increases supervisor workload. Moreover, an agent overseen by a single person can pass an existing regression suite while introducing errors the suite misses. Such errors accumulate and make the code harder to maintain, which poses a risk to the quality and numerical correctness of scientific software.

We argue that agents are better used within a collaborative structure than in full automation, with work divided into stages that humans can easily review and verify. In the workflows we propose, domain experts write the specification and plan for each stage of the work, and agents carry out the mechanical work in bounded orchestration patterns. Each stage ends with a numerical comparison against the reference code, and only a human can record the approval that lets the next stage proceed. Building on empirical studies of the effect of AI coding assistants on developer productivity and code quality, we explicitly separate the roles of supervision, implementation, and acceptance. This keeps the human developer engaged and preserves their understanding of the code.

To test this approach, we use a computational Lab Notebook built on the practices we developed in our earlier work on reproducible computational research, which provides a controlled environment in which the same task can be repeated under equivalent conditions.

The Lab Notebook is a versioned directory tree that holds the code, configuration, and the agentic layer (specification, plan, tools, and logs) for each stage. Keeping this state in shared files rather than in a user’s private orchestrator configuration is what lets the same task be rerun under a different orchestrator for comparison. As in the experimental sciences, the Lab Notebook provides consistent record keeping and reproducibility for computational work.

Principles

P2. Humans design and accept the objectives, agents do the repetitive work. Agents are used for tasks that are broad and repetitive, such as applying a known translation rule across many files, updating build files, and checking test coverage. Humans make the decisions that require judgment, such as what counts as correct for a given routine, how to resolve a numerical disagreement, and whether to accept a result.

P3. Reproducibility and provenance. The orchestration of the agents is deterministic, but their output is not. The workflow therefore records what was done, including which files were produced, which test exercised them, and what numerical agreement was observed. This record is kept in plain text files, tool-call logs, and reasoning summaries, so that a run can be inspected, resumed, or repeated.

P4. Collaboration between roles. The work involves domain experts, who know what the code computes, and research software engineers, who know how it is built and run. Domain experts write the specification and review the results, while software engineers write and maintain the tools and workflow code that the agents use.

P5. Open and user-controlled agent execution policy. The scientists doing the work should have full access to the orchestrator’s agentic stack: system prompts, inter-agent interactions, tool definitions and protocols, model calls, shell environment behavior, and ReAct-based execution policies. With this control, workflows can be specified explicitly and reproduced reliably.

Lab Notebook

The principles above require a record kept outside any single agent or orchestrator: a place where the domain experts write the agentic layer and record approvals, which the agents can read but not modify (P2, P5), which retains what each run did (P3), and which is available to every member of the team and to every orchestrator (P4). The Lab Notebook provides this record as a single versioned directory tree shared by the team.

The directory dev/ holds the files (agentic layer) through which humans and agents work on the code, namely the transformations and the tools described below. Some orchestrators also expect their own files at a fixed location. Claude Code, for example, reads workflow scripts from.claude/workflows at the root of the tree.

The agentic work changes the code from one state to another, for example from Fortran to C++, and a project may carry several of these transformations at once. Each transformation is a directory under dev/transformations that contains a specification (desired_spec.md), a plan (current_plan.md), the agent log (agent_log.md), and the configuration files through which humans interact with the agents (approvals.toml, loop.toml). Because this state is kept on disk, a transformation can be paused, resumed, or handed to a different orchestrator or a teammate.

The tools available to an agent are the internal tools of an orchestrator, programs already available in the shell environment, and project-specific scripts under dev/tools, which operate on a file or a list of files. The latter can be a collection of scripts, tied together with a common command-line interface like dev/workflow.py in the example Lab Notebook.

Humans have write access to every file in a transformation directory, and the agent only to its log. The specification and the plan are written by humans and carry the intent and the acceptance criteria, and the approvals in approvals.toml are likewise read-only for the agents. In agent_log.md the agents record what was attempted, which checks were run, and what remains open.

Orchestration patterns

Single-agent loops are a common choice for such translation tasks. One agent runs repeatedly in short sessions and keeps all of its state on disk, a pattern known as the Ralph Loop and used by for Fortran to JAX code translation. Each iteration starts a new session and passes it a file, prompt.md, that points the agent to the shared inputs. The session reads the current state, advances the work, and exits, so state passes between iterations only through the files on disk. describes a similar practice, in which the agent records its progress in a plan file after every step. The purpose is to avoid the degradation of output quality due to growing context length.

Enforced limits. CodeScribe enforces the limits on each agent at the validation step between iterations. It caps the number of iterations and tool calls, and it rejects a tool call after repeated failures. After several consecutive failed iterations, it instructs the agent to report a blocker instead of continuing. When a tool call is rejected, CodeScribe returns an error message to the agent so it can diagnose the problem in the next iteration. Unlike limits stated in the specification or the prompt, which the model may not follow, these cannot be exceeded by the agent. This implements principle P5 and allows the loop to run unsupervised within a stage.

Implementation. CodeScribe calls the model APIs directly (e.g. Anthropic’s Messages API or OpenAI’s Chat Completions API). This gives it control over which tools the agents call and how much context each tool result adds. CodeScribe is open source and takes configurable API keys, so the same tools and plan can be run against different providers, including open-weight models. Working at the API level also gives direct control over prompt caching and reasoning. CodeScribe places explicit cache breakpoints on the system prompt, the tool schemas, and the accumulated history, so the cache written in one iteration is read in the next. The workspace context, which holds the iteration number, the remaining budgets, and recent tool results, is appended after the last breakpoint and rebuilt at every iteration, so it does not invalidate the cache. Reasoning is set per provider: on Anthropic’s API it enables adaptive thinking with summarized traces, and on an OpenAI-compatible endpoint it sets a fixed high reasoning effort. The Anthropic models used here (Opus 5 and Sonnet 5) think adaptively by default, so for them the parameter does not change how much the model reasons, only whether a summary of the reasoning is returned and recorded in the logs. Section 4 shows an example of a CodeScribe transcript and reports API call measurements.

For the multi-agent workflow, authoring is parallel and integration is serial. Many subagents translate individual files at the same time, each writing only its own output, while a single integrator subagent owns the shared build, adds the new files, and runs the verification. Authoring is routed by file complexity: the workflow inspects each file and sends ordinary files to a lighter model and large or deeply nested files to a stronger one. To profile the full transformation end to end, we run the workflow as an open-ended process across these agents, so it terminates only at the approval gate rather than after a fixed number of steps. As a result, the multi-agent workflow itself runs as a loop, with additional control flow around the agents.

The author-reviewer loop workflow in Claude Code mirrors CodeScribe, but its limits on tool usage, shell environment, agent interactions, and ReAct policies are enforced only through prompt-based guidance, and it has no control over prompt caching or model API interactions. This workflow differs from the default /loop skill in Claude Code, and placing a loop.js in.claude/workflows overrides that default behavior.

The Lab Notebook and the Design of Experiments

The transformation transformations/mcfm-translate is designed to batch-translate a group of Fortran files. Each file carries three attributes. A file is ready when every file it depends on has been translated, and it is not marked as untestable infrastructure. File-level dependencies are obtained from a Doxygen cross-reference build of the Fortran source. Its oracle status is verified, translated, or failed, as determined by the checks above. Its recorded outcome is the status the agent itself reports, which may contain hallucinations.

The agent groups ready files, typically about five that share a folder or a test, and lists each group in agent_log.md as a Markdown heading followed by a checklist of its files. Before opening a new group, an agent runs a gate script that reads these groups and the approvals in approvals.toml. The gate limits how far the agents can work ahead of human review: a new group cannot be opened while three completed groups are waiting for approval, or while a group waiting for approval contains a failed file. Work in a group that is already open may finish. Only a human writes approvals to approvals.toml (Section 2.2).

The deterministic steps, namely building the dependency map, ranking the ready files, checking a file against the oracle, and enforcing the gate, are scripts under dev/tools. Under both orchestrators, the agents run these tools through dev/workflow.py, which takes a transformation name and runs the corresponding script using Python. CodeScribe agents use the python3 executable from their allowlist, and Claude Code agents follow the directions in their prompts. The gate and the oracle are therefore the same code in every run, so the orchestrator and the pattern can be varied while everything else stays fixed.

The configurations ccworkflow and csloop differ in both orchestration pattern and base agent, so comparing them directly cannot isolate the effect of either factor on cost and performance. The third configuration, ccloop, shares its agent with ccworkflow and its pattern with csloop, so each pairwise comparison varies only one factor.

Comparing ccloop against ccworkflow holds the agent and the model fixed (Claude Code, Opus 5) and varies only the orchestration pattern. Comparing ccloop against csloop holds the pattern fixed, and varies only the base tool-calling agent and its execution policy. Together, these two comparisons let us attribute performance differences to specific layers of the agentic stack. Within csloop the orchestrator stays the same while the model changes across different families, so differences there can be attributed to the model and its API format.

Comparison across models

The runs from a different family (csloop GPT 5.6-Sol, R9–R11) show that the results carry over to a different provider. R10–R11 performed similarly per file to the Opus 5 runs at a similar token cost, though GPT 5.6-Sol used more tool calls to get there. They also picked work that closely matched what the Opus 5 runs picked (Section 4.5).

A major difference between the runs originates in a Fortran idiom in the MCFM codebase that has no direct C++ equivalent. On one file, the runs split on a design decision the agent specification never addressed. The Fortran original declared four named precision kinds.

The third Opus 5 run, and all three GPT 5.6-Sol runs, wrote a plain integer for each kind instead of a real type. One of them named the real type in a comment next to the integer it stored.

These integers are the kind values that selected_real_kind returns under gfortran on x86-64. Two GPT 5.6-Sol runs wrote the identical byte counts. The remaining run copied each kind’s own precision argument straight through (6, 15, 18, 33), as if it were the value. Either way, the result passed every test. The converted C++ code used the type keywords directly wherever a kind was needed, rather than referencing these constants, so the choice did not affect the benchmark results. However, we count this file as settled when the model made a type-preserving choice, as Opus 5 did above.

Conclusion

Scientific software is expensive to maintain and sensitive to error, and AI agents can already carry out substantial autonomous work on it. Using that capability without eroding domain understanding and correctness guarantees requires structure around the agent. We designed such a collaborative orchestration structure and compared its variants on a single task, the translation of MCFM.

In our approach, humans retain ownership of intent and acceptance, and numerical correctness is specified and enforced at an explicit verification boundary. Hallucinated progress is contained by checks that the workflow must confirm before a file counts as verified. Five design principles connect the orchestration architecture with the agentic layer to run a multi-agent workflow or a two-agent loop.

We ran fourteen versions of the same translation task, changing the orchestrator (CodeScribe vs Claude Code) and the models (Opus 5, Sonnet 5, GPT 5.6-Sol), to identify which parts of the design determined the outcome. A single author–reviewer loop matched the output of the multi-agent workflow at roughly one third of the cost per file settled. Multiple parallel agents pay off only when the work and its context are independent (Section 4.2).

The models we tested chose similar files, largely because the ranking tool used by the orchestrator determined which files were ready to translate. Tool usage was enforced through the agent execution policy (CodeScribe) or through prompt-based instructions (Claude Code), which influenced the outcome. One result was driven by an orchestrator memory note that influenced agent decision-making in three later runs without leaving a trace in our records. The oversight was ours, but a mechanism that can introduce a correct assumption across runs can introduce an incorrect one the same way.

Shared agentic layers can help teams organize their science campaigns and promote systematic use of AI to improve productivity. The author-reviewer loop can be applied to deploy simulation campaigns, run analyses, and perform work in manageable portion, which lets humans supervise AI work effectively. Several aspects of agentic layers remain open and may continue to shape their design. One is the format of the model API. The model API exposes controls for prompt caching and tool use, which account for the cache efficiency of CodeScribe (Section 4.4). Reasoning summaries, also available through the API, allow direct inspection of model reasoning and support human-AI collaboration. Exposing reasoning through an API introduces security risks, and recent work has proposed mitigations. Such work will likely influence how open-source LLMs are used and may lead to a common model API for scientific applications.