AgentListing.of constructor
AgentListing.of(
- AgentSurface surface
Reads surface's agent list, through the copy in its generated
AgentSurface.agentSchema when it has one, and names its items.
Throws a StateError when the list names a getter or a method the
generated code does not know; in debug an assert also compares the copy
with AgentSurface.agentCapabilities. Either means the code was not
generated again after the list changed. Also throws one for a method
whose tool starts with tandem_, which names Tandem's own tools.
Implementation
factory of(AgentSurface surface) {
final schema = surface.agentSchema;
final capabilities = _read(surface, schema);
final seen = _pairViews(capabilities, schema);
final tools = <String, AgentTool>{};
for (final item in capabilities) {
if (item case _Calls(:final method)) {
final tool = schema.calls.firstWhere(
(tool) => tool.method == method,
orElse: () => throw StateError(
'The generated code does not know a method of the agent list. '
'Run build_runner again.',
),
);
if (tool.name.startsWith('tandem_')) {
throw StateError(
'The agent list calls ${tool.name}, but tandem_ starts only the '
"names of Tandem's own tools. Rename the method.",
);
}
if (tools.containsKey(tool.name)) {
throw StateError('The agent list has ${tool.name} twice.');
}
tools[tool.name] = tool;
}
}
return ._(surface, capabilities, seen, tools);
}