# Run optimization
result = optimizer.optimize_prompt(
    prompt=research_prompt,
    dataset=research_dataset,
    metric=research_quality_metric,
    n_samples=100,
    max_rounds=5
)

print("Optimized prompt with tools:")
print(result.prompt)
```

## Best Practices for Tool Optimization

### 1. Tool Schema Design

* **Clear descriptions** - Provide detailed descriptions for each tool
* **Comprehensive parameters** - Include all necessary parameters with types
* **Example usage** - Add examples in tool descriptions when helpful
* **Error handling** - Define expected error conditions and responses

### 2. Prompt Structure

* **Tool introduction** - Clearly explain available tools to the model
* **Usage guidelines** - Provide specific instructions on when and how to use tools
* **Output formatting** - Specify how tool outputs should be processed
* **Fallback instructions** - Define what to do when tools fail

### 3. Evaluation Considerations

* **Tool usage metrics** - Measure not just final output quality but tool usage effectiveness
* **Multi-step evaluation** - Evaluate each step in tool-based workflows
* **Error rate tracking** - Monitor tool failure rates and recovery strategies
* **Context preservation** - Ensure important context is maintained across tool calls

## Limitations and Considerations

### Current Limitations

* **MetaPrompt Only** - Tool optimization is currently only available with the MetaPrompt Optimizer
* **Tool Complexity** - Very complex tool workflows may require manual optimization
* **Tool Availability** - Optimization assumes tools are available during evaluation
* **Schema Changes** - Tool schema modifications may require re-optimization

### Performance Considerations

* **Evaluation Cost** - Tool-enabled prompts require more LLM calls for evaluation
* **Tool Latency** - External tool calls can slow down optimization
* **Resource Usage** - Complex tool workflows may require significant computational resources

## Future Roadmap

Tool optimization is an active area of development. Planned improvements include:

* **Multi-optimizer support** - Extending tool optimization to other optimizers
* **Tool-specific metrics** - Specialized evaluation metrics for tool usage
* **Automated tool discovery** - Automatic detection and optimization of tool patterns
* **Tool performance optimization** - Optimizing not just prompts but tool usage efficiency

## Getting Started

To start optimizing tool-enabled prompts:

1. **Choose MetaPrompt Optimizer** - Currently the only optimizer supporting tool optimization
2. **Define your tools** - Create clear tool schemas with comprehensive descriptions
3. **Structure your prompt** - Include clear instructions for tool usage
4. **Prepare evaluation data** - Ensure your dataset includes tool usage scenarios
5. **Run optimization** - Use the standard optimization process with tool-enabled prompts

<Info>
  **Need Help?**

  For questions about tool optimization or to request support for additional optimizers, please reach out
  on [GitHub](https://github.com/comet-ml/opik/issues) or check the [MetaPrompt Optimizer
  documentation](/agent_optimization/algorithms/metaprompt_optimizer) for detailed configuration options.
</Info>

## References

* [MetaPrompt Optimizer Documentation](/agent_optimization/algorithms/metaprompt_optimizer)
* [Model Context Protocol Specification](https://modelcontextprotocol.io/)