From prototype to production
An agent isn't done when it gets your first example right. You want to know how often it's right before you ship it, whether it stays right in production, and whether your next change makes it better or worse.
This guide follows one agent, an invoice extractor, through that whole life. At every step it shows what you do in your own code with the Aigentic library, and what the Aigentic Platform does for you.
- 1PrototypeDoes it work at all?
- 2Ground truthWhat's the right answer?
- 3ValidateIs it good enough to ship?
- 4Go liveIs it still right in production?
- 5ImproveDid the change make it better?In your code
geminiModel { }Apply the proposal, or try another model. Its runs become the next version.
1. Prototype: does it work at all?
Start in code. Describe the task, give the agent an output type and try it on a few invoices.
@AigenticParameter
data class Invoice(
val invoiceNumber: String,
@Description("The total including VAT, null when the invoice doesn't mention it")
val total: Double?,
val lines: List<InvoiceLine>,
)
@AigenticParameter
data class InvoiceLine(val description: String, val amount: Double)
val invoiceExtractor = agent<Unit, Invoice> {
geminiModel {
apiKey(System.getenv("GEMINI_API_KEY"))
modelIdentifier(GeminiModelIdentifier.Gemini3_5Flash)
}
task("Extract the invoice fields from the document") {
addInstruction("Return null for a field the invoice doesn't mention")
}
platform {
name("invoice-extractor")
secret(System.getenv("AIGENTIC_PLATFORM_SECRET"))
}
}
The output type matters later: the platform scores each of its fields. platform { } is optional this early, but it costs one block and you'll see every run you try, with its input, tool calls and response. See Getting Started and Connect an agent.
2. Ground truth: what's the right answer?
A few examples that look right tell you little. Collect a fixed set of real inputs and the right answer for each: your ground truth. Aim for a few dozen to a hundred invoices, including the awkward ones: scans, credit notes, foreign formats. Measuring well explains how many you need.
Often the answers already exist, in your bookkeeping for example. Send them along with each run:
@Serializable
data class Labeled(val file: String, val expected: Invoice)
val groundTruth = Json.decodeFromString<List<Labeled>>(File("ground-truth/expected.json").readText())
groundTruth.forEach { (file, expected) ->
val pdf = Base64.getEncoder().encodeToString(File("ground-truth/$file").readBytes())
invoiceExtractor.start(
null,
Attachment.Base64.pdf(pdf),
expected = Expected("invoices-ground-truth", expected),
)
}
The platform puts these runs in an evaluation called invoices-ground-truth and stores your answers as its ground truth. If you don't have answers yet, pick the runs on the platform and confirm the right value per field instead. See Ground truth from your code and Evaluations.
3. Validate: is it good enough to ship?
Open the evaluation's results. You see the accuracy of every output field and every wrong value next to the right one. Decide per field what's good enough: a wrong invoice total costs more than a slightly different line description.
When a field falls short:
- Open the inputs it went wrong on and look at the run: often the document explains the mistake.
- Formatting differences, like
1.250,00against1250, aren't mistakes. Give the field a value normalizer. - Start the fix assistant. It tries changes to the task, and if needed the model or its settings, on the inputs you have ground truth for and proposes the best one with its cost per run.
Apply the change in your code and run those inputs again. Every change becomes a new config version, so you compare the two field by field. Ship when the fields you care about are where they should be.
4. Go live: is it still right in production?
Deploy the agent with the same platform { } block. Every production run is recorded with its outcome, its cost and the config version it ran on. See Runs, versions and costs.
Production inputs don't come with answers, but your process often produces them. When an employee approves or corrects an extracted invoice, send that as the expected output:
// invoice.platformRunId is the run.platformRunId you stored with the invoice
invoice.platformRunId?.let { runId ->
invoiceExtractor.addToEvaluationSet(
runId = runId,
evaluationSet = "invoices-production",
expected = approvedInvoice,
)
}
Every correction adds to the ground truth, so the accuracy of invoices-production shows how the agent does on real traffic, without anyone annotating on the platform. A run that ends Stuck comes with the agent's reason: route those to a person.
5. Improve: did the change make it better?
Sooner or later you change something: a new instruction for a supplier that keeps going wrong, a newer model, or a cheaper one.
- Change the agent in your code. Its next run creates a new config version on the platform.
- Run the new version on the inputs you have ground truth for.
- Compare it with the previous version, field by field, and look at the cost per run. Did the field you targeted improve? Did another one get worse? Does the cheaper model keep up?
If you're not sure what to change, the fix assistant tries changes on those inputs and proposes the one that scores best.
Then you're back at step 3: every version is scored against the same ground truth, so you always know whether the agent got better or worse.