Consolidate grounded event extraction instructions
This commit is contained in:
@@ -18,7 +18,6 @@ var promptAssetManifest = shared.PromptAssetManifest{
|
||||
ModuleFiles: []promptfs.ModulePromptFile{
|
||||
{Name: "prompt.yaml", Path: "prompts/prompt.yaml"},
|
||||
{Name: "combat-grounding.md", Path: "prompts/combat-grounding.md"},
|
||||
{Name: "task.md", Path: "prompts/task.md"},
|
||||
{Name: "instructions.md", Path: "prompts/instructions.md"},
|
||||
},
|
||||
SharedFiles: []string{
|
||||
|
||||
@@ -28,21 +28,32 @@ func TestRegisterPromptAssetsAndPrepareEnemyEventPrompt(t *testing.T) {
|
||||
if prepared.PromptID != PromptID || prepared.OutputContract.SchemaPath != "dnd_enemy_events_llm.v1.json" || prepared.SelectedProfileID != "dnd-extraction" {
|
||||
t.Fatalf("prepared prompt = %#v", prepared)
|
||||
}
|
||||
referenceIndex := renderedMessageIndex(t, prepared.Messages, "enemy-player")
|
||||
transcriptIndex := renderedMessageIndex(t, prepared.Messages, "enemy-transcript")
|
||||
for _, sentinel := range []string{"enemy-npc", "enemy-turn", "enemy-opponent", "Extract Dungeons & Dragons enemy events"} {
|
||||
if transcriptIndex <= referenceIndex {
|
||||
t.Fatalf("transcript message index = %d, want after references index %d", transcriptIndex, referenceIndex)
|
||||
}
|
||||
groundingIndices := make([]int, 0, 3)
|
||||
for _, sentinel := range []string{"enemy-npc", "enemy-turn", "enemy-opponent"} {
|
||||
if index := renderedMessageIndex(t, prepared.Messages, sentinel); index <= transcriptIndex {
|
||||
t.Fatalf("message containing %q has index %d, want after transcript index %d", sentinel, index, transcriptIndex)
|
||||
} else {
|
||||
groundingIndices = append(groundingIndices, index)
|
||||
}
|
||||
}
|
||||
instructionIndex := renderedMessageIndex(t, prepared.Messages, "Return the `events` array")
|
||||
if instructionIndex <= transcriptIndex {
|
||||
t.Fatalf("instruction index = %d, want after transcript index %d", instructionIndex, transcriptIndex)
|
||||
instructionIndex := renderedMessageIndex(t, prepared.Messages, "Extract Dungeons & Dragons enemy events")
|
||||
for _, index := range groundingIndices {
|
||||
if instructionIndex <= index {
|
||||
t.Fatalf("instruction index = %d, want after grounding index %d", instructionIndex, index)
|
||||
}
|
||||
}
|
||||
if instructionIndex != len(prepared.Messages)-1 {
|
||||
t.Fatalf("instruction message index = %d, want final message", instructionIndex)
|
||||
}
|
||||
if cache := prepared.Messages[instructionIndex].CacheControl; cache == nil || cache.Type != promptkit.CacheControlEphemeral {
|
||||
t.Fatalf("final instruction cache control = %#v", cache)
|
||||
for _, index := range []int{referenceIndex, transcriptIndex, instructionIndex} {
|
||||
if cache := prepared.Messages[index].CacheControl; cache == nil || cache.Type != promptkit.CacheControlEphemeral {
|
||||
t.Fatalf("message %d cache control = %#v, want ephemeral", index, cache)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,6 @@ var promptAssetManifest = shared.PromptAssetManifest{
|
||||
ModuleFiles: []promptfs.ModulePromptFile{
|
||||
{Name: "prompt.yaml", Path: "prompts/prompt.yaml"},
|
||||
{Name: "location-registry.md", Path: "prompts/location-registry.md"},
|
||||
{Name: "task.md", Path: "prompts/task.md"},
|
||||
{Name: "instructions.md", Path: "prompts/instructions.md"},
|
||||
},
|
||||
SharedFiles: []string{
|
||||
|
||||
@@ -29,8 +29,8 @@ func TestRegisterPromptAssetsPreparesLocationOccurrencePrompt(t *testing.T) {
|
||||
prepared, err := engine.Prepare(context.Background(), promptkit.RunRequest{
|
||||
PromptID: PromptID, PromptVersion: SchemaVersion, ProfileID: "location-occurrences-test",
|
||||
Inputs: map[string]promptkit.ArtifactRef{
|
||||
"transcript": promptkit.Inline(`{"units":[1]}`), "players": promptkit.Inline(" "), "party": promptkit.Inline(" "), "glossary": promptkit.Inline(" "),
|
||||
"locations": promptkit.Inline(`{"locations":[{"id":"location:sha256:test","name":"The Mill"}]}`),
|
||||
"transcript": promptkit.Inline(`{"units":[{"sentinel":"location-occurrence-transcript"}]}`), "players": promptkit.Inline("location-occurrence-player"), "party": promptkit.Inline(" "), "glossary": promptkit.Inline(" "),
|
||||
"locations": promptkit.Inline(`{"locations":[{"id":"location:sha256:test","name":"location-occurrence-registry"}]}`),
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
@@ -40,10 +40,17 @@ func TestRegisterPromptAssetsPreparesLocationOccurrencePrompt(t *testing.T) {
|
||||
t.Fatalf("prepared prompt = %#v", prepared)
|
||||
}
|
||||
var registryMessage string
|
||||
referenceIndex := -1
|
||||
transcriptIndex := -1
|
||||
registryIndex := -1
|
||||
evidenceIndex := -1
|
||||
taskIndex := -1
|
||||
for index, message := range prepared.Messages {
|
||||
if strings.Contains(message.Content, "location-occurrence-player") {
|
||||
referenceIndex = index
|
||||
}
|
||||
if strings.Contains(message.Content, "location-occurrence-transcript") {
|
||||
transcriptIndex = index
|
||||
}
|
||||
if strings.Contains(message.Content, "normalized location registry") {
|
||||
registryMessage = message.Content
|
||||
registryIndex = index
|
||||
@@ -51,14 +58,28 @@ func TestRegisterPromptAssetsPreparesLocationOccurrencePrompt(t *testing.T) {
|
||||
if strings.Contains(message.Content, "Transcript units are the only evidence") {
|
||||
evidenceIndex = index
|
||||
}
|
||||
if strings.Contains(message.Content, "Extract Dungeons & Dragons location occurrences") {
|
||||
taskIndex = index
|
||||
}
|
||||
}
|
||||
if !strings.Contains(registryMessage, "location:sha256:test") || !strings.Contains(registryMessage, "The Mill") || strings.Contains(registryMessage, "source_refs") {
|
||||
if !strings.Contains(registryMessage, "location:sha256:test") || !strings.Contains(registryMessage, "location-occurrence-registry") || strings.Contains(registryMessage, "source_refs") {
|
||||
t.Fatalf("rendered prompt did not preserve source-free registry grounding: %s", registryMessage)
|
||||
}
|
||||
if evidenceIndex < 0 || taskIndex < 0 || registryIndex <= evidenceIndex || registryIndex >= taskIndex {
|
||||
t.Fatalf("registry prompt placement = evidence %d, registry %d, task %d", evidenceIndex, registryIndex, taskIndex)
|
||||
instructionsIndex := len(prepared.Messages) - 1
|
||||
if referenceIndex < 0 || transcriptIndex <= referenceIndex || evidenceIndex <= transcriptIndex || registryIndex <= evidenceIndex || instructionsIndex <= registryIndex {
|
||||
t.Fatalf("message order = references %d, transcript %d, evidence %d, registry %d, instructions %d; want that order", referenceIndex, transcriptIndex, evidenceIndex, registryIndex, instructionsIndex)
|
||||
}
|
||||
for _, index := range []int{referenceIndex, transcriptIndex, instructionsIndex} {
|
||||
if cache := prepared.Messages[index].CacheControl; cache == nil || cache.Type != promptkit.CacheControlEphemeral {
|
||||
t.Fatalf("message %d cache control = %#v, want ephemeral", index, cache)
|
||||
}
|
||||
}
|
||||
for index, message := range prepared.Messages {
|
||||
if index != referenceIndex && strings.Contains(message.Content, "location-occurrence-player") {
|
||||
t.Errorf("message %d unexpectedly rendered campaign-reference input", index)
|
||||
}
|
||||
if index != transcriptIndex && strings.Contains(message.Content, "location-occurrence-transcript") {
|
||||
t.Errorf("message %d unexpectedly rendered transcript input", index)
|
||||
}
|
||||
if index != registryIndex && strings.Contains(message.Content, "location-occurrence-registry") {
|
||||
t.Errorf("message %d unexpectedly rendered registry grounding input", index)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@ var promptAssetManifest = shared.PromptAssetManifest{
|
||||
ModuleDir: "dnd.npc_interactions",
|
||||
ModuleFiles: []promptfs.ModulePromptFile{
|
||||
{Name: "prompt.yaml", Path: "prompts/prompt.yaml"},
|
||||
{Name: "task.md", Path: "prompts/task.md"},
|
||||
{Name: "instructions.md", Path: "prompts/instructions.md"},
|
||||
},
|
||||
SharedFiles: []string{
|
||||
|
||||
@@ -34,15 +34,15 @@ func TestRegisterPromptAssetsAndPrepareInteractionPrompt(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
transcript := `{"units":[1]}`
|
||||
transcript := `{"units":[{"sentinel":"interaction-transcript"}]}`
|
||||
prepared, err := engine.Prepare(context.Background(), promptkit.RunRequest{
|
||||
PromptID: PromptID, PromptVersion: SchemaVersion, ProfileID: "npc-interactions-test-profile",
|
||||
Inputs: map[string]promptkit.ArtifactRef{
|
||||
"transcript": promptkit.InlineWithURI("file:///session.json", transcript),
|
||||
"players": promptkit.Inline("Dana: Mira"),
|
||||
"players": promptkit.Inline("interaction-player"),
|
||||
"party": promptkit.Inline("Mira: ranger"),
|
||||
"glossary": promptkit.Inline("Greencloak: title"),
|
||||
"npcs": promptkit.Inline(`{"npcs":[{"name":"Mira Thorn"}]}`),
|
||||
"npcs": promptkit.Inline(`{"npcs":[{"name":"interaction-npc"}]}`),
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
@@ -51,6 +51,43 @@ func TestRegisterPromptAssetsAndPrepareInteractionPrompt(t *testing.T) {
|
||||
if prepared.PromptID != PromptID || prepared.OutputContract.SchemaPath != "dnd_npc_interactions_llm.v1.json" {
|
||||
t.Fatalf("prepared prompt = %#v", prepared)
|
||||
}
|
||||
if len(prepared.Messages) < 6 {
|
||||
t.Fatalf("prepared messages = %#v, want shared context, NPC grounding, and instructions", prepared.Messages)
|
||||
}
|
||||
referenceIndex := -1
|
||||
transcriptIndex := -1
|
||||
npcIndex := -1
|
||||
for index, message := range prepared.Messages {
|
||||
if strings.Contains(message.Content, "interaction-player") {
|
||||
referenceIndex = index
|
||||
}
|
||||
if strings.Contains(message.Content, "interaction-transcript") {
|
||||
transcriptIndex = index
|
||||
}
|
||||
if strings.Contains(message.Content, "interaction-npc") {
|
||||
npcIndex = index
|
||||
}
|
||||
}
|
||||
instructionsIndex := len(prepared.Messages) - 1
|
||||
if referenceIndex < 0 || transcriptIndex <= referenceIndex || npcIndex <= transcriptIndex || instructionsIndex <= npcIndex {
|
||||
t.Fatalf("message order = references %d, transcript %d, NPCs %d, instructions %d; want that order", referenceIndex, transcriptIndex, npcIndex, instructionsIndex)
|
||||
}
|
||||
for _, index := range []int{referenceIndex, transcriptIndex, instructionsIndex} {
|
||||
if cache := prepared.Messages[index].CacheControl; cache == nil || cache.Type != promptkit.CacheControlEphemeral {
|
||||
t.Fatalf("message %d cache control = %#v, want ephemeral", index, cache)
|
||||
}
|
||||
}
|
||||
for index, message := range prepared.Messages {
|
||||
if index != referenceIndex && strings.Contains(message.Content, "interaction-player") {
|
||||
t.Errorf("message %d unexpectedly rendered campaign-reference input", index)
|
||||
}
|
||||
if index != transcriptIndex && strings.Contains(message.Content, "interaction-transcript") {
|
||||
t.Errorf("message %d unexpectedly rendered transcript input", index)
|
||||
}
|
||||
if index != npcIndex && strings.Contains(message.Content, "interaction-npc") {
|
||||
t.Errorf("message %d unexpectedly rendered NPC grounding input", index)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestPromptMetadataDoesNotExposeAssetContent(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user