feat(agent): choose the reasoning effort in the Agent tab (#2507)

* feat(agent): choose the reasoning effort in the Agent tab; agent processes survive Steam session cleanup; sdkmanager license step tolerates SIGPIPE

* docs(agent): on-device build and commit pitfalls for the agent
This commit is contained in:
Kurt Himebauch authored and GitHub committed 2026-11-12 10:23:38 -05:00
1 parent c8dec0a8bc
commit 3b1366f85c
6 files changed
+41 -4

No files matched your search

@@ -21,6 +21,8 @@ interface AgentHarness {
val signIn: List<String>
/** Whether [Options.plan] means anything to this CLI. */
val plans: Boolean
/** Reasoning effort levels the CLI accepts, lowest first; empty when it has none. */
val efforts: List<String>
/** Models to offer besides the CLI's default; [rootfs] is where the CLI's own files can be read. */
fun models(rootfs: File): List<Model>
/** The guest command for one turn; [conversation] is null for the first one. */
@@ -32,7 +34,7 @@ interface AgentHarness {
data class Model(val id: String, val label: String)
data class Options(val model: String? = null, val plan: Boolean = false, val brief: String? = null)
data class Options(val model: String? = null, val plan: Boolean = false, val brief: String? = null, val effort: String? = null)
companion object {
val all: List<AgentHarness> = listOf(ClaudeCode, Codex)
@@ -60,6 +62,7 @@ object ClaudeCode : AgentHarness {
override val signedIn = listOf("sh", "-c", "$binary auth status | grep -q '\"loggedIn\": true'")
override val signIn = listOf(binary, "auth", "login", "--claudeai")
override val plans = true
override val efforts = listOf("low", "medium", "high", "xhigh", "max")
/**
* Commits and pull requests the agent makes carry no Claude Code credit or co-author line by
@@ -92,6 +95,7 @@ object ClaudeCode : AgentHarness {
addAll(listOf(binary, "-p", message, "--output-format", "stream-json", "--verbose", "--include-partial-messages"))
addAll(listOf("--permission-mode", if (options.plan) "plan" else "bypassPermissions"))
options.model?.let { addAll(listOf("--model", it)) }
options.effort?.let { addAll(listOf("--effort", it)) }
options.brief?.let { addAll(listOf("--append-system-prompt", it)) }
if (conversation != null) addAll(listOf("--resume", conversation))
}
@@ -212,6 +216,7 @@ object Codex : AgentHarness {
override val signedIn = listOf(binary, "login", "status")
override val signIn = listOf(binary, "login")
override val plans = false
override val efforts = listOf("low", "medium", "high")
/** Codex keeps the models its account can use in `~/.codex/models_cache.json` once it has run. */
override fun models(rootfs: File): List<AgentHarness.Model> = runCatching {
@@ -231,6 +236,7 @@ object Codex : AgentHarness {
if (conversation != null) addAll(listOf("resume", conversation))
addAll(listOf("--json", "--dangerously-bypass-approvals-and-sandbox", "--skip-git-repo-check"))
options.model?.let { addAll(listOf("-m", it)) }
options.effort?.let { addAll(listOf("-c", "model_reasoning_effort=\"$it\"")) }
// codex exec has no system prompt option, so a new conversation starts with the brief.
add(if (conversation == null && options.brief != null) "${options.brief}\n\n$message" else message)
}
@@ -78,6 +78,9 @@ object AgentHost {
/** The chosen model for [harness]; null is the CLI's default. */
var model by mutableStateOf<String?>(null)
private set
/** The chosen reasoning effort for [harness]; null is the CLI's default. */
var effort by mutableStateOf<String?>(null)
private set
var plan by mutableStateOf(false)
private set
var chat by mutableStateOf<String?>(null)
@@ -131,6 +134,7 @@ object AgentHost {
File(app.filesDir, "agent").mkdirs()
harness = AgentHarness.byId(prefs(app).getString(HARNESS_KEY, null))
model = prefs(app).getString(modelKey(harness), null)
effort = prefs(app).getString(effortKey(harness), null)?.takeIf { it in harness.efforts }
plan = prefs(app).getBoolean(PLAN_KEY, false)
available = LinuxRuntime.hasRootfs(app)
installed = harness.files.all { guestFileExists(app, it) }
@@ -220,6 +224,11 @@ object AgentHost {
prefs(context).edit().putString(modelKey(harness), id).apply()
}
fun chooseEffort(context: Context, level: String?) {
effort = level
prefs(context).edit().putString(effortKey(harness), level).apply()
}
fun choosePlan(context: Context, on: Boolean) {
plan = on
prefs(context).edit().putBoolean(PLAN_KEY, on).apply()
@@ -254,7 +263,7 @@ object AgentHost {
AgentHostService.start(app)
val current = harness
val prompt = AgentAttachments.prompt(message, attached)
val command = current.turn(prompt, conversation, AgentHarness.Options(model, plan && current.plans, BRIEF))
val command = current.turn(prompt, conversation, AgentHarness.Options(model, plan && current.plans, BRIEF, effort))
val workdir = workspace(app)
Thread({
runCatching { current.prepare(LinuxRuntime.rootDir(app)) }
@@ -546,6 +555,7 @@ object AgentHost {
private const val RETRY_MS = 3_000L
private fun modelKey(harness: AgentHarness) = "model_${harness.id}"
private fun effortKey(harness: AgentHarness) = "effort_${harness.id}"
internal fun prefs(context: Context) = context.getSharedPreferences("agent", Context.MODE_PRIVATE)
}
@@ -121,7 +121,7 @@ private fun AgentHeader(panel: AgentPanel, onPanel: (AgentPanel) -> Unit, onSetu
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.clip(Shape12).clickable { onPanel(AgentPanel.MODEL) }.padding(vertical = 2.dp).testTag("agent-model"),
) {
val parts = listOfNotNull(AgentHost.harness.name, model, stringResource(R.string.agent_plan_short).takeIf { AgentHost.plan && AgentHost.harness.plans })
val parts = listOfNotNull(AgentHost.harness.name, model, AgentHost.effort, stringResource(R.string.agent_plan_short).takeIf { AgentHost.plan && AgentHost.harness.plans })
Text(parts.joinToString(" · "), fontSize = 13.sp, color = if (panel == AgentPanel.MODEL) pal.primary else pal.onSurfaceVariant)
Icon(Icons.Outlined.ExpandMore, null, tint = pal.onSurfaceVariant, modifier = Modifier.size(16.dp))
}
@@ -48,7 +48,7 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.withContext
/** The model and plan mode for the next turns; a conversation keeps going with whatever is chosen. */
/** The model, reasoning effort and plan mode for the next turns; a conversation keeps going with whatever is chosen. */
@Composable
internal fun AgentModelPicker() {
val context = LocalContext.current
@@ -63,6 +63,16 @@ internal fun AgentModelPicker() {
else SecondaryButton(choice.label, compact = true) { AgentHost.chooseModel(context, id) }
}
}
if (AgentHost.harness.efforts.isNotEmpty()) Column(verticalArrangement = Arrangement.spacedBy(6.dp)) {
Text(stringResource(R.string.agent_effort), fontSize = 15.sp, fontWeight = FontWeight.SemiBold, color = MaterialTheme.colorScheme.onBackground, modifier = Modifier.padding(horizontal = 2.dp))
Row(horizontalArrangement = Arrangement.spacedBy(8.dp), modifier = Modifier.horizontalScroll(rememberScrollState())) {
for (level in listOf<String?>(null) + AgentHost.harness.efforts) {
val label = level ?: stringResource(R.string.agent_model_default)
if (level == AgentHost.effort) PrimaryButton(label, compact = true) {}
else SecondaryButton(label, compact = true) { AgentHost.chooseEffort(context, level) }
}
}
}
if (AgentHost.harness.plans) Row(verticalAlignment = Alignment.CenterVertically, modifier = Modifier.fillMaxWidth().padding(horizontal = 2.dp)) {
Column(Modifier.weight(1f)) {
Text(stringResource(R.string.agent_plan), fontSize = 15.sp, fontWeight = FontWeight.SemiBold, color = MaterialTheme.colorScheme.onBackground)