formatToolsPrompt method
Format tool definitions into a system prompt using C++ implementation (uses default format).
toolsJson JSON array of tool definitions
Returns formatted system prompt string
Implementation
String formatToolsPrompt(String toolsJson) {
if (toolsJson.isEmpty || toolsJson == '[]') {
return '';
}
try {
final formatFn = lib.lookupFunction<
Int32 Function(Pointer<Utf8>, Pointer<Pointer<Utf8>>),
int Function(Pointer<Utf8>, Pointer<Pointer<Utf8>>)>(
'rac_tool_call_format_prompt_json',
);
final racFreeFn = lib.lookupFunction<Void Function(Pointer<Void>),
void Function(Pointer<Void>)>('rac_free');
final toolsPtr = toolsJson.toNativeUtf8();
final promptPtrPtr = calloc<Pointer<Utf8>>();
try {
final rc = formatFn(toolsPtr, promptPtrPtr);
if (rc != RAC_SUCCESS || promptPtrPtr.value == nullptr) {
return '';
}
final result = promptPtrPtr.value.toDartString();
racFreeFn(promptPtrPtr.value.cast());
return result;
} finally {
calloc.free(toolsPtr);
calloc.free(promptPtrPtr);
}
} catch (e) {
_logger.error('formatToolsPrompt failed: $e');
return '';
}
}