Step 2 implements automated benchmarking for the tax agent using Runloop's benchmarking framework. This allows you to systematically evaluate the agent's performance across multiple test scenarios.
The step2 scripts create and run benchmarks that test the tax agent's ability to:
- Parse different W-2 formats (PDF and text)
- Extract key fields accurately
- Calculate federal taxes correctly
- Generate valid Form 1040 output
-
Complete Step 1 setup:
pnpm step1_runloop_setup
-
Set environment variables:
export RUNLOOP_API_KEY=your-runloop-api-key export OPENAI_API_KEY=your-openai-api-key
To set up and run benchmarks:
# Create scenarios and benchmark (one-time setup)
pnpm step2_setup
# Run the benchmark
pnpm step2_run_benchmarkCreates individual test scenarios for the tax agent:
pnpm step2_create_scenariosWhat it does:
- Creates 4 test scenarios covering different W-2 formats and income levels
- Each scenario includes:
- Problem statement (what the agent should do)
- Expected values for validation
- Scoring functions to evaluate success
- Environment setup (devbox with agent)
- Saves scenario IDs to
frontend/resources/step2-scenarios.json
Scenarios created:
- basic-w2-parsing: Parse a simple text W-2 (Jane Doe, $72,500)
- high-income-calculation: High-income taxpayer (Mary Jones, $125,000)
- pdf-w2-parsing: Parse a PDF W-2 (E. Darling, $44,629)
- middle-income-calculation: Middle-income taxpayer (Billy Kidd, $95,000)
Creates a benchmark from the scenarios:
pnpm step2_create_benchmarkWhat it does:
- Loads the scenarios created in step 1
- Creates a benchmark containing all scenarios
- Saves benchmark ID to
frontend/resources/step2-benchmark.json
Runs the benchmark and monitors progress:
pnpm step2_run_benchmarkWhat it does:
- Starts a benchmark run with all scenarios
- Monitors progress (polls every 5 seconds)
- Displays results for each scenario
- Calculates overall statistics:
- Total scenarios run
- Number completed
- Number passed (score > 70%)
- Average score
- Saves detailed results to
frontend/resources/benchmark-run-{id}.json
Example output:
📊 Scenario Results:
✅ tax-agent-basic-w2-parsing
Status: completed
Score: 100.0%
✅ tax-agent-high-income-calculation
Status: completed
Score: 85.5%
❌ tax-agent-pdf-w2-parsing
Status: completed
Score: 65.0%
✅ tax-agent-middle-income-calculation
Status: completed
Score: 90.0%
📈 Overall Statistics:
Total Scenarios: 4
Completed: 4/4
Passed (>70%): 3/4
Average Score: 85.1%
Each scenario is evaluated using three scoring functions:
-
output-file-exists (30% weight)
- Checks if the result.json file was created
-
valid-json-output (30% weight)
- Validates the output is well-formed JSON
-
success-flag (40% weight)
- Checks if the agent reported success in the output
A scenario passes if it achieves a score > 70%.
Contains scenario IDs and metadata:
{
"scenarioIds": ["scn_123...", "scn_456..."],
"scenarios": [
{
"name": "basic-w2-parsing",
"description": "...",
"id": "scn_123..."
}
],
"createdAt": "2024-12-16T..."
}Contains benchmark ID and configuration:
{
"benchmarkId": "bmk_123...",
"benchmarkName": "tax-agent-benchmark-...",
"scenarioIds": ["scn_123...", "scn_456..."],
"createdAt": "2024-12-16T..."
}Contains detailed results from a benchmark run:
{
"runId": "bmr_123...",
"benchmarkId": "bmk_123...",
"status": "completed",
"scenarioRuns": [...],
"statistics": {
"total": 4,
"completed": 4,
"passed": 3,
"averageScore": 0.851
},
"completedAt": "2024-12-16T..."
}To add new test scenarios, edit packages/scripts/src/step2-create-scenarios.ts:
const TAX_SCENARIOS: TaxScenario[] = [
// ... existing scenarios ...
{
name: 'your-new-scenario',
description: 'Test description',
w2File: 'your_w2.txt',
expectedValues: {
wages: 50000,
federalWithholding: 5000,
},
},
];Then re-run the setup:
pnpm step2_setupRun pnpm step2_create_scenarios first.
Run pnpm step2_create_benchmark after creating scenarios.
Make sure you've exported your Runloop API key:
export RUNLOOP_API_KEY=your-key-hereCheck the detailed results in benchmark-run-{id}.json to see which scoring functions failed. Common issues:
- Agent not creating output file
- Invalid JSON format
- Agent reporting failure in output
After running benchmarks:
- Review results in the saved JSON files
- Investigate failing scenarios
- Improve the tax agent based on findings
- Re-run benchmarks to measure improvements
The step2 scripts use the Runloop SDK's benchmarking APIs:
runloop.scenarios.create()- Create test scenariosrunloop.benchmarks.create()- Create benchmarksrunloop.benchmarks.startRun()- Run benchmarksrunloop.benchmarks.runs.retrieve()- Check run statusrunloop.benchmarks.runs.listScenarioRuns()- Get scenario results
Documentation: ~/src/api-client-ts/docs-md/@runloop/