This was not urgent but…
It’s just fun, and I kinda like the approach… And easy, too!
LLMs are impressive, no question – and yet they also are not great, they hallucinate, they can be prompt injected, environment, geopolitics, education, cybersecurity, etc. all sorts of impacts.
But let’s assume for a second, for some of the above aspects, local inference has some advantages. Then in such scenario there is a relevant drawback: Model capability. Large models don’t easily fit on limited computing power.
Small models are generally less capable. But as hinted last week, maybe that doesn’t mean they are necessarily bad.
Let’s do a very quick exercise, building on last week’s (also easy) entry.
Adding capabilities to a small model
The approach: One way to compensate for limited small-language-model capabilities could be, to an extent, to add tools on top of the model. Tools that take care of some more (complicated or not) operations.
Very easy code: We define a function (simplistic example) and then register that as a tool to be called by a language model, through {ellmer}.
add <- function(x, y) {
sum(x, y)
}
tool_add <- tool(
add,
name = "add",
description = "Add two numbers together",
arguments = list(
x = type_number("First number to add"),
y = type_number("Second number to add")
)
)
chat$register_tool(tool_add)
chat$chat("Sum the following two numbers: 3 and 7.8")And that’s it!

Or look at it this way: Let’s not rely on the model for some operations we can ensure are executed correctly with a function of our choosing (whether you call that “skills” or “tools” I would argue doesn’t really matter here).
As shown, this is easy with {ellmer}. And even though it’s a small model, it makes the right choice if the queries are simple…

The potential issue?
Maybe, just maybe, for complex stuff, the “SLM” misses the point and fails to call a tool.
I’m expecting that might be more of an issue for unclear things, or too big conversations where the window somehow fails to keep the tool call in context. I don’t know. I don’t often have such needs.
And I don’t mean to say this little exercise, of an SLM + tools is a perfect (or even good enough) replacement for a frontier LLM with a great harness and modern MCP-served capabilities… Of course not.
But it is not an uninteresting exercise. And for simple stuff, with no ill intent, it does work nicely for simple contexts. Intent is caught indeed.

Less easy: generating images…
So imagine you want to generate plots… How do we get the chatbot to play nice with that?
It’s been a bit more involved. {ellmer} won’t simply return images, AFAICT. So I had to create a tool that generates an image and returns a path, to a PNG file. Then you can load the PNG in R. That might just do the trick for a Shiny App or a Quarto document, but… Well, I have a hard time imagining embedding a chatbot in a Quarto document generation…
Anyhow. Can be done? Yes. I did find it a bit more involved.
(Actually, one can cheat: just return a plot. The chatbot will complain, but then R will generate the plot… Curious…)
I’d have to look further into this, but it’s really not an actual need I have for now… After all, we have a “language” model interface… IDK. Not too important for now.
One last note: Reading images
It’s actually fun:

It’s not perfect though, if I ask for y value for x=-10 or 0, it makes stuff up… Oh well…
Conclusions
Really fun indeed, today.
And yet maybe this approach can help make a small local model more useful. Even quite powerful I’d say. While I haven’t done extensive testing or tried many complicated tools, at least the first few tests seem to work…
So could I use this with… RLCS? 🧐 Probably!
But actually I should stop playing around and go back to some PhD tasks I have (quite a few of them…).
Resources
Tool creation/registering in {ellmer}, which I used for today’s example
https://cran.r-project.org/web//packages/ellmer/vignettes/tool-calling.html