Agentic AI · Intermediate level

Intermediate level · Module 2: Prompt Chaining and Task Decomposition · Lesson 3 of 3

Testing and Costing Chains

Learners test each step separately and the whole chain end to end, and measure the cost and latency of each step to find where to optimise.

In this lesson you will

  • Test chains step by step and end to end
  • Measure and reduce chain cost and latency

Key concepts

unit tests per stepend-to-end testslatency per steptoken use per stepoptimisation

The lesson

Test each step with fixed inputs and scripted responses, then test the full chain on realistic questions. Step tests show where a failure starts; end-to-end tests show whether the whole result is right.

Log time and tokens per step. Often one step dominates, for example a draft prompt that includes too many documents. Reducing the evidence passed, using a smaller model for simple steps, or caching repeated lookups can cut cost substantially.

Record the before and after numbers for every optimisation, together with the effect on quality.

Step by step

  1. Write a test for each chain step.
  2. Run the end-to-end evaluation on ten questions.
  3. Produce a table of time and tokens per step.
  4. Apply one optimisation and re-measure cost and quality.

Practice activity

Produce a cost and latency profile of the chain and one measured optimisation.

Expected result: A per-step profile and an optimisation that reduces cost without lowering quality.

Check your understanding

  1. Why test steps separately?

    Show answer

    To find exactly where a failure starts.

  2. Name one way to reduce chain cost.

    Show answer

    For example pass less evidence, use a smaller model for simple steps, or cache repeated lookups.

Further learning

Taught live by an instructor — online or in person. Free course lessons are for self-study and do not lead to a certificate — see registration options.