Add background investigation scout step before planning
Summary
Add a "background investigation" (scout) step before planning: one cheap researcher pass grounds the planner with a handful of real snippets so the resulting plan is anchored in current facts rather than the model's priors.
Problem
Our planner plans blind — it decomposes from the prompt alone. Plan quality improves markedly when the planner has seen a few relevant results first (correct entity names, current facts, scope of the space). deer-flow runs a background investigation before the planner node for exactly this reason.
Solution (optional)
Scope: core.
- Optional pre-planner step: a single cheap
researcher(web/doc) call, results fed into the planner prompt as grounding context. - Gate behind config + a heuristic (skip for trivial asks, or when #2's
has_enough_contextwould already fire). - Keep it bounded — one call, capped result size, summarized into the planner prompt.
[scout]logging on invoke / skip / inject.
Acceptance criteria
- [ ] Scout step — optional grounding pass runs before
plannerwhen enabled. - [ ] Grounding injected — scout results reach the planner as context.
- [ ] Bounded & gated — single capped call, config-gated, skipped for trivial asks.
- [ ] Diff coverage ≥ 80% — the implementing PR meets the changed-lines coverage gate.
Related
Part of a deer-flow parity set (harness improvements 1–6). Composes with #3882 (skip scout when context already sufficient) and feeds better plans into #3881.
Implementation Plan
Triage Assessment
- The
plannerbuiltin agent doesn't receive pre-grounded context: it decomposes the task solely from the user prompt. - A
context_scoutsubagent exists (src/openhuman/agent/harness/subagent_runner/ops/prompt.rs:39-46) but runs inside the orchestration graph as a per-session subagent, not before the planner. - Issue #3882 (has_enough_context early-exit, closed as completed) already provides the heuristic gating.
- User impact: planner produces better plans (correct entity names, current facts, accurate scope).
Proposed Scope
- In-scope:
- Define a pre-planner scout step: before
plannerruns, make one bounded researcher/doc call. - Feed summarized results into the planner's instruction context (not injected into the conversation as turns).
- Gate behind a new
scout_before_planconfig flag + the existinghas_enough_contextheuristic from #3882. - Add
[scout]tracing on invoke / skip / injection.
- Define a pre-planner scout step: before
- Explicit non-goals:
- Not building a new web search agent (reuses existing
researcherbuiltin agent atsrc/openhuman/agent/harness/builtin_definitions.rs:265). - Not adding a multi-call investigation loop (single capped call).
- Not changing the planner's internal decomposition logic.
- Not building a new web search agent (reuses existing
Implementation Steps
src/openhuman/agent/harness/grounding_scout.rs— New module. DefineGroundingScoutstruct with:invoke(ctx: &ScoutContext) -> Option<String>— spawns theresearchersubagent with the user prompt, caps tool calls at 1, caps result length at ~2000 chars, summarizes the output. ReturnsNoneif skipped (config off, trivial ask, orhas_enough_contexttrue).- Config check from
Config::agent().scout_before_plan(add to config schema insrc/openhuman/config/schema/). - Trivial-ask heuristic: skip if prompt length < 50 chars or is a known-simple pattern (yes/no, greeting, confirmation).
src/openhuman/agent/harness/mod.rs— Addpub mod grounding_scout;.- Planner prompt injection — In
src/openhuman/agent/harness/subagent_runner/ops/prompt.rs, before building the planner's base prompt, callGroundingScout::invoke. If it returnsSome(summary), prepend the summary to the planner's instructions (e.g."[Background context from research:\n{summary}\n---]"). - Config gate — Add to
src/openhuman/config/schema/agent.rs:
Wire env override inpub scout_before_plan: bool, // default falsesrc/openhuman/config/schema/load.rs. - Logging — In
GroundingScout::invoke, emittracing::debug!(target: "scout", "[scout] invoke|skip|inject ...")on each path. - Test the scout — Add
#[cfg(test)] mod testsingrounding_scout.rs:scout_invokes_researcher_when_enabled— mock the subagent runner, assert researcher is called.scout_skips_when_disabled— config off, assert no call.scout_skips_trivial_ask— prompt "yes", assert no call.scout_skips_when_context_sufficient— reusehas_enough_contextlogic, assert skip.
- Planner prompt test — Add test in
src/openhuman/agent/harness/subagent_runner/ops/prompt.rsor a new test file verifying scout summary appears in planner's built instructions.
Verification
cargo test --lib openhuman::agent::harness::grounding_scout::tests— scout unit tests.cargo test --lib openhuman::agent::harness::subagent_runner::ops::prompt::tests— planner prompt injection tests.- Compose with #3882: verify that
has_enough_context = truefrom completed #3882 skips the scout. pnpm test:rust— full suite must stay green.
Risks and Open Questions
- The scout adds one LLM call (the researcher) and one tool call. Even capped, this adds latency to every planning turn. The config default should be
false. - What happens when the researcher returns empty results for a novel domain? The planner gets an empty grounding context, which is equivalent to today's behavior — acceptable.
- The existing
context_scoutsubagent may overlap partially. Ensure the pre-planner scout is a different point in the flow (before planner decomposition, not during orchestration execution). - If the planner prompt already contains sufficient context from the conversation transcript, the scout adds no value. The
has_enough_contextheuristic should be the primary gating signal.
Acceptance Criteria
- Pre-planner scout step runs when
scout_before_plan = trueandhas_enough_contextis false. - Scout results are injected into the planner's instruction context.
- Single capped researcher call, results summarized to ≤2000 chars.
- Config-gated with default
false. - Diff coverage >= 80%.
Hi, I'd like to work on this issue.
My understanding is that the goal is to add a lightweight, optional scouting step before planning so the planner can be grounded with a small amount of real context instead of planning solely from the user prompt.
My current idea is to keep it bounded to a single researcher/search pass, gate it behind configuration and existing context checks, and inject a summarized version of the findings into the planner's context. I'll also make sure the scout step can be skipped when the request is trivial or sufficient context is already available.
Before I start implementing, does this direction align with what you had in mind, particularly around where the scout should live in the planning flow?
Happy to take this on if nobody else is working on it.
Verified on main (6be58a9ab) — unimplemented, but every building block already exists. This is wiring, not new machinery.
@ssmadhavan006 — your direction is right, and your open question ("where should the scout live in the planning flow?") has a fairly concrete answer in the current tree. Findings:
1. The planner still plans blind. src/openhuman/agent/registry/agents/planner/ (prompt.md, prompt.rs, agent.toml) contains no mention of scout, grounding, or background investigation. It decomposes from the prompt alone, exactly as the issue says.
2. context_scout exists and is already a first-class agent — confirming the triage note. src/openhuman/agent/harness/subagent_runner/ops/prompt.rs:42-49:
context_scoutdefines its own strict output contract (emit a single … ) … Skip the suffix for the scout; itsprompt.md…
It is handled specially precisely because it has a strict output contract, which is what makes it safe to consume programmatically. You should not need to write a new researcher agent.
3. The #3882 gating heuristic is live and reusable. has_enough_context exists as a real field, not just a concept:
src/openhuman/agent/harness/fork_context.rs:167—pub has_enough_context: Option<bool>src/openhuman/agent/orchestration/tools/agent_prepare_context_part_01.rs:66— the folding logic across prepared sourcessrc/openhuman/agent/harness/session/turn/core_turn.rs:535
4. There is already a prepared-context bundle abstraction — agent_prepare_context produces sources carrying both has_enough_context and recommended_tool_calls, and already_prepared_context_bundle() (agent_prepare_context_part_01.rs:56+) renders a no-op result when context was prepared earlier, with an explicit sufficiency note.
What that means for the design
The three acceptance criteria map onto existing seams rather than new ones:
| criterion | existing seam |
|---|---|
Scout step runs before planner when enabled |
invoke the existing context_scout agent |
| Grounding injected into the planner | the prepared-context bundle already has a render path into a prompt |
| Bounded & gated, skipped for trivial asks | has_enough_context from #3882 is the gate |
So the answer to "where should it live" is most likely the prepared-context path, not a new node — agent_prepare_context is already the thing that gathers grounding and reports sufficiency, and the gap is that the planner does not consult it. Framing the work as "make the planner consume a prepared-context bundle, and run the scout to populate one when it is missing and the ask is non-trivial" reuses all four pieces above and keeps the bounded/gated requirement essentially free.
Worth confirming with a maintainer before you start, since this touches the orchestration graph — but that framing should make the scope much smaller than the issue implies.
One thing to watch: context_scout's strict output contract is what the prompt.rs special-case protects. If the scout output gets summarized into the planner prompt, make sure the summarization does not re-introduce the generic headings that special-case exists to avoid — the comment at prompt.rs:45-47 is describing a failure that has already happened once.
Leaving open and unassigned as far as I can tell — @ssmadhavan006 asked in June and has had no reply, which is probably the main thing blocking this.
Triage: needs opinion — “Add background investigation scout step before planning” needs a maintainer decision on product scope/priority or fresh reproduction evidence before its status can be settled. Please advise whether to pursue, narrow, or close it.
Thanks for this, and @ssmadhavan006, thanks for offering to take it. The agents this plan connects have since been removed: the planner and context_scout sub-agents went in #6760 and #8319, and planning now happens in plan mode with request_plan_review. So this issue can't be done as written, and we're closing it.
The idea itself, grounding a plan with a quick look first, still makes sense. If you'd like to pursue it, please open a new issue proposing where a scout step would fit in plan mode, and a maintainer can confirm the approach before you start.