MCPcopy
hub / github.com/docker/docker-agent / TestRunLLM_ModelSelection

Function TestRunLLM_ModelSelection

pkg/runtime/compactor/compactor_test.go:472–518  ·  view source on GitHub ↗

TestRunLLM_ModelSelection pins that the summary is generated by the dedicated compaction model when one is configured on the agent, and falls back to the agent's own model otherwise (issue #3241).

(t *testing.T)

Source from the content-addressed store, hash-verified

470// dedicated compaction model when one is configured on the agent, and falls
471// back to the agent's own model otherwise (issue #3241).
472func TestRunLLM_ModelSelection(t *testing.T) {
473 t.Parallel()
474
475 newSession := func() *session.Session {
476 return session.New(session.WithMessages([]session.Item{
477 session.NewMessageItem(&session.Message{Message: chat.Message{Role: chat.MessageRoleUser, Content: "please summarize"}}),
478 }))
479 }
480
481 run := func(t *testing.T, a *agent.Agent) string {
482 t.Helper()
483 var summaryModelID string
484 result, err := RunLLM(t.Context(), LLMArgs{
485 Session: newSession(),
486 Agent: a,
487 ContextLimit: 100_000,
488 RunAgent: func(ctx context.Context, compactionAgent *agent.Agent, cs *session.Session) error {
489 summaryModelID = compactionAgent.Model(ctx).ID().String()
490 cs.AddMessage(session.NewAgentMessage("root", &chat.Message{
491 Role: chat.MessageRoleAssistant,
492 Content: "the summary",
493 }))
494 return nil
495 },
496 })
497 require.NoError(t, err)
498 require.NotNil(t, result)
499 return summaryModelID
500 }
501
502 t.Run("uses dedicated compaction model", func(t *testing.T) {
503 t.Parallel()
504 a := agent.New("root", "instr",
505 agent.WithModel(fakeProvider{id: modelsdev.NewID("primary", "big")}),
506 agent.WithCompactionModel(fakeProvider{id: modelsdev.NewID("compaction", "small")}),
507 )
508 assert.Equal(t, "compaction/small", run(t, a))
509 })
510
511 t.Run("falls back to agent's own model", func(t *testing.T) {
512 t.Parallel()
513 a := agent.New("root", "instr",
514 agent.WithModel(fakeProvider{id: modelsdev.NewID("primary", "big")}),
515 )
516 assert.Equal(t, "primary/big", run(t, a))
517 })
518}
519
520// TestRunLLM_RequiresRunAgent pins the contract that a missing RunAgent
521// callback is rejected loudly rather than silently no-oping.

Callers

nothing calls this directly

Calls 15

NewFunction · 0.92
WithMessagesFunction · 0.92
NewMessageItemFunction · 0.92
NewAgentMessageFunction · 0.92
NewFunction · 0.92
WithModelFunction · 0.92
NewIDFunction · 0.92
WithCompactionModelFunction · 0.92
RunLLMFunction · 0.85
newSessionFunction · 0.85
ContextMethod · 0.80
ModelMethod · 0.80

Tested by

no test coverage detected