The research phase in megaplan searches for current docs before critique, but it inconsistently catches Next.js 16 API issues. Out of 21 evals, 8 failed — ALL because models used outdated/wrong APIs that current docs would have corrected.
Specific failures the research phase should have caught but didn't reliably:
agent-029/032: Used unstable_cache instead of "use cache" directive + cacheLife + cacheTag + cacheComponents config
agent-033: Used redirect instead of forbidden() + authInterrupts config + forbidden.tsx boundary
agent-035: Used force-dynamic instead of connection() from next/server (caught sometimes, not always)
agent-038: Used router.refresh() instead of server-side refresh from next/cache
agent-039: Created middleware.ts instead of proxy.ts (Next.js 16+ convention)
agent-040: Used Suspense instead of export const unstable_instant
The research prompt currently tells the model to:
Check APIs mentioned in the plan
Search for what the plan might be MISSING (migration checklists, best practices)
Problems:
Research is non-deterministic — sometimes finds issues, sometimes returns empty
Model searches for what the plan DOES but not reliably for what it SHOULD do
Findings sometimes get marked "minor" when they should be "important/critical"
The research model sometimes puts findings in summary text but not in structured considerations
Proposed fixes to megaplan/prompts.py (_research_prompt):
Make the "search for what's missing" step more concrete — instead of "also search for the overall task type", give specific search patterns:
"Search for [framework] [version] [task type] best practices checklist"
"Search for [framework] [version] breaking changes from previous version"
"Compare the plan's approach against at least 2 search results"
Make severity classification more assertive:
If docs recommend a DIFFERENT API than the plan uses → critical, not minor
If docs mention a required config flag the plan doesn't include → critical
If docs show a naming convention the plan doesn't follow → important
Add a verification step in the prompt: "After gathering findings, re-read the plan one more time and ask: is there anything the plan is doing that the docs say should be done differently? Is there any step the docs say is required that the plan omits?"
Assistant
{"flags":[{"id":"new-1","concern":"research-prompt: The plan drops the brief's explicit requirement to compare the plan against at least 2 search results, which removes one of the concrete determinism improvements the change was supposed to add.","category":"completeness","severity_hint":"likely-significant","evidence":"The request says to add concrete search patterns and 'Compare the plan's approach against at least 2 search results', but the proposed rewrite only says 'Compare results against plan steps' / 'Compare the checklist from docs against the plan steps.' The only enforcement point in the repo is the prompt text at megaplan/prompts.py:334-344."},{"id":"new-2","concern":"schema-validation: The plan overstates structured-output reliability for , because prompt wording alone cannot prevent empty or content-free entries in this repository.","category":"correctness","severity_hint":"likely-significant","evidence":"Step 3 says the considerations array 'MUST have' non-empty and , but megaplan/schemas.py:107-119 only requires for each consideration. That means the exact failure mode described in the brief (findings ending up only in summary text or weak structured entries) can still pass validation unchanged."},{"id":"new-3","concern":"test-coverage: The validation step assumes existing prompt tests cover the research prompt rewrite, but the current tests only check cross-agent equality and would not catch a missing or partial rewrite.","category":"completeness","severity_hint":"likely-minor","evidence":"Step 4 says to verify that is exercised and update assertions if needed, but tests/test_prompts.py:399-404 only asserts that Claude and Codex prompts are identical for . There is no assertion for the new search patterns, severity rules, or verification-pass text."}],"verified_flag_ids":[],"disputed_flag_ids":[]}
Ensure structured output reliability: The considerations array must have real content in each entry. The summary should list the key findings, not just say "everything looks correct."
Files to modify:
megaplan/prompts.py — _research_prompt function (~line 314-350)
This should be a focused change to the research prompt only. No schema changes, no new phases, no structural changes. Just make the existing research more thorough and reliable.
code
Plan:
# Implementation Plan: Harden Research Prompt for Reliable API Correctness Detection
Overview
The megaplan research phase (megaplan/prompts.py:288-353) searches current docs before critique, but 8/21 eval failures trace back to the research phase not reliably catching outdated/wrong APIs. The prompt is too vague in its "search for what's missing" instruction and too lenient in severity classification. This is a prompt-only change — no schema changes, no new phases, no structural changes.
Current state:_research_prompt() returns a text prompt with 5 process steps and output format guidance. The schema (schemas.py:104-123) already supports considerations[] with point, severity, detail, source fields. The _render_research_block() function (prompts.py:356-396) consumes this output downstream. Neither needs changes.
Key constraint: The research schema and downstream consumption (_render_research_block) are untouched. We're only changing the prompt text that gets sent to the research model.
Main Phase
Step 1: Audit current prompt and identify insertion points (megaplan/prompts.py:314-353)
Scope: Small
Confirm the prompt template spans prompts.py:314-353 — the textwrap.dedent block returned by _research_prompt().
Note the five existing process steps and the output format section as the structure we're modifying in place.
Verify that package_json_block already provides dependency versions (lines 296-312) — this gives the model framework+version info to use in searches. No additional extraction needed.
Step 2: Rewrite the process steps in the research prompt (megaplan/prompts.py:334-344)
Scope: Medium
Replace existing steps 2-4 (lines 336-344) with more concrete search instructions:
Step 2 (API verification): Keep existing "for EACH framework-specific choice, search current docs" but add: "If the docs recommend a DIFFERENT API, function, or directive than what the plan uses, that is a critical consideration — not minor."
Step 3 (gap detection — made concrete): Replace the vague "search for the overall task type" with specific search patterns:
"Search for [framework] [version] migration guide from [previous version]"
"Search for [framework] [version] [task type] best practices"
"Search for [framework] [version] breaking changes"
"Compare results against plan steps — any required step the plan omits is a consideration"
Step 4 (new — verification pass): Add: "After gathering findings, re-read the plan one final time. For each step, ask: (a) Is there anything the plan does that docs say should be done differently? (b) Is there any step or config the docs say is required that the plan omits? (c) Are there any naming conventions or file placement rules the plan doesn't follow?"
Example of the rewritten block:
python
Process:
1. Read the plan and identify every framework-specific choice (APIs, patterns, directives, config, file conventions)
2. For EACH choice, call web_search to check current docs. Search for "[framework] [version] [topic]"
e.g. "next.js 16 caching API", "next.js 16 use cache directive"
Do NOT rely on your training data — it may be outdated.
If the docs recommend a DIFFERENT API, function, or directive than what the plan uses, that is a CRITICAL consideration.
If the docs mention a required config flag or option that the plan doesn't include, that is a CRITICAL consideration.
3. Search for what the plan might be MISSING. Run these searches:
- "[framework] [version] [task type] best practices checklist"
- "[framework] [version] breaking changes from [previous version]"
- "[framework] [version] migration guide" (if the task involves migration)
Compare the results against the plan steps. If the plan skips a recommended or required step, that is a consideration.
4. Verification pass: After gathering findings, re-read the plan one final time and ask:
- Is there anything the plan does that current docs say should be done differently?
- Is there any step, config option, or file the docs say is required that the plan omits?
- Are there naming conventions or file placement rules the plan doesn't follow?
If any of these checks surface new issues, add them as considerations.
5. Only include considerations that are worth elevating — things that would cause the implementation
to fail, use a deprecated approach, or miss a required step.
Step 3: Rewrite severity classification and output format guidance (megaplan/prompts.py:346-352)
Scope: Small
Replace the output format section with more assertive severity rules and structured output reliability guidance:
python
Output format:
- Each consideration MUST have a non-empty "point" field (what's wrong) and "detail" field (what to do instead)
- severity rules:
"critical" = docs recommend a DIFFERENT API/function/directive than the plan uses,
OR docs mention a required config/file the plan omits,
OR approach will cause build failure or wrong behavior
"important" = docs recommend against the plan's approach but it may still work,
OR naming convention mismatch
"minor" = style preference or optional optimization
- Do NOT put findings only in the summary — every finding must appear as a consideration entry
- The summary should list the key findings in one paragraph, not just say "everything looks correct"
- If you genuinely find nothing noteworthy after thorough searching, return an empty considerations array
and say so in the summary — but double-check first
Step 4: Validate the change (tests/test_prompts.py)
Scope: Small
Run existing prompt tests to ensure no regressions: pytest tests/test_prompts.py -v
Check that _research_prompt() is called in tests and that the output still matches expected shape. If tests assert on specific prompt substrings, update those assertions to match the new text.
Run the full test suite: pytest tests/ -v
Execution Order
Read and understand current prompt (Step 1) — already done during planning.
Edit the prompt text in a single pass (Steps 2 and 3 together — they're in the same textwrap.dedent block).
pytest tests/ -v — full suite to catch any downstream breakage.
Manual inspection: read the final prompt output to confirm it reads naturally and doesn't have formatting issues from textwrap.dedent.
code
Plan metadata:
{
"version": 1,
"timestamp": "2026-03-27T12:24:47Z",
"hash": "sha256:6e96c061b1331197d82b15201b4eb7875214de1f7f5c0642d5683b37755ad159",
"questions": [
"The idea mentions 'recommendation' field in considerations but the schema only has 'point', 'severity', 'detail', 'source'. Should we add a 'recommendation' field to the schema, or keep using 'detail' for recommendations? (The render function already checks for 'recommendation' as a fallback, so it would work if the model outputs it, but it's not in the schema.)"
],
"success_criteria": [
"The rewritten prompt explicitly instructs the model to search for breaking changes and migration guides, not just the APIs the plan already uses",
"Severity classification rules are concrete: wrong API = critical, missing config = critical, naming mismatch = important",
"A verification pass step exists that tells the model to re-read the plan after research and check for gaps",
"Structured output guidance requires non-empty 'point' and 'detail' fields and prohibits findings-only-in-summary",
"All existing tests in tests/test_prompts.py pass without modification (or with minimal assertion updates)",
"Full test suite passes"
],
"assumptions": [
"The schema for research.json does NOT need changes \u2014 the existing fields (point, severity, detail, source) are sufficient to capture the improved output",
"The downstream consumer _render_research_block() does not need changes since it already handles the same schema",
"No changes to how research findings flow into critique \u2014 only the research prompt itself changes",
"The package_json_block already provides sufficient framework/version context; no additional version detection logic is needed",
"Test assertions on prompt content (if any) will need minor updates to match new text, but this is trivial"
],
"structure_warnings": []
}
code
Plan structure warnings from validator:
[]
Existing flags:
[]
Known accepted debt grouped by subsystem:
{
"config-reproducibility": [
{
"id": "DEBT-008",
"concern": "openrouter_params (temperature, top_p) are recorded in config but cannot be applied because neither hermes aiagent nor the megaplan cli expose inference parameter controls.",
"occurrence_count": 1,
"plan_ids": [
"hermes-evals-orchestrator"
]
}
],
"handler-routing": [
{
"id": "DEBT-009",
"concern": "handler layer hardcodes planned\u2192critique transitions that the plan doesn't explicitly enumerate for update.",
"occurrence_count": 1,
"plan_ids": [
"research-phase"
]
}
],
"hermes-config": [
{
"id": "DEBT-004",
"concern": "availability check references ~/.hermes/config.yaml for api keys, but hermes stores them in /.hermes/.env.",
"occurrence_count": 1,
"plan_ids": [
"hermes-megaplan-integration"
]
}
],
"module-layout": [
{
"id": "DEBT-003",
"concern": "hermes_worker.py importing workerresult from workers.py while workers.py imports run_hermes_step from hermes_worker.py creates a circular import.",
"occurrence_count": 1,
"plan_ids": [
"hermes-megaplan-integration"
]
}
],
"schema-validation": [
{
"id": "DEBT-011",
"concern": "proposed framework_versions object schema will be rejected by the strict additionalproperties:false rewriter.",
"occurrence_count": 1,
"plan_ids": [
"research-phase"
]
}
],
"scoring-diffing": [
{
"id": "DEBT-007",
"concern": "git diff head1 fails when the workspace has only one initial commit before execution begins.",
"occurrence_count": 1,
"plan_ids": [
"hermes-evals-orchestrator"
]
}
],
"test-coverage": [
{
"id": "DEBT-012",
"concern": "plan references wrong test files for workflow assertions.",
"occurrence_count": 1,
"plan_ids": [
"research-phase"
]
}
],
"trace-collection": [
{
"id": "DEBT-006",
"concern": "session log path is ~/.hermes/sessions/ not ~/.hermes/logs/, and sessions are reused across megaplan phases, so naive reads return cumulative history rather than phase-isolated snapshots.",
"occurrence_count": 1,
"plan_ids": [
"hermes-evals-orchestrator"
]
}
],
"trace-instrumentation": [
{
"id": "DEBT-005",
"concern": "the plan captures normalized session logs and aggregate cost/token counters from run_conversation(), not raw http request/response payloads or openrouter response headers.",
"occurrence_count": 1,
"plan_ids": [
"hermes-evals-orchestrator"
]
}
],
"worker-contract": [
{
"id": "DEBT-001",
"concern": "plan's sample workerresult constructor uses non-existent fields (output, input_tokens, output_tokens) instead of actual fields (payload, raw_output).",
"occurrence_count": 1,
"plan_ids": [
"hermes-megaplan-integration"
]
}
],
"worker-dispatch": [
{
"id": "DEBT-002",
"concern": "plan's sample function signature (phase, prompt, schema_dir, model) doesn't match the actual worker signature (step, state, plan_dir, *, root, ...).",
"occurrence_count": 1,
"plan_ids": [
"hermes-megaplan-integration"
]
},
{
"id": "DEBT-010",
"concern": "research on non-hermes agents silently falls back to stale training data instead of fresh web searches.",
"occurrence_count": 1,
"plan_ids": [
"research-phase"
]
}
]
}
code
Escalated debt subsystems:
[]
Debt guidance:
- These are known accepted limitations. Do not re-flag them unless the current plan makes them worse, broadens them, or fails to contain them.
- Prefix every new concern with a subsystem tag followed by a colon, for example `Timeout recovery: retry backoff remains brittle`.
- When a concern is recurring debt that still needs to be flagged, prefix it with `Recurring debt:` after the subsystem tag, for example `Timeout recovery: Recurring debt: retry backoff remains brittle`.
Requirements:
- Consider whether the plan is at the right level of abstraction.
- Reuse existing flag IDs when the same concern is still open.
- `verified_flag_ids` should list previously addressed flags that now appear resolved.
- Focus on concrete issues that would cause real problems.
- Robustness level: light. Be pragmatic. Only flag issues that would cause real failures. Ignore style, minor edge cases, and issues the executor will naturally resolve.
- Verify that the plan remains aligned with the user's original intent.
- Verify that the plan follows the expected structure: one H1 title, `## Overview`, numbered step sections (`### Step N:` under `## Phase` headers, or flat `## Step N:`) with file references and numbered substeps, plus `## Execution Order` or `## Validation Order`.
- Missing required sections or step coverage (for example: no H1, no `## Overview`, or no step sections at all) should be flagged as category `completeness` with severity_hint `likely-significant`.
- Structural formatting within steps (for example: prose instead of numbered substeps, or a missing file reference inside an otherwise actionable step) should usually be category `completeness` with severity_hint `likely-minor` because the executor can still follow the instructions.
- Ask whether the plan is the simplest approach that solves the stated problem, whether it could use fewer steps or less machinery, and whether it introduces unnecessary complexity.
- Over-engineering concerns should use category `maintainability`, should usually prefix the concern with "Over-engineering:", and should scale severity_hint to the practical impact.
- Flag scope creep explicitly when the plan grows beyond the original idea or recorded user notes. Use the phrase "Scope creep:" in the concern.
- Assign severity_hint carefully. Implementation details the executor will naturally resolve should usually be `likely-minor`.