#17714: feat: LangGraph pre-response context enrichment plugin
docs
stale
size: L
Cluster:
Plugin and Hook Enhancements
## Summary
This PR adds a new plugin that uses the existing `before_agent_start` hook to automatically gather relevant context before each agent response using LangGraph.
## Motivation
Currently, users who want intelligent context enrichment need to manually configure pre-response checks in their AGENTS.md or workspace files. This plugin provides an opt-in solution that:
1. **Automatically detects user intent** using AI (Claude Haiku, ~$0.0001/query)
2. **Routes to relevant tools** only - no brute-force checking all sources
3. **Executes in parallel** for speed (typical: 0.5-2s)
4. **Falls back gracefully** if the planner fails or times out
## How It Works
```
User Message
│
▼
before_agent_start hook fires
│
▼
Plugin spawns langgraph_planner_v4.py
│
▼
Planner detects intent (task_query, financial_query, etc.)
│
▼
Routes to relevant tools and executes in parallel
│
▼
Returns { prependContext: '...' }
│
▼
Context prepended to user message
│
▼
LLM generates response with enriched context
```
## Example
User: "What should I do today?"
Plugin detects `task_query` intent and runs:
- `commitments_check` → finds overdue items
- `todo_parse` → finds critical tasks
- `calendar_check` → finds today's events
Injects context:
```markdown
## Pre-Response Context (Auto-Generated)
_Intents detected: task_query_
### Commitments
**Overdue:**
- ⚠️ Review PR for project X (due 2026-02-14)
### TODO Items
**Critical:**
- 🚨 Fix production bug (CRITICAL)
### Calendar
- 10:00 AM: Team standup
- 2:00 PM: Client call
---
```
## Configuration
```yaml
plugins:
langgraph-pre-response:
enabled: true
plannerPath: scripts/langgraph_planner_v4.py
timeoutMs: 5000
```
## Files Added
- `extensions/langgraph-pre-response/index.ts` - Plugin implementation
- `extensions/langgraph-pre-response/README.md` - Plugin documentation
- `extensions/langgraph-pre-response/package.json` - Package manifest
- `extensions/langgraph-pre-response/openclaw.plugin.json` - Plugin metadata
- `docs/plugins/langgraph-pre-response.md` - User documentation
## Backward Compatibility
- ✅ No breaking changes
- ✅ Plugin is opt-in (disabled by default)
- ✅ Uses existing `before_agent_start` hook
- ✅ Graceful fallback on errors
## Testing
Tested with:
- Various query types (task, financial, health, project)
- Timeout scenarios
- Missing planner file
- Planner errors
## References
- [Hook Proposal Gist](https://gist.github.com/openmetaloom/657c4668c09d235f8da1306e2438904b)
- [LangGraph Documentation](https://langchain-ai.github.io/langgraph/)
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
This PR adds a plugin that enriches agent context before responses using LangGraph-based intent detection and tool routing. The implementation follows the existing plugin architecture by registering a `before_agent_start` hook that spawns a Python planner subprocess to intelligently gather relevant context.
**Key Changes:**
- New plugin structure under `extensions/langgraph-pre-response/` with TypeScript implementation
- Configuration schema for planner path, timeout, and other options
- Context formatter that transforms planner results into prepended markdown context
- Documentation in both README and docs directory
**Issues Found:**
- Missing `openclaw.extensions` field in `package.json` (breaks plugin loading)
- Missing `zod` dependency declaration (runtime failure)
- `openclaw` incorrectly placed in `dependencies` instead of `devDependencies` (npm install breaks)
- Unsafe fallback when `HOME` env var is undefined
- Duplicate timeout handling creates race condition between spawn option and manual setTimeout
- Shared `/tmp/` results file path enables race conditions in concurrent scenarios
- Greedy regex may capture incorrect JSON when planner emits debug output with braces
<h3>Confidence Score: 2/5</h3>
- This PR introduces multiple critical issues that will prevent the plugin from functioning correctly
- The plugin has several blocking issues including missing required package.json fields that prevent loading, missing dependencies that cause runtime failures, and logic errors. While the overall architecture is sound, these issues must be resolved before merge.
- extensions/langgraph-pre-response/package.json requires multiple corrections (missing openclaw.extensions field, dependency placement, missing zod). extensions/langgraph-pre-response/index.ts needs fixes for the HOME fallback, timeout handling, and file path race conditions.
<sub>Last reviewed commit: aff390c</sub>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#14873: [Feature]: Extend before_agent_start hook context with Model, Tools...
by akv2011 · 2026-02-12
79.1%
#22624: feat(plugins): add before_context_send hook and model routing via b...
by davidrudduck · 2026-02-21
77.5%
#14544: feat: add before_context_send plugin hook
by Windelly · 2026-02-12
77.0%
#8022: feat: implement before_model_select plugin hook
by dead-pool-aka-wilson · 2026-02-03
73.9%
#20067: feat(plugins): add before_agent_reply hook for message interception
by JoshuaLelon · 2026-02-18
73.8%
#23559: feat(plugins): add before_context_send hook and model routing via b...
by davidrudduck · 2026-02-22
73.6%
#22733: feat(plugin): add runner-extensions extension
by cintia09 · 2026-02-21
73.5%
#11124: feat(plugins): add before_llm_request hook for custom LLM headers
by johnlanni · 2026-02-07
73.5%
#6017: feat(hooks): add systemPrompt and tools to before_agent_start event
by yajatns · 2026-02-01
73.4%
#21648: feat: execution plan governance plugin
by nayname · 2026-02-20
73.4%