Skip to content

Commit 8ba270e

Browse files
committed
add section to the tutorial on tool calling
1 parent 4d912a1 commit 8ba270e

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

docs/tutorial.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
- [Chapter 9: Interoperability with Other Frameworks](#chapter-9-interoperability-with-other-frameworks)
2121
- [Chapter 10: Prompt Engineering for Mellea](#chapter-10-prompt-engineering-for-m)
2222
- [Custom Templates](#custom-templates)
23+
- [Chapter 11: Tool Calling](#chapter-11-tool-calling)
2324
- [Appendix: Contributing to Melles](#appendix-contributing-to-mellea)
2425

2526
## Chapter 1: What Is Generative Programming
@@ -1281,6 +1282,33 @@ To customize the template and template representation of an existing class, simp
12811282

12821283
See [`mellea/docs/examples/mify/rich_document_advanced.py`](./examples/mify/rich_document_advanced.py)
12831284

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+
12841312
## Appendix: Contributing to Mellea
12851313

12861314
### Contributor Guide: Requirements and Verifiers

0 commit comments

Comments
 (0)