# Collect performance data
for query in test_queries:
    interaction = await agent.process_query(query)
    # Log: query, tools called, success rate, response time
```

What to measure:

- **Success rate:** Did the agent complete the task correctly?
- **Tool call efficiency:** How many API calls were needed?
- **Response time:** How long did each interaction take?
- **Error patterns:** Which operations consistently fail?

### Step 2: Calculate the Cost-Aware Pass Rate (CAPR)

Unlike traditional success metrics, CAPR penalizes inefficient tool usage:

```python
def calculate_capr(interactions, efficiency_threshold=5):
    scores = []
    for interaction in interactions:
        success = interaction.success
        tool_calls = len(interaction.tool_calls)

        if tool_calls > efficiency_threshold:
            scores.append(0)  # Too inefficient
        else:
            efficiency = 1 - (tool_calls / efficiency_threshold)
            scores.append(success * efficiency)

    return sum(scores) / len(scores)
```

### Step 3: Apply joint optimization

The Bloomberg framework optimizes both system prompts and tool descriptions together:

```python