|
20 | 20 | - [Chapter 9: Interoperability with Other Frameworks](#chapter-9-interoperability-with-other-frameworks) |
21 | 21 | - [Chapter 10: Prompt Engineering for Mellea](#chapter-10-prompt-engineering-for-m) |
22 | 22 | - [Custom Templates](#custom-templates) |
| 23 | +- [Chapter 11: Tool Calling](#chapter-11-tool-calling) |
23 | 24 | - [Appendix: Contributing to Melles](#appendix-contributing-to-mellea) |
24 | 25 |
|
25 | 26 | ## Chapter 1: What Is Generative Programming |
@@ -1281,6 +1282,33 @@ To customize the template and template representation of an existing class, simp |
1281 | 1282 |
|
1282 | 1283 | See [`mellea/docs/examples/mify/rich_document_advanced.py`](./examples/mify/rich_document_advanced.py) |
1283 | 1284 |
|
| 1285 | +## Chapter 11: Tool Calling |
| 1286 | +Mellea supports tool calling for providers/models that support it. Most session level functions support setting a tool_calls boolean. Setting this to true allows tools to be called, but there's no guarantee that a model will call them. |
| 1287 | + |
| 1288 | +Tools can be made available for the model to call in a few ways: |
| 1289 | +1. Components: components can have a TemplateRepresentation object that contains tools. |
| 1290 | +2. Context: depending on the context, the components in that context can be used as sources of additional tools in the exact same way they would if they were the current action. |
| 1291 | +3. `ModelOptions.TOOLS`: model options can include a tools parameter. The preferred way of passing these tools is as a list of function objects. |
| 1292 | + |
| 1293 | +Currently, tools are identified by the name of the function. If there are conflicts, the most recent tool with that name will be preferred. This means the tools available to the model will have the same priority listed above: |
| 1294 | +1. Tools from the current component will always be included |
| 1295 | +2. Tools from the context will be included if there are no name conflicts. A given context can decide what tools to surface, but in most cases, tools from the most recent component in the context will take priority over tools from older requests. |
| 1296 | +3. Tools from `ModelOptions.TOOLS` will only be added if they do not conflict with any of the above functions. |
| 1297 | + |
| 1298 | +For examples on adding tools to the template representation of a component, see the `Table` object in [richdocument.py](../mellea/stdlib/docs/richdocument.py). |
| 1299 | + |
| 1300 | +Here's an example of adding a tool through model options. This can be useful when you want to add a tool like web search that should almost always be available: |
| 1301 | +```python |
| 1302 | +from mellea.backends.types import ModelOption |
| 1303 | + |
| 1304 | +def web_search(query: str) -> str: |
| 1305 | + ... |
| 1306 | + |
| 1307 | +model_opts = { |
| 1308 | + ModelOptions.TOOLS: [web_search] |
| 1309 | +} |
| 1310 | +``` |
| 1311 | + |
1284 | 1312 | ## Appendix: Contributing to Mellea |
1285 | 1313 |
|
1286 | 1314 | ### Contributor Guide: Requirements and Verifiers |
|
0 commit comments