Extending Optimizers
Extend Opik with custom optimization algorithms and contributions.
Opik Agent Optimizer is designed to be a flexible framework for prompt and agent optimization. While it provides a suite of powerful built-in algorithms, you might have unique optimization strategies or specialized needs. This guide discusses how you can conceptually think about building your own optimizer logic that integrates with Opik’s evaluation ecosystem and how you can contribute to the broader Opik Agent Optimizer project.
Currently, direct inheritance and registration of custom optimizer classes into the opik-optimizer
SDK by end-users is not a formally exposed feature. This guide provides a conceptual overview for advanced users and potential future development or contributions.
Core Concepts for a Custom Optimizer
If you were to design a new optimization algorithm to work within Opik’s ecosystem, it would typically need to interact with several key components:
-
Task Definition (
TaskConfig
): Your optimizer would take aTaskConfig
object as input. This defines what needs to be optimized (theinstruction_prompt
), how inputs are mapped (input_dataset_fields
), and what the target output is (output_dataset_field
). -
Evaluation Mechanism (
MetricConfig
& Dataset): Your optimizer would need a way to score candidate prompts. This is achieved by using aMetricConfig
(specifying the metric and its inputs) and an evaluationdataset
.- Internally, your optimizer would likely call an evaluation function repeatedly, passing different generated prompts to be scored against the dataset samples based on the
MetricConfig
.
- Internally, your optimizer would likely call an evaluation function repeatedly, passing different generated prompts to be scored against the dataset samples based on the
-
Optimization Loop: This is the heart of your custom optimizer. It would involve:
- Candidate Generation: Logic for creating new prompt variations. This could be rule-based, LLM-driven, or based on any other heuristic.
- Candidate Evaluation: Using the
MetricConfig
anddataset
to get a score for each candidate. - Selection/Progression: Logic to decide which candidates to keep, refine further, or how to adjust the generation strategy based on scores.
- Termination Condition: Criteria for when to stop the optimization (e.g., number of rounds, score threshold, no improvement).
-
Returning Results (
OptimizationResult
): Upon completion, your optimizer should ideally structure its findings into anOptimizationResult
object. This object standardizes how results are reported, including the best prompt found, its score, history of the optimization process, and any other relevant details.
Conceptual Structure of an Optimizer
While the exact implementation would vary, a custom optimizer might conceptually have methods like:
The opik-optimizer
SDK already provides robust mechanisms for prompt evaluation that existing optimizers leverage. A custom optimizer would ideally reuse or adapt these internal evaluation utilities to ensure consistency with the Opik ecosystem.
How to Contribute to Opik Agent Optimizer
Opik is continuously evolving, and community feedback and contributions are valuable!
- Feature Requests & Ideas: If you have ideas for new optimization algorithms, features, or improvements to existing ones, please share them through our community channels or by raising an issue on our GitHub repository (if available for
opik-optimizer
). - Bug Reports: If you encounter issues or unexpected behavior, detailed bug reports are greatly appreciated.
- Use Cases & Feedback: Sharing your use cases and how Opik Agent Optimizer is (or isn’t) meeting your needs helps us prioritize development.
- Code Contributions: While direct pull requests for new optimizers might require significant coordination if the SDK isn’t fully open for such extensions yet, expressing interest and discussing potential contributions with the development team is a good first step. Keep an eye on the project’s contribution guidelines.
Key Takeaways
- Building a new optimizer involves defining a candidate generation strategy, an evaluation loop using Opik’s
MetricConfig
anddataset
paradigm, and a way to manage the optimization process. - The
TaskConfig
andOptimizationResult
objects are key for integration. - While the SDK may not formally support pluggable custom optimizers by third parties at this moment, understanding these design principles is useful for advanced users and potential future contributions.
We encourage you to explore the existing optimizer algorithms to see different approaches to these challenges.