oss-fuzz-gen icon indicating copy to clipboard operation
oss-fuzz-gen copied to clipboard

Add chat history logging to Prototyper

Open myanvoos opened this issue 8 months ago • 1 comments

Related issue #969

This PR adds chat history logging to the Prototyper agent (and Enhancer as well, since Enhancers inherit from Prototypers). Unlike the initial suggestion in the issue, I thought it'd be more appropriate to put the chat history adding logic in execute instead of _container_handle_conclusion because it's the main orchestration method.

myanvoos avatar Apr 11 '25 03:04 myanvoos

Hey @DonggeLiu, thanks for the comments! And no worries, I did mean this to be a draft PR for more discussion (I'll mark them as draft properly in the future) ^^

What I've done is I made this function in base_agent.py

def _format_chat_history_line(self, cur_round: int, prompt_or_response: str, 
                                agent_type: str, content: str) -> str:
    """Formats a chat history line."""
    return (f'Round {cur_round:02d}: <{agent_type.upper()} {prompt_or_response.upper()}:ROUND {cur_round:02d}>\n'
            f'{content}\n'
            f'</{agent_type.upper()} {prompt_or_response.upper()}:ROUND {cur_round:02d}>\n')

So that in prototyper.py we can call

build_result.chat_history[self.name] += self._format_chat_history_line(
            cur_round, 'PROMPT', self.name, prompt.get())

build_result.chat_history[self.name] += self._format_chat_history_line(
            cur_round, 'RESPONSE', self.name, response)

And deleted the redundant line in cloud_builder.py.

I included self.name in the line to make it easier to know which agent is at any prompt or response when reading the logs i.e. <PROTOTYPER PROMPT:ROUND 02>

Is this kind of what you were thinking of?

myanvoos avatar Apr 11 '25 07:04 myanvoos