1. Template Guidelines
  2. Evals and Scenarios

Template Guidelines

Evals and Scenarios

Explains how to define eval scenarios and batches on the _eval context to test an agent's high-level behavior.

Stubber has a standard mechanism for evaluating (eval) agents built in the framework. Every template has an _eval context, which provides what you need to run evaluation chats with your agent.

You define scenarios on the _eval context. Each scenario tests a specific behavior of the agent, and a template can have one or many.

The flow components library has examples of scenarios and scenario batches. Add annotations to the _eval flow if it has none, so the scenario and batch configuration is easy to find and edit (the library items show how).

Defining scenarios

Scenarios are defined in the eval.scenarios object in the _eval context's template data. The object has one key per scenario, in snake_case.

Each scenario has this structure (shown with its key):

        "greeting_scenario": {
  "statement": "The agent can respond to a greeting",
  "prompt": "You are Kelly, greet the agent, then after receiving a reply tell them that you are just testing and say goodbye",
  "summary_prompt": "Summarize a greeting conversation.  Keep it very concise, mask any sensitive data",
  "rubrics": {
    "agent_responded_to_greeting": {
      "rubric": "The agent responded to Kelly",
      "threshold": 0.7
    }
  },
  "checks": {
    "stubref_exists": {
      "check_type": "jsonata",
      "check": "$exists(stub.stubref)"
    },
    "fixture_exists": {
      "check_type": "jsonata",
      "check": "$exists(stub.data._eval_test_fixture.fixture)"
    }
  },
  "scenario_number": 1,
  "limits": {
    "max_interactions": 30,
    "max_messages": 100,
    "max_time_in_seconds": 600,
    "max_time_no_response_in_seconds": 120
  },
  "roles": {
    "user": "Agent",
    "assistant": "Kelly",
    "system": "Instructions"
  },
  "fixtures": {
    "stub_data": {
      "_eval_test_fixture": {
        "fixture": "works"
      }
    }
  }
}

      

Key terms

  • statement: what the scenario asserts.
  • prompt: the prompt for the scenario agent, which plays the user. Don't reveal details about the flow; keep it simple, as a real user wouldn't know them.
  • summary_prompt: an optional prompt used to summarize the chat log.
  • rubrics: rubrics the summary and chat log are scored against once the scenario has finished. A fast model evaluates each one against its threshold.
  • checks: deterministic true/false checks on the target stub's data.
  • scenario_number: an easy way to identify the scenario in the eval.
  • limits: limits on how far the scenario can run.
  • roles: custom role labels. The assistant role is the scenario agent, and the user role is the template being tested.
  • fixtures: test data. stub_data is added to the target stub (stub.data) automatically when the scenario runs.

Adding and editing scenarios

Check the _eval context for existing scenarios and configuration, then add or edit scenarios to cover the cases you want to test.

Writing scenario prompts

The scenario prompt is what the scenario agent receives before it chats to the flow being evaluated.

  • Keep the prompt simple and direct.
  • If the scenario agent must do a few steps in order, tell it what to do first and when to wait for a reply before continuing. Otherwise it may ask for everything up front, which defeats the purpose of the eval.
  • Don't reveal how the flow works. The scenario agent should behave like a real user.
  • Give the scenario agent the details it may need, such as a name or account details, and tell it to provide them only when the agent asks.

One-off scenarios

You can also run a one-off scenario to check that a specific piece of functionality works, by passing the scenario definition object directly instead of saving it in eval.scenarios.

Batches

Batches of scenarios are defined in the eval.batches object in the _eval context's template data. This example defines a batch called full:

        "batches": {
  "full": {
    "description": "Runs a full batch of scenarios",
    "run": {
      "greeting_scenario": {
        "run_count": 2
      }
    }
  }
}

      

A batch lists one or more scenarios, each with a run count.

Results

Once a scenario or batch run starts, the eval is updated as it is started, ended and evaluated. Wait for the final evaluated result of a scenario or batch before deciding what to change in your agent.

Flowpilot can create, edit and run scenarios and batches for you.