Reproducible Agentic Pipelines with targets
Source:vignettes/targets_integration.Rmd
targets_integration.RmdHydraR is designed to be a building block for complex,
long-running scientific workflows. When combined with the targets package, you can
create reproducible agentic pipelines that cache expensive LLM calls and
manage complex dependencies.
The “Agent-as-Target” Pattern
The most straightforward way to integrate HydraR is to
encapsulate an AgentDAG run within a discrete target. This
ensures that the agent only runs if its inputs (data, prompts, or code)
change.
Example: Literature Synthesis Pipeline
Imagine a pipeline where we first fetch raw data, and then an agent
summarizes it. We define the agent’s logic in
targets_integration.yml.
library(targets)
library(HydraR)
# _targets.R
list(
tar_target(
raw_document,
"Highly complex scientific text about bioinformatics trends in 2026..."
),
tar_target(
agent_results,
{
# 1. Load the workflow definition from YAML
wf <- load_workflow("targets_integration.yml")
# 2. Spawn the DAG
dag <- spawn_dag(wf)
# 3. Run with data from 'raw_document'
dag$run(initial_state = list(raw_text = raw_document))
}
),
tar_target(
final_summary,
agent_results$state$get("summarizer")
)
)Benefits of Integration
1. Caching Expensive LLM Calls
LLM interactions can be costly and slow. By wrapping a
HydraR run in a target, targets will skip the
entire agentic workflow if the inputs haven’t changed, saving you tokens
and time.