Add Tool Calling and Reasoning Token Metadata to genai_config.json with Fallback Map#2215
Open
sayanshaw24 wants to merge 4 commits into
Open
Add Tool Calling and Reasoning Token Metadata to genai_config.json with Fallback Map#2215sayanshaw24 wants to merge 4 commits into
genai_config.json with Fallback Map#2215sayanshaw24 wants to merge 4 commits into
Conversation
added 2 commits
June 23, 2026 14:36
…into sayanshaw/tool-tags
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds support for exposing model “generation tags” (tool-calling and reasoning start/end tokens) via genai_config.json, with a model-type-based fallback for older model artifacts. It extends the internal config/model layers and surfaces a generic tag getter through the public C API and C++ wrapper, plus adds C API tests to validate both fallback and explicit config parsing.
Changes:
- Extend config schema/parsing with optional
tool_callingandreasoningsections (Config::ToolCalling,Config::Reasoning). - Add
Model::GetTag(tag_name)with a static fallback map keyed bymodel.type. - Expose tag lookup via
OgaModelGetTag(C API) andOgaModel::GetTag(C++ wrapper), and add tests covering fallback and config-driven values.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| test/c_api_tests.cpp | Adds tests for tag fallback behavior and tag parsing from a temp genai_config.json. |
| src/ort_genai.h | Adds C++ wrapper OgaModel::GetTag(...) calling the new C API. |
| src/ort_genai_c.h | Adds public C API declaration/docs for OgaModelGetTag(...). |
| src/ort_genai_c.cpp | Implements OgaModelGetTag(...) by allocating a returned string from Model::GetTag. |
| src/models/model.h | Declares internal Model::GetTag(...) accessor (config + fallback). |
| src/models/model.cpp | Implements fallback map + config accessors for tag lookup. |
| src/config.h | Adds Config::ToolCalling and Config::Reasoning structs to the config model. |
| src/config.cpp | Wires new SAX elements (ToolCalling_Element, Reasoning_Element) into root parsing. |
Comment on lines
+1838
to
+1839
| auto temp_dir = std::filesystem::temp_directory_path() / "oga_test_tool_tags"; | ||
| std::filesystem::create_directories(temp_dir); |
Comment on lines
+410
to
+414
| * \brief Returns a tag value for this model by name. | ||
| * | ||
| * Known tag names: "tool_call_start", "tool_call_end", "reasoning_start", "reasoning_end". | ||
| * Returns an empty string if the model doesn't define the requested tag. | ||
| * |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add tool calling and reasoning generation tags to genai_config.json
Summary
Adds support for reading tool call start/end tokens and reasoning start/end tokens from
genai_config.json, with a fallback map bymodel.typefor backward compatibility with older model files.This enables downstream consumers (Foundry Local C++ SDK) to get these tokens from GenAI's model API instead of relying on catalog metadata — required for the Catalog v2 migration where
toolCallStart/toolCallEnd/reasoningStart/reasoningEndtags will no longer be available.Changes
Config parsing (
config.h/config.cpp)Config::ToolCallingstruct withtool_call_start_tokenandtool_call_end_tokenConfig::Reasoningstruct withreasoning_start_tokenandreasoning_end_tokenToolCalling_Element,Reasoning_Element) wired intoRoot_ElementModel API (
models/model.h/models/model.cpp)Model::GetGenerationTag(tag_name)— single generic method that returns the value for a given tag keymodel.typefor models without the new config sections:qwen2/qwen3/phi3→<tool_call>/</tool_call>gptoss→<|start|>/<|call|>qwen3→<think>/</think>(reasoning)Public C API (
ort_genai_c.h/ort_genai_c.cpp)OgaModelGetGenerationTag(model, tag_name, &out)— single generic API accepting tag name as string keySupported tag names:
"tool_call_start","tool_call_end""reasoning_start","reasoning_end"C++ wrapper (
ort_genai.h)OgaModel::GetGenerationTag(tag_name)methodTests (
test/c_api_tests.cpp)GenerationTags_Fallback— verifiesgpt2model (not in fallback map) returns empty stringsGenerationTags_FromConfig— creates a temp model dir withtool_calling/reasoningsections in genai_config.json and verifies correct parsinggenai_config.json format
{ "model": { "type": "qwen2", ... }, "tool_calling": { "tool_call_start_token": "<tool_call>", "tool_call_end_token": "</tool_call>" }, "reasoning": { "reasoning_start_token": "<think>", "reasoning_end_token": "</think>" } }Both sections are optional. If absent, the fallback map is used. If the model type isn't in the fallback map either, empty strings are returned (meaning the model doesn't support tool calling / reasoning).
Motivation
The Foundry Local C++ SDK (
sdk_v2) currently reads tool call and reasoning tokens from Azure catalog metadata (ModelInfo.string_properties). With Catalog v2, these fields are being removed. This PR makes the tokens available directly from GenAI's model object, sourced from the model-shippedgenai_config.json.Priority order in FL SDK will be:
API Design Note
The API uses a single generic
OgaModelGetGenerationTag(model, tag_name, &out)rather than separate functions per token. Rationale:<|channel|>,<|message|>,<|constrain|>). A generic API avoids adding new functions for each.Related PRs
BuildToolCallContext()inchat_session.ccto read from GenAI API