---
title: "Comment by Ahmet Özel on \"Run AI Locally on Your Mac with Ollama: Chat, Tools, RAG and a Custom Model (Real Numbers from a Mac mini M4)\" | Hashnode"
description: "The tool loop is the part I would adjust before adding the second function from your examples. The displayed snippet calls get_disk_free() for every tool call,"
url: "https://hashnode.com/posts/run-ai-locally-on-your-mac-with-ollama-chat-tools-rag-and-a-custom-model-real-numbers-from-a-mac-mini-m4/6ac345cb6485b2d515e70eea/comment/6ac39bc0431f4fd6048d0b28"
---

[Discussion](https://hashnode.com/posts/run-ai-locally-on-your-mac-with-ollama-chat-tools-rag-and-a-custom-model-real-numbers-from-a-mac-mini-m4/6ac345cb6485b2d515e70eea)

Comment [Run AI Locally on Your Mac with Ollama: Chat, Tools, RAG and a Custom Model (Real Numbers from a Mac mini M4)](https://hashnode.com/posts/run-ai-locally-on-your-mac-with-ollama-chat-tools-rag-and-a-custom-model-real-numbers-from-a-mac-mini-m4/6ac345cb6485b2d515e70eea)

[Ahmet Özel](https://hashnode.com/@ahmetozel)

[Oct 5](https://hashnode.com/posts/run-ai-locally-on-your-mac-with-ollama-chat-tools-rag-and-a-custom-model-real-numbers-from-a-mac-mini-m4/6ac345cb6485b2d515e70eea/comment/6ac39bc0431f4fd6048d0b28)

The tool loop is the part I would adjust before adding the second function from your examples. The displayed snippet calls get\_disk\_free() for every tool call, regardless of the requested function name. That works for the single-tool demonstration, but a request for system memory would need a different dispatch path.

A small function-name-to-handler mapping, with arguments validated for the selected handler, would make that extension explicit. I would also append response.message once before iterating over its tool calls, then append each tool result separately. Otherwise a response containing multiple calls repeats the same assistant message in the conversation history.

[RainyTech](https://hashnode.com/@rainytechlab)

[Oct 6](https://hashnode.com/posts/run-ai-locally-on-your-mac-with-ollama-chat-tools-rag-and-a-custom-model-real-numbers-from-a-mac-mini-m4/6ac345cb6485b2d515e70eea/comment/6ac39bc0431f4fd6048d0b28#reply-6ac4ec29bba31b46e154237b)

Good catch, thank you! You're right: I shortened the loop for the article, and that version always calls `get_disk_free()` and re-appends the assistant message for every call. The code in the repo does it your way: a `TOOLS` dict mapping each name to its function, `response.message` appended once, then `TOOLS[call.function.name](**call.function.arguments)` for each call. It doesn't validate arguments yet, so I'll add that and fix the snippet in the article. The full version is tools.py in the GitHub repo linked at the top of the post.

[Ahmet Özel](https://hashnode.com/@ahmetozel)

[Oct 6](https://hashnode.com/posts/run-ai-locally-on-your-mac-with-ollama-chat-tools-rag-and-a-custom-model-real-numbers-from-a-mac-mini-m4/6ac345cb6485b2d515e70eea/comment/6ac39bc0431f4fd6048d0b28#reply-6ac538ec0c735b2dd8efe4d7)

Thanks for separating the article snippet from the repository implementation. My criticism applies to the displayed loop, and the mapping plus single assistant-message append in the full version already addresses those two issues.

For argument validation, I would reject unknown tool names and unexpected fields before invoking a handler, then return a structured tool error tied to that call. A regression with two different calls in one response would check dispatch, result ordering and conversation history together, while a malformed argument case checks that neither handler runs accidentally.

[RainyTech](https://hashnode.com/@rainytechlab)

[Oct 8](https://hashnode.com/posts/run-ai-locally-on-your-mac-with-ollama-chat-tools-rag-and-a-custom-model-real-numbers-from-a-mac-mini-m4/6ac345cb6485b2d515e70eea/comment/6ac39bc0431f4fd6048d0b28#reply-6ac7821864c340e4de511305)

Thanks, that part is done now. tools.py in the repo and the snippet in the article both look the tool up with `TOOLS.get(name)` and check the argument names against the function's signature (`inspect.signature`) before running anything. An unknown tool or an unexpected field never reaches a handler. It goes back to the model as the tool message for that call.

To be honest, two things aren't there yet. The error is still a plain string, not a structured object. And the check only catches extra fields, not missing required ones. Neither function takes arguments right now, so that hasn't come up yet. There are no tests either. The two-call case was only checked by hand in the video run: one response asked for get\_disk\_free and get\_memory, and both results came back in order (150 GB disk free, 61% of 16 GB memory free). Your two regression cases are a good checklist for when I add a tool that takes arguments.

[Ahmet Özel](https://hashnode.com/@ahmetozel)

[Oct 9](https://hashnode.com/posts/run-ai-locally-on-your-mac-with-ollama-chat-tools-rag-and-a-custom-model-real-numbers-from-a-mac-mini-m4/6ac345cb6485b2d515e70eea/comment/6ac39bc0431f4fd6048d0b28#reply-6ac8870e2881eaeaece2c13e)

The updated snippet now has the dispatch boundary the article needed. For missing required arguments, inspect.signature(handler).bind(\*\*arguments) can check both missing and unexpected names before the handler is invoked; a TypeError becomes a result for that particular tool call.

That is still argument binding, not type validation, so it should not claim to validate annotated value types. A tiny test handler with one required argument would expose the current missing-field gap even though get\_disk\_free and get\_memory accept none. The two-call test can then assert that only the valid handler ran.

[RainyTech](https://hashnode.com/@rainytechlab)

[Oct 13](https://hashnode.com/posts/run-ai-locally-on-your-mac-with-ollama-chat-tools-rag-and-a-custom-model-real-numbers-from-a-mac-mini-m4/6ac345cb6485b2d515e70eea/comment/6ac39bc0431f4fd6048d0b28#reply-6ace1e489552445c96d30119)

Thanks, `signature(handler).bind(**arguments)` is a neat way to catch both missing and unexpected arguments in one step. And fair point that it's argument binding, not type validation. A test handler with one required argument would expose the gap nicely.

[Ahmet Özel](https://hashnode.com/@ahmetozel)

[Oct 15](https://hashnode.com/posts/run-ai-locally-on-your-mac-with-ollama-chat-tools-rag-and-a-custom-model-real-numbers-from-a-mac-mini-m4/6ac345cb6485b2d515e70eea/comment/6ac39bc0431f4fd6048d0b28#reply-6ad13c5b7a125a4ea87ff5b5)

The required-argument fixture can stay independent of the actual disk and memory tools. Give the fake handler a call counter, submit one missing-argument call followed by a valid call, and assert that only the latter increments it.

That checks a useful recovery property too: rejecting one tool call should not prevent valid sibling calls from producing their own results. Keep the call identifiers in those results so the model can associate the validation error and successful output with the right requests.
