You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Not respecting the EVOLVE-BLOCK-START / END markers #106
I'm finding that open evolve isn't respecting the EVOLVE-BLOCK-START and EVOLVE-BLOCK-END markers as it evolves the initial_program.py into subsequent versions. Anybody else seeing this behavior? I suppose I need to look into what enforces the constraint.
I'm using my own config to evolve an agent to solve simple RL environments, and I do have allow_full_rewrites: true in my config. I'll try setting it to false.
Lol. I'm working to evolve simple agents to solve simple RL environments, but as it's not respecting the start-end blocks it's learned that it can modify its own reward function! So canonical reward hacking at its best:)
I've got openai.py modified to allow access to some other privately hosted models. Does the current configuration depend on
just instructing/asking the LLM to respect the begin/end markers? If so, perhaps the models I'm querying aren't playing nice.
I cannot reproduce it with your files, see the attached output folder. Did you try with the latest version of the code? Or do you see the issue appear only after a certain number of iterations?
I suspect that the root cause is that we're depending on the LLM to play nice, rather than enforcing the constraint. I've got some code that does so which I am testing.
Yeah it would be interesting to see what happens if we just flat out don't allow any edits outside the markers, meaning if it tried to like put a function there its code would fail.
So I put in place code to revert everything before and after the evolve start/end comments back to the initial code. Also it prints a diff in stdout when the llm attempts to edit code outside the comments, which it continues to do.
However. I then added a line to the system prompts (in config.yaml) like so:
You must only perform edits between the # EVOLVE-BLOCK-START and # EVOLVE-BLOCK-END comments. This constraint is checked and enforced, so any edits you make outside of these blocks will be reverted to the initial program.
And it stopped attempting to write outside the comment blocks. So, one could perhaps just add that line to the system prompt and that may convince the LLM that it's not worth trying. But it certainly could still make improper edits if it decided to.
(I'm using diffs rather than whole file rewrites.)
What happens if i have a function or more function calls in the evolve block? Do i need to include them in the evolve-block-start and end sentence or not?
What happens if i have a function or more function calls in the evolve block? Do i need to include them in the evolve-block-start and end sentence or not?
You can have functions within the blocks. Just that they may be rewritten or completed removed. Just need to ensure that the parts you do not want to be evolved are outside the block.
I found that the LLMs are quite happy to write code outside of defined functions that runs when the file is imported. Particularly, in the context of the text-based Taxi reinforcement learning game it defined a random Q table and an instance of the Taxi game, trained the Q table for 2000 games, and then during normal execution, referenced the Q table object to convert incoming observations to actions!
The "You must only perform edits between the # EVOLVE-BLOCK-START and # EVOLVE-BLOCK-END comments. This constraint is checked and enforced, so any edits you make outside of these blocks will be reverted to the initial program" works generally pretty well when optimizing for anything except shortness of code, in which it just has no impact. There's gotta be a better solution here.
Activity
codelion commentedon Jun 24, 2025
What config did you use? earlier there was a allow_full_rewrite config that was causing problems I have removed it now.
robertmash2 commentedon Jun 24, 2025
I'm using my own config to evolve an agent to solve simple RL environments, and I do have
allow_full_rewrites: truein my config. I'll try setting it to false.robertmash2 commentedon Jun 24, 2025
Thing is, when I search the repo on Github, I don't see any calls to
parse_evolve_blocksinopenevolve/utils/code_utils.py.robertmash2 commentedon Jun 24, 2025
(Setting
allow_full_rewrites: falsedoes fix the problem though. Thanks for that.)AriKorpus commentedon Jun 26, 2025
I'm still having this issue even with allow_full_rewrites set to false
codelion commentedon Jun 26, 2025
What's your config.yaml? which model are you using?
robertmash2 commentedon Jun 26, 2025
Lol. I'm working to evolve simple agents to solve simple RL environments, but as it's not respecting the start-end blocks it's learned that it can modify its own reward function! So canonical reward hacking at its best:)
AriKorpus commentedon Jun 26, 2025
@codelion Config.yaml is pretty standard stuff with diff based on and full rewrites off, using gemini flash 2.5 - It's for a custom project
robertmash2 commentedon Jun 26, 2025
I've got openai.py modified to allow access to some other privately hosted models. Does the current configuration depend on
just instructing/asking the LLM to respect the begin/end markers? If so, perhaps the models I'm querying aren't playing nice.
codelion commentedon Jun 26, 2025
Yes, I will need to see the initial program and config to be able to reproduce the issue. I haven’t had this issue in the examples after removing the allow_full_rewrites config - cfb3022#diff-463219ee5ff29defd64e3ccdec7940e9660053d4d04096075577cfe3416c694f
AriKorpus commentedon Jun 26, 2025
For my situation, I have attached my config and other relevant files. Thanks!
https://drive.google.com/drive/folders/1sInd8Zri67qtyztvDoMPpQQXTkFAhefb
codelion commentedon Jun 27, 2025
I cannot reproduce it with your files, see the attached output folder. Did you try with the latest version of the code? Or do you see the issue appear only after a certain number of iterations?
openevolve_output.zip
AriKorpus commentedon Jun 29, 2025
I must have forgotten to upgrade openevolve, just redownloaded, and the issue is solved. My bad, and sorry for wasting your time!
AriKorpus commentedon Jun 30, 2025
For some reason the same issue has reemerged for me, but only when using openai model (i.e, o4-mini). Weird...
robertmash2 commentedon Jul 1, 2025
I suspect that the root cause is that we're depending on the LLM to play nice, rather than enforcing the constraint. I've got some code that does so which I am testing.
I'm using gpt4o and mini too.
AriKorpus commentedon Jul 1, 2025
Yeah it would be interesting to see what happens if we just flat out don't allow any edits outside the markers, meaning if it tried to like put a function there its code would fail.
robertmash2 commentedon Jul 1, 2025
So I put in place code to revert everything before and after the evolve start/end comments back to the initial code. Also it prints a diff in stdout when the llm attempts to edit code outside the comments, which it continues to do.
However. I then added a line to the system prompts (in config.yaml) like so:
And it stopped attempting to write outside the comment blocks. So, one could perhaps just add that line to the system prompt and that may convince the LLM that it's not worth trying. But it certainly could still make improper edits if it decided to.
(I'm using diffs rather than whole file rewrites.)
luciangorie commentedon Jul 2, 2025
What happens if i have a function or more function calls in the evolve block? Do i need to include them in the evolve-block-start and end sentence or not?
codelion commentedon Jul 2, 2025
You can have functions within the blocks. Just that they may be rewritten or completed removed. Just need to ensure that the parts you do not want to be evolved are outside the block.
robertmash2 commentedon Jul 2, 2025
I found that the LLMs are quite happy to write code outside of defined functions that runs when the file is imported. Particularly, in the context of the text-based Taxi reinforcement learning game it defined a random Q table and an instance of the Taxi game, trained the Q table for 2000 games, and then during normal execution, referenced the Q table object to convert incoming observations to actions!
AriKorpus commentedon Jul 3, 2025
The "You must only perform edits between the # EVOLVE-BLOCK-START and # EVOLVE-BLOCK-END comments. This constraint is checked and enforced, so any edits you make outside of these blocks will be reverted to the initial program" works generally pretty well when optimizing for anything except shortness of code, in which it just has no impact. There's gotta be a better solution here.
luciangorie commentedon Jul 7, 2025
C:\Users\ALESSA
1\AppData\Local\Temp\tmpw_23qpfq.cpp:450:11: error: invalid preprocessing directive #EVOLVE1\AppData\Local\Temp\tmpw_23qpfq.cpp:632:3: error: invalid preprocessing directive #EVOLVE450 | # EVOLVE-BLOCK-START
| ^~~~~~
C:\Users\ALESSA
632 | # EVOLVE-BLOCK-END
| ^~~~~~
, ta_value=0.0000
-- and what happens if i do not put flags?
Report unapplied diffs and add opt-in EVOLVE-BLOCK enforcement
Reject malformed diffs, report unapplied diffs, opt-in EVOLVE-BLOCK e…