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
| Name | Id | Scope | Description | Security |
|---|---|---|---|---|
List Reflection Roots | reflect.list_roots | Read | Lists registered reflection roots and availability. | High |
Inspect Object | reflect.inspect_object | Read | Returns a snapshot of a registered live object or nested path. | Critical |
Describe Type | reflect.describe_type | Read | Returns runtime type metadata. | Moderate |
Set Member Value | reflect.set_member_value | Write | Writes a settable field or property reachable from a registered root. | Critical |
Invoke Method | reflect.invoke_method | Write | Invokes 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.