LocalAI/pkg/functions
Ettore Di Giacinto 21c84f432f
feat(function): Add tool streaming, XML Tool Call Parsing Support (#7865)
* feat(function): Add XML Tool Call Parsing Support

Extend the function parsing system in LocalAI to support XML-style tool calls, similar to how JSON tool calls are currently parsed. This will allow models that return XML format (like <tool_call><function=name><parameter=key>value</parameter></function></tool_call>) to be properly parsed alongside text content.

Signed-off-by: Ettore Di Giacinto <mudler@localai.io>

* thinking before tool calls, more strict support for corner cases with no tools

Signed-off-by: Ettore Di Giacinto <mudler@localai.io>

* Support streaming tools

Signed-off-by: Ettore Di Giacinto <mudler@localai.io>

* Iterative JSON

Signed-off-by: Ettore Di Giacinto <mudler@localai.io>

* Iterative parsing

Signed-off-by: Ettore Di Giacinto <mudler@localai.io>

* Consume JSON marker

Signed-off-by: Ettore Di Giacinto <mudler@localai.io>

* Fixup

Signed-off-by: Ettore Di Giacinto <mudler@localai.io>

* add tests

Signed-off-by: Ettore Di Giacinto <mudler@localai.io>

* Fix pending TODOs

Signed-off-by: Ettore Di Giacinto <mudler@localai.io>

* Don't run other parsing with ParseRegex

Signed-off-by: Ettore Di Giacinto <mudler@localai.io>

---------

Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
2026-01-05 18:25:40 +01:00
..
grammars fix: handle multi-type arrays in JSON schema to prevent panic (#6495) 2025-10-17 11:07:37 +02:00
function_structure.go feat(grammar): add llama3.1 schema (#3015) 2024-07-26 20:11:29 +02:00
functions.go chore(refactor): move logging to common package based on slog (#7668) 2025-12-21 19:33:13 +01:00
functions_suite_test.go feat(grammar): add llama3.1 schema (#3015) 2024-07-26 20:11:29 +02:00
functions_test.go feat(functions): parse broken JSON when we parse the raw results, use dynamic rules for grammar keys (#2912) 2024-07-18 17:52:22 +02:00
iterative_parser.go feat(function): Add tool streaming, XML Tool Call Parsing Support (#7865) 2026-01-05 18:25:40 +01:00
json_mode.go refactor: break down json grammar parser in different files (#3004) 2024-07-25 08:41:00 +02:00
json_stack_parser.go feat(function): Add tool streaming, XML Tool Call Parsing Support (#7865) 2026-01-05 18:25:40 +01:00
parse.go feat(function): Add tool streaming, XML Tool Call Parsing Support (#7865) 2026-01-05 18:25:40 +01:00
parse_test.go feat(function): Add tool streaming, XML Tool Call Parsing Support (#7865) 2026-01-05 18:25:40 +01:00