← Back to PRs

#17714: feat: LangGraph pre-response context enrichment plugin

by AvenueDAdmin open 2026-02-16 03:35 View on GitHub →
docs stale size: L
## 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