Ch 7 — Sampling & Elicitation Under the Hood
Wire formats, model preferences, includeContext, elicitation schemas, capability negotiation
Under the Hood
-
Click play or press Space to begin...
ASampling Request Wire FormatThe full createMessage request structure
1send
createMessagemessages, model
prefs, maxTokens
params
2tune
modelPreferenceshints, cost, speed,
intelligence priority
3arrow_downward includeContext: requesting conversation history
BincludeContextServer can request the host include conversation context
history
noneOnly server's
messages sent
or
chat_bubble
thisServerInclude context
from this server
or
forum
allServersInclude full
conversation
4arrow_downward Sampling response: what comes back
CSampling ResponseThe result returned to the server
psychology
LLM GeneratesHost sends to LLM
gets completion
returns
chat
Responserole, content,
model used
includes
5stop_circle
stopReasonendTurn, maxTokens,
or stopSequence
6arrow_downward Elicitation request: JSON Schema for user input
DElicitation RequestDefining what the server needs from the user
send
elicitation/createmessage +
requestedSchema
schema
schema
JSON Schemastring, number,
boolean, enum
response
7task_alt
Action + Contentaccept, decline,
or dismiss
8arrow_downward Capability negotiation for sampling and elicitation
ECapability NegotiationBoth sides must opt in during initialization
dns
Server DeclaresI need sampling
and/or elicitation
handshake
hub
Host DeclaresI support sampling
and/or elicitation
result
9handshake
AgreedBoth sides know
what's available
10arrow_downward Agentic loop: combining sampling with tools
FAgentic Loop PatternServer drives a multi-step workflow using sampling + tools
psychology
SampleAsk LLM to
analyze / decide
act
build
ExecuteServer acts on
LLM's response
loop
loop
RepeatUntil task
is complete