From 9fd908bb7112eb4e2aaee84f8a0b99c3fffe0055 Mon Sep 17 00:00:00 2001 From: twosom Date: Mon, 15 Sep 2025 22:57:50 +0900 Subject: [PATCH] docs: add documentation for client-managed tool calls --- docs/docs/apis-generate/chat-with-tools.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/docs/docs/apis-generate/chat-with-tools.md b/docs/docs/apis-generate/chat-with-tools.md index e7646aa..edc1dc4 100644 --- a/docs/docs/apis-generate/chat-with-tools.md +++ b/docs/docs/apis-generate/chat-with-tools.md @@ -29,6 +29,18 @@ session. The tool invocation and response handling are all managed internally by This tool calling can also be done using the streaming API. +### Client-managed tool calls (clientHandlesTools) + +By default, ollama4j automatically executes tool calls returned by the model during chat, runs the corresponding registered Java methods, and appends the tool results back into the conversation. For some applications, you may want to intercept tool calls and decide yourself when and how to execute them (for example, to queue them, to show a confirmation UI to the user, to run them in a sandbox, or to perform multi‑step orchestration). + +To enable this behavior, set the clientHandlesTools flag to true on your OllamaAPI instance. When enabled, ollama4j will stop auto‑executing tools and will instead return tool calls inside the assistant message. You can then inspect the tool calls and execute them manually. + + +Notes: +- Default value: clientHandlesTools is false for backward compatibility. +- When clientHandlesTools is false, ollama4j auto‑executes tools and loops internally until tools are resolved or max retries is reached. +- When clientHandlesTools is true, ollama4j will not execute tools; you are responsible for invoking tools and passing results back as TOOL messages, then re‑calling chat() to continue. + ### Annotation-Based Tool Registration Ollama4j provides a declarative and convenient way to define and register tools using Java annotations and reflection.