How Pinterest Improved Analytics Agent Compliance with Loop Engineering
Pinterest’s Analytics Agent, designed to answer data-related questions, faces a compliance problem: ensuring it follows the correct steps at the appropriate times. Compliance means the agent identifies and executes relevant steps for each query, such as utilizing data-discovery skills or inspecting table metadata. However, the agent's flexibility in handling diverse questions makes compliance challenging, as skipping crucial steps can lead to inaccurate or incomplete results. Manually revising the agent's instructions proved insufficient, often leading to unpredictable model interpretations and new regressions. For instance, a guardrail intended to limit the agent's scope incorrectly led it to decline valid data-related questions.To address these issues, a repeatable process called loop engineering was developed, beginning with an evaluation framework. This framework includes paired test suites for each compliance rule and a larger regression suite to protect existing functionality. Each rule has a "required" suite for cases where the rule applies and a "skip" suite for when it doesn't, ensuring balanced testing. The tuning loop itself uses a "fresh context with structured memory" approach, where each iteration starts with a compact handoff of crucial information without retaining full conversation history.This structured memory includes current results, failing cases, the best changes so far, and approaches to avoid repeating mistakes. The tuning loop drafts and evaluates up to four changes, selects the highest-scoring candidate, and then evaluates it on full tuning and validation suites. Critical "repair/break," "acceptance critic," and "regression guard" checks ensure changes fix more cases than they break, address general patterns, and do not degrade overall performance. The loop also imposes limits on the scope and size of changes to prevent overfitting and ensure targeted improvements. Early runs revealed that overall score improvements could hide individual case variations, highlighting the need to learn from specific cases rather than just aggregated scores.