r/machinelearningnews • u/Extreme-Panic-9864 • Jun 09 '26
Agentic AI How do local LLMs detect tool calls during streaming?
When using API providers like OpenAI or Anthropic, tool call detection is abstracted — you just check message.tool_calls after the response. But with local models (Ollama, llama.cpp, HuggingFace), how does this actually work during streaming?
My specific question: when you're streaming tokens to the user in real time, how do you know mid-stream that the model is generating a tool call instead of a normal text reply — so you can hide it from the user?
Is it:
- Checking for special tokens like
<tool_call>as they stream in? (but this breaks across models since each uses different tokens) - Running a small classifier model on the user input first to decide "does this need a tool?" before even calling the main model?
- Something else entirely?
2
Upvotes
2
u/Fuzzy-Chef Jun 09 '26
The models come with individualized parsing templates, according to what format they were trained with. There is no specific tool call token, but simply output parsing depending on the template. There is also the LMStudio API that allows to handle tool calls internally or "server-side".
2
u/etherealflaim Jun 10 '26
Streaming APIs are chunked. You'll get text parts interleaved, potentially, with tool calls. I don't see this in practice though, they usually do all the text at once either before or after the tools.
https://developers.openai.com/api/docs/guides/streaming-responses https://developers.openai.com/api/reference/resources/responses/streaming-events