Skip to content

Commit 5fb9efb

Browse files
thomwebbTJ Webb
andauthored
web-retriever: ask before persisting extracted data to a file (#792)
Previously web-retriever's core workflow had an unconditional step 7: always write extracted data to a file. Benchmarking against qa-kitten (same model, same tasks, only the agent differs) showed this firing even on tasks with no requested output format, silently dropping a JSON file the user never asked for. New behavior: - If the user explicitly requested a file (any format), always create it -- this takes precedence over everything else. - If the task/user already specified an inline output format (a single answer, a specific field, yes/no), answer inline -- skip file logic. - If the result is small enough to read comfortably in chat, answer inline. - Otherwise (genuinely open-ended, large/structured extraction with no explicit file request), ask via ask_user_question whether to save to a file before writing anything. ask_user_question hard-errors instead of prompting when interactive tools are unavailable (sub-agent invocation via invoke_agent, autonomous-loop mode, non-interactive/CI) -- web-retriever's primary advertised invocation path is exactly that sub-agent case, so the prompt explicitly tells the model not to retry on that error and to fall back to inline output instead. Re-verified against the exact repro case: same task/model that previously produced an unrequested file now answers inline with file_tool_calls=0. Jira: PUP-637 Co-authored-by: TJ Webb <thomas.webb@walmart.com>
1 parent 173c904 commit 5fb9efb

1 file changed

Lines changed: 29 additions & 4 deletions

File tree

code_puppy/agents/agent_web_retriever.py

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,35 @@ def get_system_prompt(self) -> str:
188188
from snapshot/locator results.
189189
6. **Paginate/crawl**: repeat navigate -> snapshot -> extract across a
190190
URL list or "next page" control as needed.
191-
7. **Persist**: write extracted data to a file the user can actually use
192-
- `create_file`/`replace_in_file` for JSON, CSV, or markdown tables,
193-
matching whatever format was requested (default to JSON if unspecified).
194-
Tell the user exactly where the file landed.
191+
7. **Confirm before persisting -- don't silently drop files on disk.**
192+
Writing an unrequested file is a surprising side effect, not a free
193+
convenience. Before calling `create_file`/`replace_in_file`, check in
194+
this order:
195+
- Did the user explicitly ask for a file (any format)? Always create
196+
it -- this wins over everything below. You may still add a brief
197+
inline summary alongside it.
198+
- Otherwise, did the user (or the task itself) already specify an
199+
inline output format -- an inline answer, a specific field to
200+
report, a yes/no, a single value? If so, just answer inline. Skip
201+
the rest of this step; don't ask, don't write a file.
202+
- Otherwise, is the result small enough to read comfortably in chat (a
203+
handful of fields, one item, a short list)? Answer inline.
204+
- Otherwise (genuinely open-ended extraction that produced a
205+
multi-row/structured result with no inline format specified and no
206+
explicit file request): try `ask_user_question` to check whether
207+
they want it saved to a file (and in what format) before writing
208+
anything. `ask_user_question` returns an error instead of prompting
209+
when interactive tools are unavailable (sub-agent invocation,
210+
autonomous-loop mode, non-interactive/CI environment) -- if you get
211+
that error, do NOT retry the call. Fall back to answering inline
212+
(report the full extracted data as text/markdown) and note briefly
213+
that you defaulted to inline output because file confirmation
214+
wasn't available.
215+
- If the user confirmed a file via `ask_user_question`, or explicitly
216+
asked for one up front, use `create_file`/`replace_in_file` for
217+
JSON, CSV, or markdown tables, matching whatever format was
218+
requested (default to JSON if unspecified). Tell the user exactly
219+
where the file landed.
195220
8. **Save the recipe**: `browser_save_workflow` after a non-trivial
196221
multi-step scrape/automation succeeds, so the next run doesn't start
197222
from zero. Name workflows descriptively (include the domain and goal).

0 commit comments

Comments
 (0)