iconLensAI

Goal Tracking

Define, measure, and optimize the objectives your AI agents are designed to achieve

Goal Tracking

AI agents exist to achieve specific business outcomes. A customer support agent should resolve issues. A sales assistant should qualify leads. A code generator should produce working, accepted code. Goal tracking in LensAI connects operational metrics (costs, latency, tokens) to these business outcomes, allowing you to measure whether your AI is actually accomplishing what it was designed to do.

Why Goal Tracking Matters

Without goal tracking, you only know what your AI is doing (how many requests, how much it costs, how long it takes). Goal tracking tells you whether your AI is effective—whether it's achieving the intended outcomes.

Traditional metrics tell you:

  • We processed 10,000 customer support requests this month
  • Average cost per request was $0.15
  • Average latency was 2.3 seconds

Goal tracking tells you:

  • 8,200 of those requests successfully resolved the customer's issue (82% success rate)
  • Resolved issues cost an average of $0.18
  • Unresolved issues (which still cost money) had a 0% success rate
  • Issues resolved in the first interaction cost 40% less than those requiring multiple back-and-forth exchanges

This shift from activity metrics to outcome metrics transforms how you think about AI performance and optimization.

Defining Goals

A goal represents a specific, measurable objective your agent is designed to achieve. Goals should be:

Specific: Clearly defined with objective criteria for success Measurable: Either binary (achieved or not) or quantifiable (degree of achievement) Attributed: Tied to a session, customer, or agent Business-relevant: Connected to real value delivered to users or the business

Examples of Goals

Customer Support Agent:

  • Issue resolved without escalation
  • Customer satisfaction > 4/5
  • Time to resolution < 10 minutes

Sales Assistant:

  • Lead qualified as sales-ready
  • Meeting scheduled
  • Demo completed

Code Assistant:

  • Code generated and accepted by user
  • No compilation errors
  • Passed all tests

Content Generator:

  • Content published
  • Content required < 2 revisions
  • User rated content as helpful

Onboarding Assistant:

  • User completed onboarding flow
  • All required profile fields filled
  • User activated key feature

Recording Goals

LensAI provides flexible APIs for recording goal achievement:

Binary Goal Achievement

For goals that are simply achieved or not:

await client.goals.record({
  session_id: 'session_123',
  goal: 'issue_resolved',
  achieved: true,
  metadata: {
    resolution_time_seconds: 180,
    escalated: false,
    customer_satisfaction: 5
  }
});

Quantifiable Goal Progress

For goals with degrees of achievement:

await client.goals.record({
  session_id: 'session_456',
  goal: 'lead_qualification_score',
  value: 85, // Score out of 100
  threshold: 70, // Score needed to consider goal "achieved"
  achieved: true // Automatically determined: value >= threshold
});

Multiple Goals per Session

A single session can involve multiple goals:

// During onboarding session
await client.goals.record({
  session_id: 'onboarding_789',
  goal: 'profile_completed',
  achieved: true
});

await client.goals.record({
  session_id: 'onboarding_789',
  goal: 'feature_activated',
  achieved: true
});

await client.goals.record({
  session_id: 'onboarding_789',
  goal: 'payment_method_added',
  achieved: false // User didn't complete this step
});

Time-Based Goals

Some goals are about speed or efficiency:

await client.goals.record({
  session_id: 'session_101',
  goal: 'resolved_first_contact',
  achieved: true,
  metadata: {
    interaction_count: 1,
    time_to_resolution_seconds: 95
  }
});

Goal Metrics and Analytics

Once you're tracking goals, LensAI provides rich analytics:

Goal Achievement Rate

The percentage of sessions where a specific goal was achieved:

Goal Achievement Rate = (Goals Achieved / Total Goal Attempts) × 100

Example: If 820 out of 1,000 support sessions resulted in "issue_resolved" being achieved, your achievement rate is 82%.

Track this metric over time to measure whether agent improvements are working. A declining achievement rate may indicate new edge cases, model degradation, or changes in user behavior.

Cost per Goal Achieved

The average cost of achieving a specific goal:

Cost per Goal Achieved = Total Cost (for achieved goals) / Goals Achieved

Example: If 820 support issues were resolved at a total cost of $147.60, your cost per resolved issue is $0.18.

This metric connects costs directly to outcomes. An increase in cost per goal may be acceptable if value delivered also increases, but tracking the ratio helps you optimize.

Goal Efficiency Ratio

The proportion of costs spent on successful outcomes versus wasted costs:

Goal Efficiency = Cost (achieved goals) / Total Cost

Example: If you spent $147.60 resolving 820 issues (achieved goals) and $32.40 on the 180 sessions that didn't resolve issues (failed goals), your total cost is $180.00. Your goal efficiency is 82% ($147.60 / $180.00).

A low efficiency ratio means you're spending significant resources on unsuccessful attempts. This might indicate a need to improve agent design, add pre-filtering to avoid futile attempts, or set clearer success criteria.

Time to Goal Achievement

How long it takes to achieve a goal:

Avg Time to Goal = Σ(Time to Goal Achievement) / Goals Achieved

Example: If the average time to resolve a support issue is 3.5 minutes, and you reduce this to 2.8 minutes after optimization, you've improved efficiency by 20% while maintaining the same achievement rate.

Combining Goals with Value

Goals and value are closely related but distinct concepts:

Goals measure whether you achieved an intended outcome (binary or quantifiable) Value measures the tangible benefit delivered (often in dollars)

The most powerful analyses combine both:

Value per Goal Achieved

If you track both goals and value, you can calculate the average value delivered when a goal is achieved:

Value per Goal = Total Value (achieved goals) / Goals Achieved

Example: If 820 resolved support issues delivered a total of $41,000 in value (prevented churn, time saved, etc.), the average value per resolved issue is $50.

Value-Weighted Goal Achievement

Not all goals are equally valuable. Weight your achievement rate by the value delivered:

await client.goals.record({
  session_id: 'session_202',
  goal: 'enterprise_lead_qualified',
  achieved: true,
  value: 500 // High-value enterprise lead
});

await client.goals.record({
  session_id: 'session_203',
  goal: 'smb_lead_qualified',
  achieved: true,
  value: 50 // Lower-value SMB lead
});

Now you can report not just "90% of leads qualified" but "90% of leads qualified, representing $45,000 in potential value."

Goal-Based Optimization

Goal tracking unlocks powerful optimization strategies:

A/B Testing Agent Prompts

Deploy two versions of an agent prompt and compare goal achievement:

// Variant A: Original prompt
metadata: {
  experiment: 'prompt_optimization',
  variant: 'control',
  agent: 'customer_support'
}

// Variant B: New prompt
metadata: {
  experiment: 'prompt_optimization',
  variant: 'treatment',
  agent: 'customer_support'
}

After running the experiment, compare:

  • Goal achievement rate (control vs treatment)
  • Cost per goal achieved
  • Time to goal achievement

Choose the variant with better goal metrics, not just lower costs.

Identifying Failure Patterns

Analyze sessions where goals were not achieved to find patterns:

  • Do certain customer types have lower achievement rates?
  • Are there specific edge cases where the agent consistently fails?
  • Does time of day or system load correlate with failure?

This analysis guides where to focus improvement efforts.

Early Stopping and Escalation

If a session is unlikely to achieve its goal, escalate or stop early to avoid wasting resources:

// After 3 failed attempts
if (attemptCount > 3 && !goalAchieved) {
  await client.goals.record({
    session_id: session.id,
    goal: 'issue_resolved',
    achieved: false,
    metadata: {
      escalated_to_human: true,
      attempts: attemptCount
    }
  });
  // Escalate to human support
}

By recognizing failure early, you minimize cost and improve user experience (faster escalation to someone who can help).

Model Selection Based on Goal Achievement

Route requests to different models based on goal requirements:

// For high-value goals, use premium model
if (goalValue > 100) {
  model = 'gpt-4';
} else {
  model = 'gpt-3.5-turbo';
}

Track whether the more expensive model justifies its cost with higher goal achievement rates.

Best Practices for Goal Tracking

Start with one or two critical goals. Don't try to track everything at once. Identify the most important outcome for each agent and start there.

Make goals objective and verifiable. "Issue resolved" is better than "customer seems happy." Whenever possible, use measurable criteria (customer confirmed resolution, task completed, test passed).

Track failures as well as successes. Recording when a goal is not achieved is just as important as recording success. Failure data drives optimization.

Align goals with business metrics. Goals should connect to real business outcomes (revenue, retention, efficiency) so that improving goal achievement rates has visible business impact.

Combine automatic and manual goal tracking. Some goals can be automatically detected (test passed, API call succeeded). Others require human judgment (content quality, customer satisfaction). Use both.

Iterate on goal definitions. As you learn more about how your agents operate, refine what constitutes goal achievement. Early definitions are often too simple or too strict.

Compare costs to goal value. Always evaluate whether the cost of attempting a goal is justified by the value delivered when achieved. Some goals may have low achievement rates but high value when successful.

Goal Hierarchies and Composite Goals

Complex agents may have hierarchical goals:

Top-level goal: Complete customer onboarding Sub-goals:

  • Profile information collected
  • Email verified
  • Payment method added
  • First project created
  • Invited team members

You can track each sub-goal individually and roll up to a composite "onboarding_completed" goal. This granularity helps identify exactly where users drop off and where to focus improvements.

// Track sub-goal
await client.goals.record({
  session_id: 'onboarding_xyz',
  goal: 'email_verified',
  achieved: true,
  parent_goal: 'onboarding_completed'
});

// Track composite goal when all sub-goals achieved
await client.goals.record({
  session_id: 'onboarding_xyz',
  goal: 'onboarding_completed',
  achieved: true,
  sub_goals_achieved: ['profile_collected', 'email_verified', 'payment_added', 'project_created', 'team_invited']
});

Next Steps

Now that you understand goal tracking, explore:

  • Value Modeling: Quantify the tangible benefits delivered when goals are achieved
  • Cost Attribution: Compare the cost of achieving goals to the value they deliver
  • Segmentation: Analyze goal achievement across different customer segments and agent types