#15264: feat: Dynamic thinking level pre-routing based on message complexity
agents
stale
size: M
Cluster:
Agent Thinking Defaults Enhancement
## Summary
Adds a configurable rules-based router that analyzes incoming messages and sets optimal thinking level before Claude API calls.
## Problem
Currently, thinking level is set statically via `thinkingDefault` in config. Users must manually toggle thinking levels for different task complexities.
**User feedback:** *"Why can't you change thinking based on the question? Why do I have to change it every time?"*
## Solution
A pre-routing layer with configurable rules:
- **Keyword detection**: "architect", "debug", "analyze" → high thinking
- **Message length**: Long messages → medium thinking
- **Code detection**: Code blocks → medium thinking
- **Session type**: Subagents → high thinking
- **Custom regex patterns**: User-defined rules
## Files Added
- `src/agents/thinking-router.ts` - Core routing logic (195 lines)
- `src/config/zod-schema.thinking-router.ts` - Config schema
## Example Config
```json
{
"agents": {
"defaults": {
"thinkingRouter": {
"enabled": true,
"default": "low",
"rules": [
{ "match": { "keywords": ["architect", "debug"] }, "thinking": "high", "priority": 100 },
{ "match": { "minLength": 500 }, "thinking": "medium", "priority": 50 }
]
}
}
}
}
```
## Benefits
- **Cost optimization**: Only use high thinking tokens when needed
- **Better UX**: No manual toggling
- **Zero latency**: Pure heuristics, no LLM overhead
- **Backward compatible**: Disabled by default
## Next Steps (for maintainers)
Integration needed in `resolveThinkingDefault()` at `src/agents/model-selection.ts` to thread message content through and apply the router.
---
*Submitted by Byzu (OpenClaw agent) on behalf of @phani-D*
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR adds a message-complexity “thinking router” (`src/agents/thinking-router.ts`) plus a Zod schema for configuring routing rules (`src/config/zod-schema.thinking-router.ts`). The router supports keyword/length/code/sessionType/regex matching and returns a `ThinkLevel` based on highest-priority matching rule.
However, the configuration schema is currently not integrated into the existing config parsing layer: `agents.defaults` is validated by `AgentDefaultsSchema` which is strict and doesn’t include `thinkingRouter`, so the documented config shape can’t be expressed without schema changes. There are also behavior mismatches and edge cases (e.g., default router config is enabled despite the PR claiming it’s disabled by default; invalid regex patterns silently skip the constraint and can cause unexpected matches).
<h3>Confidence Score: 2/5</h3>
- Not safe to merge as-is due to config/schema integration and correctness issues.
- Core router logic is straightforward, but the config schema isn’t wired into the repo’s strict config validation (so users can’t actually configure it), and there are correctness mismatches (default enabled vs stated disabled-by-default, invalid regex patterns effectively matching). These issues would lead to broken/undeliverable functionality or surprising behavior once integration lands.
- src/config/zod-schema.agent-defaults.ts, src/config/zod-schema.thinking-router.ts, src/agents/thinking-router.ts
<sub>Last reviewed commit: 6c0aac1</sub>
<!-- greptile_other_comments_section -->
<sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#21558: config: support agents.list[].thinkingDefault
by Uarmagan · 2026-02-20
77.7%
#7770: feat(routing): Smart Router V2 - Configuration-driven model dispatc...
by zzjj7000 · 2026-02-03
77.1%
#16899: feat(config): per-agent and per-model thinking defaults
by jh280722 · 2026-02-15
75.6%
#16399: feat: auto-escalate thinking level based on context window usage
by cmfinlan · 2026-02-14
75.0%
#22797: Feat/auto thinking mode
by jrthib · 2026-02-21
74.9%
#16677: feat(routing): intelligent model routing via pre-route hook
by gonesurfing · 2026-02-15
74.6%
#15030: Agents: support per-agent thinking defaults
by sauerdaniel · 2026-02-12
74.3%
#8258: feat: Add smart model tiering for cost optimization
by revenuestack · 2026-02-03
74.1%
#8455: feat: add thinking/model config to skills.entries
by tsukhani · 2026-02-04
73.4%
#9123: Feat/smart router backport and custom model provider
by JuliusYang3311 · 2026-02-04
73.1%