lookup method
Resolves the product stored under the id argument.
Implementation
AgentToolResult lookup({required Map<String, Object?> args}) {
final decoded = ToolIngress.validate(args, ProductLookupIntent.fromWire);
return decoded.fold((intent) {
// `limit` is the maximum fact count; a non-positive limit asks for no
// facts, so an existing product still yields an empty answer rather than
// the one fact its id resolves to.
final limit = intent.limit;
if (limit != null && limit <= 0) {
return const AgentToolResult.empty();
}
final document = store.get<T>(intent.id);
if (document == null) return const AgentToolResult.empty();
return AgentToolResult(
ok: true,
facts: <AgentFact>[
_factOf(registry.resolve<T>(), document.key, document.value),
],
);
}, (error) => AgentToolResult.rejected(ToolIngress.feedback(error)));
}