A report prompt names the section first, so each section pays for it again

A long row of ledger books, each with a loose paper tag on its cover, stands beside an unused rubber stamp.

Cache never hits Reported

A multi-agent simulation and report engine on any OpenAI-compatible model; its JSON path already checks for cut-off answers and retries once.

≈ 9,000 tokens per 1,000 runs, prompt tokens the cache could have served across report sections estimate

Estimates, not measurements. Every figure on this page is an estimate from reading the code, not a measurement of the app in use.

Repository
666ghj/MiroFish
Commit audited
7657031
leanprompt version
0.1.0-dev.15
Audit date
Status
The maintainers have been told about this audit; no response yet.
Maintainers
the issue
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.

leanprompt read the code at commit 7657031 and found 2 places where its LLM calls could use fewer tokens, plus 3 other problems, not scored. Static score: 96 of 100 (an estimate from the findings). The code may have changed since.

Findings

  1. LP-PC-03 No ids, timestamps, versions or paths at the top of the prompt

    backend/app/services/report_agent.py:622 · severity medium · saves prefill

    What happens. The section-writing system prompt names the section being written on line 622, before about 3,000 tokens of instructions and the tool list that are the same for every section. Each section therefore starts with a different prompt, and the provider cannot reuse the shared text from the previous section.

    The change. Remove the section title from the system prompt template. The user prompt template already names the section (line 780), so nothing is lost. Keep the report title, summary and scenario lines where they are.

    Why it helps. The first call of every section after the first pays full price for about 3,000 tokens it paid for a minute earlier. The later calls inside one section already share the prompt.

    Estimate about 9,000 uncached prompt tokens per report (estimate)

    Assumptions. 3 of 4 sections miss the cache, 3,000 tokens of static text after the title (about 3,150 characters of Chinese plus the tool list); qwen-plus implicit cache (1,024-token minimum per the Alibaba table) or OpenAI automatic caching; share is of the report path only (about 22 calls, 9,000 prompt tokens each), not the simulation calls made through camel-ai, which were not read.

    Who reaches this. every report with 2 or more sections

  2. LP-PD-06 Compact serialisation for data in the prompt

    backend/app/services/zep_tools.py:1599 · severity low · saves prefill · size is assumed

    What happens. The agent-selection prompt lists every simulated agent with json.dumps(indent=2), so each interested_topics entry goes on its own indented line.

    The change. Use separators=(',', ':') and no indent, or one line per agent.

    Why it helps. Line breaks and indentation are tokens; with 100 agents it adds roughly a fifth to the list.

    Estimate about 2,200 prompt tokens per interview_agents call at 100 agents (estimate)

    Assumptions. 100 agents at about 110 tokens each, 20 percent whitespace overhead, one interview_agents call per report.

    How big. how many agents a typical simulation has; the cost scales with it

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.

  1. chat() never reads the finish reason, so a cut-off report section is saved as finished

    backend/app/utils/llm_client.py:156 · LP-GE-12 Read the finish reason before using an answer · severity high

    What happens. chat() returns the cleaned text without looking at finish_reason. The report section loop calls it with max_tokens=4096 (report_agent.py:1344 and :1550) and stores any answer as the section, so a section that hit the limit is written as complete.

    The change. Raise on finish_reason == 'length' in chat(), as chat_json() already does at line 242.

    In progress. Open PR 'never save an empty report section from an unusable LLM response' makes chat() reject length stops and drops the cap on retry. https://github.com/666ghj/MiroFish/pull/841

    To check. Mock a completion with finish_reason 'length' and check chat() raises.

  2. Interview summary is capped at 800 tokens but asked to be up to 1000 characters

    backend/app/services/zep_tools.py:1727 · LP-GE-12 Read the finish reason before using an answer · severity medium

    What happens. The prompt says the summary must stay within 1000 characters (line 1704) but the call sends max_tokens=800. A thousand Chinese characters is more than 800 tokens, so a full-length summary is cut mid-sentence, and chat() does not check the finish reason, so the cut text goes into the report as a tool result.

    The change. Raise the cap to about 2,000 tokens (or word the limit in tokens), and check the finish reason (see the chat() note).

    Why it matters. A truncated summary of the interviews is what the report writer then quotes from.

    To check. Feed 10 interview answers of 500 characters each and check the summary ends on a full stop and finish_reason is stop.

  3. Cut-off persona and config JSON is closed with brackets and accepted

    backend/app/services/oasis_profile_generator.py:589 · LP-GE-12 Read the finish reason before using an answer · severity medium

    What happens. When finish_reason is length the code closes the open strings and brackets (_fix_truncated_json) and parses the result as a complete persona. The same pattern is in simulation_config_generator.py:460. A persona cut in the middle becomes a shorter persona with no warning beyond a log line, and in the config version the agents after the cut are likely to fall back to rule-based defaults without a warning.

    The change. On length, retry once (the bounded retry already exists in the loop) or fall back to the rule-based profile, rather than repairing and returning. For the config batch, check that every agent_id of the batch is present before accepting.

    Why it matters. The simulation then runs on truncated personas and partial configs that look valid.

    To check. Mock a length stop mid-persona and check the generator retries or falls back instead of returning the repaired text.

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.