Skip to content

Conversation

@doxav
Copy link
Contributor

@doxav doxav commented May 30, 2025

  1. Prompt template fix to prevent frequent confusions of LLM between #Variables, #Input and #Code for trainable params
  2. construct_update_dict: more robust extraction (key matching, ast type conversion, error handling)

@doxav
Copy link
Contributor Author

doxav commented May 30, 2025

The CI error is normal, it uses current CI (the new CI has been pushed in the other PR)

chinganc pushed a commit that referenced this pull request May 30, 2025
OptoPrimeMulti add async for multi candidates technique which are compatible
@chinganc
Copy link
Member

chinganc commented Jul 1, 2025

@doxav @allenanie Lets' merge this with the effort of branch opto_refactoring

@allenanie
Copy link
Member

@doxav, I created a new version of OptoPrime with more robust parsing/extraction (it's called OptoPrimeV2). Do you mind merging this to the PR I created?

@allenanie
Copy link
Member

I looked through the change -- this should be integrated into https://github.com/AgentOpt/Trace/blob/experimental/opto/trace/projections/code_projections.py

@doxav's code is more robust than what we have right now!

…ns/code_projections.py and tested with OptoPrime (modification to OptoPrime not commited)
@doxav doxav changed the base branch from main to experimental July 19, 2025 21:04
@doxav
Copy link
Contributor Author

doxav commented Jul 19, 2025

@allenanie As per your request, I adapted it to projection. I let you modify OptoPrime V1/V2 with your own strategy. I did a quick test, it worked.

My recommendations:

  • OptoPrime V1 modification/usage in _step:

    suggestion = self.extract_llm_suggestion(response)
    normalizer = SuggestionNormalizationProjection(self.parameters)
    suggestion = normalizer.project(suggestion)
    update_dict = self.construct_update_dict(suggestion)
  • OptoPrime V2 modification/usage in _step’ :

    suggestion = self.extract_llm_suggestion(response)
    normalizer = SuggestionNormalizationProjection(self.parameters)
    clean_vars = normalizer.project(suggestion['variables'])
    update_dict = self.construct_update_dict(clean_vars)

@allenanie
Copy link
Member

Thanks for the bump!!! I'll bring it up to @chinganc to see if he approves (because this is more of an aesthetic unification)

@chinganc
Copy link
Member

chinganc commented Jul 24, 2025

So this is an interesting case. Currently, projections are assigned to nodes. Each (trainable) node can have some projections and that will be used in optimizer update. See https://github.com/AgentOpt/Trace/blob/65a0309475d08232f0dd2ec4640ec43b8964306d/opto/optimizers/optimizer.py#L57

What's proposed here is different. It's a post processing step for processing the suggestion str dict of OptoPrime.
Some questions to think about..

  1. @doxav @allenanie Do you think has utilities beyond OptoPrime? if it's not obvious in the near future, we should make this an OptoPrime util. Or maybe it can be an optimizer util broadly?
  2. Does this benefit also the OptoPrimeV2 you refactored using XML? @allenanie
  3. @doxav can you give a small test case to show the errors this projection intends to fix? Thanks.

@doxav
Copy link
Contributor Author

doxav commented Jul 25, 2025

@chinganc
I just added the pytest as per your request.

A little bit of context: When I initialy created tests/llm_optimizers_tests/test_optimizer.py and tested it with local small language models (phi-4), I often got basic optimizer failures due to formatting errors or proposition to train non trainable parameters. So I applied this code in OptoPrime,converting according to their type and filtering only on trainable params, this highly raised the success rate for SLM. I then moved it to projection following Nie suggestion in PR. I think it is a good default processing, custom projections can still be applied.

… to projection (3.9 compliance and test __code)
@chinganc
Copy link
Member

chinganc commented Jul 25, 2025

@chinganc I just added the pytest as per your request.

A little bit of context: When I initialy created tests/llm_optimizers_tests/test_optimizer.py and tested it with local small language models (phi-4), I often got basic optimizer failures due to formatting errors or proposition to train non trainable parameters. So I applied this code in OptoPrime,converting according to their type and filtering only on trainable params, this highly raised the success rate for SLM. I then moved it to projection following Nie suggestion in PR. I think it is a good default processing, custom projections can still be applied.

Maybe this should be used as a generic post processor for OptoPrime. @allenanie does this help the V2? Can we apply this to also the XML output?

@allenanie
Copy link
Member

Hi @doxav, I think the optimizer v2 APIs are finally getting finalized -- I'll take a look at this PR and see how the fixes can be applied!

@doxav
Copy link
Contributor Author

doxav commented Sep 8, 2025

This should not be a projection, the initial code was to correct issue in extract_llm_suggestion and construct_update_dict which are still failing, this impacts OptoPrime / OptoPrimeV2 / OptoPrimeMulti.

I should replace by this https://github.com/doxav/NewTrace/tree/more_robust_llm_extraction and make a PR then ?

@doxav doxav closed this Sep 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants