The same empty, cut-off request is sent up to ten times, unchanged

A research agent that already meters every attempt and keeps a standard report to three calls.
≈ 660,000 tokens per 1,000 calls, for empty, cut-off answers asked for again unchanged estimate
Audited with leanprompt 0.1.0-dev.15
Estimates, not measurements. Every figure on this page is an estimate from reading the code, not a measurement of the app in use.
- Repository
- assafelovic/gpt-researcher
- Commit audited
9d39a2f- leanprompt version
- 0.1.0-dev.15
- Audit date
- Status
- The maintainers have been told about this audit; no response yet.
- Maintainers
- the pull request
- How it ran
- Unattended audit: nobody was asked during the run, so priority, volume and prices were left open; the questions for the owner are listed at the end.
A research agent that already meters every attempt and tracks its costs closely; a standard report is three calls. The largest finding, a cut-off empty answer resent unchanged, continues the project's own issue #2251; pull request #2381, opened with this audit, proposes the fix. Audited with leanprompt 0.1.0-dev.11, re-scored with 0.1.0-dev.14.
leanprompt read the code at commit 9d39a2f and found 7 places where its LLM calls could use fewer tokens, plus 5 other problems, not scored. Static score: 78 of 100 (an estimate from the findings). The code may have changed since.
Findings
-
LP-GE-05Retry only retryable errors; never retry a truncation unchangedgpt_researcher/utils/llm.py:151· severity high · saves prefill and generation · how often is assumedWhat happens. When a model returns an empty answer, the shared completion helper sends the exact same request again, up to 10 times. On reasoning models an empty answer almost always means the output limit was used up by reasoning, so the same request fails the same way and every attempt is billed.
The change. Read the finish reason the provider already returns (finish_reason 'length' on OpenAI-compatible APIs, stop_reason 'max_tokens' on Anthropic, MAX_TOKENS on Gemini). If the empty answer was cut off by the limit, retry at most once with a larger limit (for example double, capped), or raise a clear error naming the token-limit setting. Keep the current retry for empty answers that were not cut off.
Why it helps. Each repeated attempt bills up to the full output limit (4,000 or 8,000 tokens in deep research) and returns nothing usable.
Estimate about 300k output and 360k prompt tokens per 1,000 calls (estimate)
Assumptions. Call mix: 80% of runs are standard reports (3 calls), 15% deep research (about 33 calls), 5% detailed; so about 60% of calls are deep research. After PR #2260, 2% of result-analysis calls (8,000 limit) and 10% of plan calls and 2% of query calls (4,000 limit) still come back empty from truncation, and when they do the 9 retries also come back empty. Issue #2251 measured 202 empty responses in 13 runs before the fix. Each retry also resends the prompt, about 6k tokens on average, so the prompt side is about 0.06 of prompt tokens; the share recorded is the larger output side.
How often. How often a call still comes back empty because the output limit was reached after #2260: count 'Empty response' warnings, with the provider's finish reason, in a deep-research run log.
-
LP-PC-02Stable content first, without hurting meaningbackend/chat/chat.py:246· severity high · saves prefillWhat happens. The chat-about-the-report system prompt contains the current time down to the microsecond and the report passages retrieved for this turn, and it comes before the conversation history. So the start of every request is new, and none of the earlier turns can be served from the provider's prompt cache.
The change. Keep the system prompt fixed for the conversation (date only, no time, set once), keep the history after it unchanged, and put the passages retrieved for this turn into the newest user message instead of the system prompt. Retrieval per turn (the comment at line 223) stays as it is.
Why it helps. On OpenAI, prompt caching is automatic for a repeated prefix of 1,024 tokens or more; with a new prefix on every turn the history is billed at full input price every time.
Estimate about 93k prompt tokens per 1,000 calls not served from cache (estimate)
Assumptions. Chat is 10% of the app's calls; 4 turns per chat; about 650 tokens per turn of history; fixed system part about 300 tokens; only prefixes of 1,024 tokens or more count, in 128-token steps, so turns 1 and 2 gain nothing.
-
LP-GE-03Output and thinking budgets that fit the taskgpt_researcher/skills/deep_research.py:349· severity medium · saves generation · how often is assumedWhat happens. The deep-research plan call runs the strategic model at high reasoning effort with the helper's default 4,000-token limit, which also has to cover the reasoning. This is the same shape PR #2260 fixed for the result-analysis call, but the plan call and the query-generation call were left at 4,000.
The change. Pass max_tokens=cfg.strategic_token_limit to generate_research_plan and generate_search_queries, as #2260 did for process_research_results.
Why it helps. A cut-off plan returns empty after spending the whole 4,000-token budget, and then falls into the unchanged retry above.
Estimate about 13k output tokens per 1,000 calls (estimate), first attempts only; the retries are counted in the empty-answer finding
Assumptions. About 18 plan calls and 74 query calls per 1,000 app calls; 10% of plan calls and 2% of query calls are cut off at 4,000 tokens.
How often. How often gpt-5.4 at reasoning_effort high returns empty content for the research-plan prompt with a 4,000-token limit (count 'LLM returned empty response' warnings in a deep run log).
-
LP-GE-10Structured output instead of parse-and-re-askgpt_researcher/skills/deep_research.py:382· severity medium · saves generationWhat happens. The deep-research calls ask for JSON in the prompt text but do not use the provider's structured output. The parsers are forgiving and fall back to line parsing, so a malformed answer is rarely re-asked, but when nothing parses the learnings from that query are dropped.
The change. Where the provider supports it, pass a JSON schema (with_structured_output or response_format json_schema) for the learnings, queries and plan calls, and keep the current parser as the fallback for providers without it.
Why it helps. An unparseable answer is output that was paid for and thrown away.
Estimate about 3k output tokens per 1,000 calls (estimate)
Assumptions. 1% of the 166 result-analysis calls per 1,000 calls fail to parse at about 2,000 output tokens each.
-
LP-PD-06Compact serialisation for data in the promptgpt_researcher/skills/deep_research.py:341· severity low · saves prefillWhat happens. The research-plan prompt pastes the raw search results as a Python list repr, with every key and quote repeated for each result.
The change. Format the results as short title, URL and snippet lines, as other prompts in the project already do.
Why it helps. Repeated keys and quoting add tokens that carry no information.
Estimate about 1k prompt tokens per 1,000 calls (estimate)
Assumptions. One plan call per deep run (about 18 per 1,000 calls); about 3,000 tokens of results, 15% of it key and quote overhead.
-
LP-GE-05Retry only retryable errors; never retry a truncation unchangedgpt_researcher/utils/llm.py:127· severity high · saves prefill and generationWhat happens. Every exception from the provider is retried up to 10 times with backoff, including errors that cannot succeed on retry: a wrong API key, a rejected parameter, a prompt over the context window, exhausted credit. Sub-query generation chains three such calls, so a bad key takes 30 attempts and about 3 minutes before the run reports the error.
The change. Do not retry authentication, permission, bad-request and context-length errors (HTTP 400, 401, 403, 404, 413, and 429 for exhausted quota); raise them on the first attempt. Keep retries for connection errors, 408, 409, 429 rate limits and 5xx.
Why it helps. Rejected requests are usually not billed, so the cost is mostly time and a slow, noisy failure, not tokens.
Estimate near zero tokens; up to about 55 s of backoff per call and about 3 minutes per run on a persistent error (estimate)
Assumptions. Rejected 4xx requests are not billed by the provider. The SDK under LangChain also retries 408, 409, 429 and 5xx twice on its own.
-
LP-GE-08Route trivially small calls to a small modelgpt_researcher/actions/agent_creator.py:46· severity medium · saves prefill and generationWhat happens. Picking the research persona is a short label call (a name and a one-paragraph role), but it runs on the smart model, the one used to write the report.
The change. Run choose_agent on the fast model (FAST_LLM), after an answer check on a sample of queries.
Why it helps. The smart model (default gpt-6-sol) costs several times the fast model (default gpt-5.4-mini) per token for a task the small model can do.
Estimate price only, no tokens saved
Assumptions. One persona call per research run, and one per nested researcher in deep research.
Other problems the audit found
Problems read in the code that cost no tokens of their own, such as a cost meter or an error path. Not scored.
-
Cached OpenAI input is priced at half the input rate for every model
gpt_researcher/utils/costs.py:24·LP-GE-11Meter every billed token, cached and unfinished ones too · severity lowWhat happens. OPENAI_CACHED_INPUT_DISCOUNT = 0.5 applies to every OpenAI model (used at lines 306-313). OpenAI's pricing page (read 2026-11-26) lists cached input at a tenth of the input price for the three default models, so their cached tokens are reported at five times their price. The tests use gpt-4o, where 0.5 is right. The comment at lines 18-23 says to revisit this when a model has a different ratio.
The change. Add a cached-input price to each OPENAI_MODEL_PRICING row and use it, keeping 0.5 as the fallback for unknown models.
To check. A parametrised test in tests/test_costs.py for the default models and gpt-4o.
-
A report cut off at the output limit is accepted as complete
gpt_researcher/actions/report_generation.py:292·LP-GE-12Read the finish reason before using an answer · severity mediumWhat happens. generate_report streams the report with max_tokens set to SMART_TOKEN_LIMIT, which on reasoning models also covers the reasoning. No code reads finish_reason or stop_reason, so a report that hits the limit stops mid-sentence and is saved and shown as complete. Only the empty case is detected (utils/llm.py:151).
The change. Warn when the response metadata says the limit was reached, naming SMART_TOKEN_LIMIT.
To check. With a small SMART_TOKEN_LIMIT, the run logs a warning and the report is marked as cut off.
-
A report stream that fails part way is shown twice
gpt_researcher/actions/report_generation.py:307What happens. When the streamed report fails after some chunks were sent, generate_report sends the whole report again through the same websocket (lines 307-322). The Next.js frontend appends report chunks (frontend/nextjs/hooks/useWebSocket.ts:120-121), so the user sees the partial report followed by the full one. Read in the code, not reproduced.
The change. Send a message that clears the partial report before the second attempt, or replace the answer instead of appending on a retry.
To check. A provider that fails after a few chunks: the page shows one report.
-
Persona calls in deep research produce a role nobody reads
What happens. Each nested researcher in deep research (about 9 per default run) calls choose_agent on the smart model (lines 388-400). The role is used by the writer and the curator, which nested researchers do not run with the default CURATE_SOURCES=False.
The change. Pass a fixed agent and role to the nested researchers, so they skip the persona call.
To check. A default deep-research run makes about 9 fewer smart-model calls, with the same report.
-
Chat and multi-agent calls are not metered
backend/chat/chat.py:155·LP-GE-11Meter every billed token, cached and unfinished ones too · severity mediumWhat happens. The chat path calls create_chat_completion_with_tools without cost_callback, so chat costs are never counted, and the multi-agent mode has cost_callback commented out (multi_agents/agents/utils/llms.py:30).
The change. Pass cost_callback on both paths.
To check. After one chat turn, get_costs() is above zero.
The maintainers’ response
No response from the maintainers yet.
How this was made
The llm-call-audit skill read the code and wrote findings.json; nothing was run against the project’s providers. The full audit page is what leanprompt report --html writes from the same findings.
Corrections and takedown: email info@podwarden.com or open an issue.