is_model_vocabulary
The words a call to a language model is described in: the tools it is
offered and the calls it proposes, the turns of the conversation, what it
replies and spends, how hard it is asked to work, and why it stopped. No
provider's JSON, and no dart:io. It depends only on checked_json.
The model only ever proposes a call. A driver returns the proposal, and the caller runs the action (after the airlock decides) and sends the result back as a turn. No driver runs a tool.
import 'package:is_model_vocabulary/is_model_vocabulary.dart';
void main() {
final effort = Effort.parse('xhigh');
print(effort?.rank); // 3: its place among the levels this code knows
print(StopReason.parse('tool_use').continuesLoop); // true
}
What it has
ToolName: the name a tool is offered under, 1 to 64 ofa-zA-Z0-9_-, the rule both the Messages API and the Responses API impose. Made withToolName.offor a name written in code, orToolName.parse, which returns null for a name that breaks it.OfferedTool: a tool as the model is shown it, itsname,descriptionandinputSchema.ToolCall: one call the model proposed, with itsToolCallId(the provider's id, echoed back, so parsed loosely), aCalledToolNameand itsToolInput. The name isWellFormedNameorIllFormedName, never refused: a model can call a tool it wasn't offered, and the caller answers that like any other unknown name. The input is the JSON text the driver encoded once, passed on byte for byte.ModelTurn:UserSaid,AgentSaid,AgentCalledTools(at least one call, with an optionalProviderContinuation) orToolAnswered, whoseToolResultisToolRan,ToolFailedorToolRefused.ToolRefusedmeans nothing ran.ModelRequest: thetoolsoffered and theturnsso far, encoded to therequesttext the airlock hashes. Equal requests encode to equal bytes, so a replay matches.ModelReply:FinishedReply,CutOffReply, orProposedToolCalls(the model stopped to have tools run), each with itsModelUsage.ProviderContinuation: provider items a call must be followed by, such as encrypted reasoning, echoed back unchanged. It is the one part of a request nobody but the provider can read: the airlock's hash keeps it intact, but an audit of what was sent can't read what it says.
Every fromJson is strict: a key it doesn't expect is refused and named.
Effort: how hard a model is asked to work. Open, because providers add levels;Effort.knownholds the ones this code knows, lowest first.ModelEfforts: the levels one model takes, and the one it works at when a request names none.StopReason: why the model stopped, a closed set with an explicitunknown, so a reason a provider adds later makes every switch say what to do with it.
What a provider's JSON calls each of these, and how a request carries an effort level, is the provider's client's to say, not this package's.
License
Apache-2.0.
Libraries
- is_model_vocabulary
- The words a call to a language model is described in: the tools it is offered and the calls it proposes, the turns of the conversation, what it replies and spends, how hard it is asked to work, and why it stopped.