Skip to main content

Android Intelligence Service

Functions

isModelFilesDownloaded

suspend fun isModelFilesDownloaded(name: String): Result<Boolean>

Checks whether model files for the given model name already exist on the device.

Parameters:

  • name: String — Model name (Orchestrator → Managed AI Models → Programmatic name).

isModelFilesDownloaded

fun isModelFilesDownloaded(
name: String,
onSuccess: (Boolean) -> Unit,
onError: ((Throwable) -> Unit)? = null
): Unit

Checks whether model files for the given model name already exist on the device.

Parameters:

  • name: String — Model name (Orchestrator → Managed AI Models → Programmatic name).
  • onSuccess: (Boolean) -> Unit — Returns true if files exist.
  • onError: ((Throwable) -> Unit)? — Error callback.

loadModel

suspend fun loadModel(
name: String,
key: String,
modelParams: ModelParams? = null
): Result<Unit>

Loads the specified model into memory with optional parameters. Use key as the session identifier for invoke, unload, and stop.

Parameters:

  • name: String — Model name (Orchestrator → Managed AI Models → Programmatic name).
  • key: String — Session key for this load.
  • modelParams: ModelParams? — Runtime configuration.

loadModel

fun loadModel(
name: String,
key: String,
modelParams: ModelParams? = null,
onSuccess: () -> Unit,
onError: ((Throwable) -> Unit)? = null
): Unit

Loads the specified model into memory with optional parameters.

Parameters:

  • name: String — Model name (Orchestrator → Managed AI Models → Programmatic name).
  • key: String — Session key for this load.
  • modelParams: ModelParams? — Runtime configuration.
  • onSuccess: () -> Unit — Called if model loaded successfully.
  • onError: ((Throwable) -> Unit)? — Error callback.

unloadModel

suspend fun unloadModel(key: String? = null): Result<Unit>

Unloads the model for the given session key from memory.

Parameters:

  • key: String? — Session key; optional.

unloadModel

fun unloadModel(
key: String? = null,
onSuccess: () -> Unit,
onError: ((Throwable) -> Unit)? = null
): Unit

Unloads the model for the given session key from memory.

Parameters:

  • key: String? — Session key; optional.
  • onSuccess: () -> Unit — Called after unload completes.
  • onError: ((Throwable) -> Unit)? — Error callback.

downloadModelFiles

suspend fun downloadModelFiles(
name: String,
onProgress: (Double) -> Unit
): Result<Unit>

Downloads the model files for the given model name.

Parameters:

  • name: String — Model name (Orchestrator → Managed AI Models → Programmatic name).
  • onProgress: (Double) -> Unit — Progress callback (0.0–1.0).

downloadModelFiles

fun downloadModelFiles(
name: String,
onProgress: (Double) -> Unit,
onSuccess: () -> Unit,
onError: ((Throwable) -> Unit)? = null
): Unit

Downloads the model files for the given model name.

Parameters:

  • name: String — Model name (Orchestrator → Managed AI Models → Programmatic name).
  • onProgress: (Double) -> Unit — Progress callback (0.0–1.0).
  • onSuccess: () -> Unit — Called when download completes.
  • onError: ((Throwable) -> Unit)? — Error callback.

deleteModelFiles

suspend fun deleteModelFiles(name: String): Result<Unit>

Deletes all downloaded files for the given model.

Parameters:

  • name: String — Model name (Orchestrator → Managed AI Models → Programmatic name).

deleteModelFiles

fun deleteModelFiles(
name: String,
onSuccess: () -> Unit,
onError: ((Throwable) -> Unit)? = null
): Unit

Deletes all downloaded files for the given model.

Parameters:

  • name: String — Model name (Orchestrator → Managed AI Models → Programmatic name).
  • onSuccess: () -> Unit — Called when deletion completes.
  • onError: ((Throwable) -> Unit)? — Error callback.

getDownloadedModelsList

suspend fun getDownloadedModelsList(): Result<List<String>>

Returns model names whose files exist on the device.

Parameters: None.

getDownloadedModelsList

fun getDownloadedModelsList(
onSuccess: (List<String>) -> Unit,
onError: ((Throwable) -> Unit)? = null
): Unit

Returns model names whose files exist on the device.

Parameters:

  • onSuccess: (List) -> Unit — Downloaded model names.
  • onError: ((Throwable) -> Unit)? — Error callback.

getLoadedModels

suspend fun getLoadedModels(): Result<List<String>>

Returns session keys for models currently loaded in memory.

Parameters: None.

getLoadedModels

fun getLoadedModels(
onSuccess: (List<String>) -> Unit,
onError: ((Throwable) -> Unit)? = null
): Unit

Returns session keys for models currently loaded in memory.

Parameters:

  • onSuccess: (List) -> Unit — Loaded session keys.
  • onError: ((Throwable) -> Unit)? — Error callback.

isModelLoaded

suspend fun isModelLoaded(key: String): Result<Boolean>

Returns whether a model is loaded for the given session key.

Parameters:

  • key: String — Session key.

isModelLoaded

fun isModelLoaded(
key: String,
onSuccess: (Boolean) -> Unit,
onError: ((Throwable) -> Unit)? = null
): Unit

Returns whether a model is loaded for the given session key.

Parameters:

  • key: String — Session key.
  • onSuccess: (Boolean) -> Unit — True if loaded.
  • onError: ((Throwable) -> Unit)? — Error callback.

invokeModel

suspend fun invokeModel(
key: String,
prompts: List<Prompt>,
inferenceParams: InferenceParams? = null,
onStream: ((String) -> Unit)? = null
): Result<String>

Runs the model using the provided prompts and inference parameters.

Parameters:

  • key: String — Session key from loadModel.
  • prompts: List — Input messages.
  • inferenceParams: InferenceParams? — Generation settings.
  • onStream: ((String) -> Unit)? — Optional partial streamed output.

invokeModel

fun invokeModel(
key: String,
prompts: List<Prompt>,
inferenceParams: InferenceParams? = null,
onStream: ((String) -> Unit)? = null,
onSuccess: (String) -> Unit,
onError: ((Throwable) -> Unit)? = null
): Unit

Runs the model using the provided prompts and inference parameters.

Parameters:

  • key: String — Session key from loadModel.
  • prompts: List — Input messages.
  • inferenceParams: InferenceParams? — Generation settings.
  • onStream: ((String) -> Unit)? — Optional partial streamed output.
  • onSuccess: (String) -> Unit — Final model output.
  • onError: ((Throwable) -> Unit)? — Error callback.

stopModelInference

suspend fun stopModelInference(key: String): Result<Unit>

Requests cancellation of generation for the given session key.

Parameters:

  • key: String — Session key.

stopModelInference

fun stopModelInference(
key: String,
onSuccess: () -> Unit,
onError: ((Throwable) -> Unit)? = null
): Unit

Requests cancellation of generation for the given session key.

Parameters:

  • key: String — Session key.
  • onSuccess: () -> Unit — Called when the stop request is handled.
  • onError: ((Throwable) -> Unit)? — Error callback.

syncRules

suspend fun syncRules(): Result<Unit>

Synchronizes rule definitions with the Orchestrator.

Parameters: None.

syncRules

fun syncRules(
onSuccess: () -> Unit,
onError: ((Throwable) -> Unit)? = null
): Unit

Synchronizes rule definitions with the Orchestrator.

Parameters:

  • onSuccess: () -> Unit — Completed callback.
  • onError: ((Throwable) -> Unit)? — Error callback.

getRules

suspend fun getRules(): Result<List<Rule>>

Returns all stored rules.

Parameters: None.

getRules

fun getRules(
onSuccess: (List<Rule>) -> Unit,
onError: ((Throwable) -> Unit)? = null
): Unit

Returns all stored rules.

Parameters:

  • onSuccess: (List) -> Unit — Rule list.
  • onError: ((Throwable) -> Unit)? — Error callback.

getRule

suspend fun getRule(name: String): Result<Rule?>

Retrieves the Rule having given programmatic name if there is one.

Parameters:

  • name: String — The unique programmatic name of the rule to retrieve.

getRule

fun getRule(
name: String,
onSuccess: (Rule?) -> Unit,
onError: ((Throwable) -> Unit)? = null
): Rule?

Retrieves the Rule having given programmatic name if there is one.

Parameters:

  • name: String — The unique programmatic name of the rule to retrieve.
  • onSuccess: (Rule?) -> Unit — Rule or null.
  • onError: ((Throwable) -> Unit)? — Error callback.

runRule

suspend fun runRule(context: Context, name: String): Result<Rule?>

Evaluates a Rule and returns its updated state.

Parameters:

  • context: Context — Android context.
  • name: String — The unique programmatic name of the rule to evaluate.

runRule

fun runRule(
context: Context,
name: String,
onSuccess: (Rule?) -> Unit,
onError: ((Throwable) -> Unit)? = null
): Unit

Evaluates a rule and returns its updated state.

Parameters:

  • context: Context — Android context.
  • name: String — Rule name.
  • onSuccess: (Rule?) -> Unit — Resulting rule state.
  • onError: ((Throwable) -> Unit)? — Error callback.

runRules

suspend fun runRules(context: Context, onlyOnInit: Boolean): Result<List<Rule>>

Evaluates multiple rules at once.

Parameters:

  • context: Context — Android context.
  • onlyOnInit: Boolean — If true, only initialization rules run.

runRules

fun runRules(
context: Context,
onlyOnInit: Boolean,
onSuccess: (List<Rule>) -> Unit,
onError: ((Throwable) -> Unit)? = null
): Unit

Evaluates multiple rules at once.

Parameters:

  • context: Context — Android context.
  • onlyOnInit: Boolean — If true, only initialization rules run.
  • onSuccess: (List) -> Unit — Updated rules.
  • onError: ((Throwable) -> Unit)? — Error callback.

syncManagedAIModels

suspend fun syncManagedAIModels(): Result<Unit>

Synchronizes the list of managed AI models with the Orchestrator.

Parameters: None.

syncManagedAIModels

fun syncManagedAIModels(
onSuccess: () -> Unit,
onError: ((Throwable) -> Unit)? = null
): Unit

Synchronizes the list of managed AI models with the Orchestrator.

Parameters:

  • onSuccess: () -> Unit — Called when sync completes.
  • onError: ((Throwable) -> Unit)? — Error callback.

getManagedAIModels

suspend fun getManagedAIModels(): Result<List<ManagedAIModel>>

Retrieves all managed AI models stored locally.

Parameters: None.

getManagedAIModels

fun getManagedAIModels(
onSuccess: (List<ManagedAIModel>) -> Unit,
onError: ((Throwable) -> Unit)? = null
): Unit

Retrieves all managed AI models stored locally.

Parameters:

  • onSuccess: (List) -> Unit — Model list.
  • onError: ((Throwable) -> Unit)? — Error callback.

getManagedAIModel

suspend fun getManagedAIModel(name: String): Result<ManagedAIModel?>

Retrieves a specific managed AI model by name.

Parameters:

  • name: String — Model name (Orchestrator → Managed AI Models → Programmatic name).

getManagedAIModel

fun getManagedAIModel(
name: String,
onSuccess: (ManagedAIModel?) -> Unit,
onError: ((Throwable) -> Unit)? = null
): Unit

Retrieves a specific managed AI model by name.

Parameters:

  • name: String — Model name (Orchestrator → Managed AI Models → Programmatic name).
  • onSuccess: (ManagedAIModel?) -> Unit — Model or null.
  • onError: ((Throwable) -> Unit)? — Error callback.

Classes

LlamaGrammarConfig

data class LlamaGrammarConfig(
val grammar: String,
val grammarRoot: String = "root"
)

InferenceParams

data class InferenceParams(
val temperature: Float = 0.8f,
val maxTokens: Int = 10_000,
val seed: Int? = null,
val topP: Float? = 0.95f,
val topK: Int? = null,
val grammarConfig: LlamaGrammarConfig? = null,
)

ModelParams

data class ModelParams(
val nCtx: Int = 512,
val nBatchSize: Int = 64,
val nThreads: Int = Runtime.getRuntime().availableProcessors().coerceAtLeast(2),
val nGpuLayers: Int = 20
)

ManagedAIModel

data class ManagedAIModel(
val id: UUID,
val name: String,
val text: String,
val vendor: String? = null,
val description: String? = null,
val downloadUrl: String,
var imageUrl: String? = null,
val multimodal: Boolean? = false,
val mmProjDownloadUrl: String? = null
)

Rule

class Rule(
val id: String,
val name: String,
val text: String,
val description: String? = null,
val trigger: String,
val conditionJson: String,
val actionJson: String
)

Action

class Action(
val type: String,
val config: ActionConfig? = null
)

ActionConfig

data class ActionConfig(
val id: String,
val script: Script?,
val event: String?,
val title: String?,
val message: String?
)

Criteria

class Criteria(
val field: String,
val criteriaOperator: String,
val value: String
)

Filter

class Filter(
val type: String?,
val filters: List<Filter>?,
val filter: Filter?,
val criteria: Criteria?
)

Prompt

data class Prompt(
val role: Role,
val content: String,
val attachment: String? = null
)