package main
import (
"context"
"fmt"
"log"
"time"
chronicle "github.com/chronicle-labs/chronicle-go"
)
func main() {
if err := evaluate(); err != nil {
log.Fatal(err)
}
}
func evaluate() error {
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Minute)
defer cancel()
client := chronicle.NewClient()
examples, err := client.Worlds.Examples.List(ctx)
if err != nil { return err }
var blueprint chronicle.WorldBlueprint
found := false
for _, example := range examples.Items {
for _, task := range example.Blueprint.Scenario.Tasks {
if task.Key == "triage-duplicate-invoice" {
blueprint, found = example.Blueprint, true
break
}
}
if found { break }
}
if !found { return fmt.Errorf("the duplicate-invoice example is not available") }
preview, err := client.Worlds.Compile(ctx, chronicle.WorldCompileParams{Blueprint: blueprint})
if err != nil { return err }
if len(preview.Problems) > 0 { return fmt.Errorf("blueprint: %v", preview.Problems) }
world, err := client.Worlds.Create(ctx, chronicle.WorldCreateParams{
Blueprint: blueprint, IdempotencyKey: "demo-1",
})
if err != nil { return err }
world, err = client.Worlds.Wait(ctx, world.World.ID)
if err != nil { return err }
if world.Status != "ready" {
return fmt.Errorf("world %s: %s; %v", world.World.ID, world.Status, world.LaunchError)
}
if world.Evaluation == nil || world.Evaluation.Status != "ready" {
return fmt.Errorf("task setup is not ready for world %s; see the Worlds guide", world.World.ID)
}
run, err := client.Evaluations.Create(ctx, chronicle.EvaluationCreateParams{
TaskSuiteID: world.Evaluation.TaskSuiteID,
Agents: []string{"billing-agent@1.0.0"}, IdempotencyKey: "demo-run-1",
})
if err != nil { return err }
run, err = client.Evaluations.Wait(ctx, run.ID)
if err != nil { return err }
if run.Status != "succeeded" { return fmt.Errorf("evaluation %s: %s; inspect its trials", run.ID, run.Status) }
results, err := client.Evaluations.Results(ctx, run.ID)
if err != nil { return err }
for _, task := range results.TaskResults {
fmt.Println(task.TaskID, task.Passed, task.FailedScorers)
}
return nil
}