gptme icon indicating copy to clipboard operation
gptme copied to clipboard

Show working directory before saving files

Open Miyou opened this issue 10 months ago • 2 comments

I had an agent running and told it to make some edits in another folder. It used cd, then I told it to write some files to its own workspace but both it and I forgot that it had cd'd away from its workspace. Perhaps showing the current working directory on each file save prompt could be useful?

Miyou avatar Jan 29 '25 14:01 Miyou

Anthropic has suggested that the solution to this is to always use absolute paths...

While building our agent for SWE-bench, we actually spent more time optimizing our tools than the overall prompt. For example, we found that the model would make mistakes with tools using relative filepaths after the agent had moved out of the root directory. To fix this, we changed the tool to always require absolute filepaths—and we found that the model used this method flawlessly.

I've considered adding it to the system prompt and optimizing for such use by returning full paths wherever we provide one.

ErikBjare avatar Jan 29 '25 17:01 ErikBjare

I now mention a preference for absolute paths it in the system prompt: https://github.com/ErikBjare/gptme/commit/ba11552a7d6febd36223a4e35e438e777646b226

Some tools should probably be updated to return absolute paths instead of relative ones.

Maybe also inject the current working directory in a ephemeral context message (we used to do something like this) before the last user/assistant message so that it can easily/reliably construct correct paths from relative dir output (like ls, find).

ErikBjare avatar Feb 07 '25 11:02 ErikBjare

The shell tool now outputs a line about any working directory change after running a command: https://github.com/gptme/gptme/pull/534

This significantly improved things. I suppose it's wasn't prompted well enough about the statefulness of path changes (might think its a subshell, for example), this makes it clear.

ErikBjare avatar Jun 04 '25 12:06 ErikBjare