Test parallel execution of code-only agents without shared state.
The code-only spike showed single-agent success. Now test if we can run multiple agents in parallel on subtasks.
This is the "embarrassingly parallel" case - no coordination, just partition and merge.
Parallel code-only agents can: 1. Reduce wall-clock time proportionally 2. Handle partitioned tasks correctly 3. Merge results coherently
-- Task that naturally partitions
batchTask :: [Text] -> IO [Text]
batchTask inputs = do
-- Sequential baseline
t1 <- timed $ traverse codeOnlyAgent inputs
-- Parallel (no communication)
t2 <- timed $ mapConcurrently codeOnlyAgent inputs
-- Compare times
...
-- Each agent researches independently, merge at end
parallelResearch :: [Topic] -> IO Summary
parallelResearch topics = do
-- Spawn one agent per topic
results <- mapConcurrently researchTopic topics
-- Merge (no shared state during execution)
mergeResults results
researchTopic :: Topic -> IO TopicResult
researchTopic topic = codeOnlyAgent ("Research: " <> topic)
-- Map phase: parallel
-- Reduce phase: single agent synthesizes
mapReduce :: Text -> [Text] -> IO Text
mapReduce question documents = do
-- Map: extract relevant info from each doc
extracts <- mapConcurrently (\doc ->
codeOnlyAgent ("Extract info about '" <> question <> "' from: " <> doc)) documents
-- Reduce: synthesize
codeOnlyAgent ("Synthesize these extracts: " <> show extracts)
-- Omni/Agent/Experiments/ParallelCodeOnly.hs
parallelCodeOnly :: Int -> [Text] -> IO [RunResult]
parallelCodeOnly concurrency tasks = do
-- Use async with concurrency limit
sem <- newQSem concurrency
mapConcurrently (withSem sem . codeOnlyAgent defaultConfig) tasks
withSem :: QSem -> IO a -> IO a
withSem sem = bracket_ (waitQSem sem) (signalQSem sem)
data ParallelBenchmark = ParallelBenchmark
{ pbName :: Text
, pbTasks :: [Text]
, pbExpectedSpeedup :: Double -- e.g., 5x for 5 tasks on 5 cores
}
runParallelBenchmarks :: IO ()
runParallelBenchmarks = do
-- Batch: 10 independent tasks
runBenchmark "batch" batchTasks 1 -- sequential
runBenchmark "batch" batchTasks 5 -- parallel
runBenchmark "batch" batchTasks 10 -- fully parallel
-- Research: 5 topics
runBenchmark "research" researchTasks 1
runBenchmark "research" researchTasks 5
| Metric | Sequential | Parallel (5x) | |--------|------------|---------------| | Wall time | 30s | ~6s | | Total cost | $0.00015 | $0.00015 | | Success rate | 100% | 100% |
1. Parallelism works - Agents don't interfere 2. Scaling characteristics - Linear? Sublinear? 3. Failure modes - Do parallel failures cascade? 4. Cost characteristics - Any overhead?