Reflection

Register the native Android reflection tool suite to inspect registered roots and optionally set values or invoke methods.

Install

Published artifact: ai.ansight:ansight-tools-reflection-android.

dependencies {
    debugImplementation("ai.ansight:ansight-tools-reflection-android:1.0.2-preview.1")
}

Register the Suite

import ai.ansight.runtime.AnsightOptions
import ai.ansight.tools.reflection.AndroidReflectionRootRegistry
import ai.ansight.tools.reflection.withReflectionTools

AndroidReflectionRootRegistry.register(
    id = "session",
    value = sessionViewModel,
    displayName = "Current Session",
)

val options = AnsightOptions.createBuilder()
    .withReflectionTools {
        allowRoot("session")
        allowTypePrefix("com.example.")
    }
    .withReadOnlyToolAccess()
    .build()

Registration API

  • AndroidReflectionRootRegistry.register(...): exposes a live object root.
  • AndroidReflectionRootRegistry.registerGetter(...): exposes a root through a getter.
  • AndroidReflectionRootRegistry.deregister(...): removes one root.
  • AndroidReflectionRootRegistry.clear(): removes all roots.
  • withReflectionTools(...): registers the reflection suite.
  • allowRoot(...) / allowTypePrefix(...): narrows reflection traversal.

Specific Concerns

  • Reflection can expose private state, model graphs, and user data.
  • Register narrow roots instead of broad application objects.
  • Set and invoke are write-scoped.

Tool Matrix

NameIdScopeDescriptionSecurity
List Reflection Rootsreflect.list_rootsReadLists registered reflection roots and availability.High
Inspect Objectreflect.inspect_objectReadReturns a snapshot of a registered live object or nested path.Critical
Describe Typereflect.describe_typeReadReturns runtime type metadata.Moderate
Set Member Valuereflect.set_member_valueWriteWrites a settable field or property reachable from a registered root.Critical
Invoke Methodreflect.invoke_methodWriteInvokes a method reachable from a registered root.Critical

Tool Details

Use read tools to inspect roots and describe types. Enable write access only when the local workflow intentionally needs mutation or invocation.

Root descriptors returned by reflect.list_roots include hostRuntime, which identifies the runtime that owns the root. Android roots report kind: "jvm" with the Android JVM/ART runtime display name, so clients can route reflection commands to the native runtime boundary instead of inferring ownership from root ids or labels.