NVIDIA:用智能体在 Rust 里编写工具调用解析器(11 月 19 日)
A tool call can arrive in pieces, an argument can be cut short, or model-specific markup can leak into the answer. A frontend parser turns that output, received as token IDs or decoded text, into visible text, reasoning, and tool calls an application can use.
In this post, you’ll learn how tool-call parsing works and use an AI agent to build a parser for a new model. You’ll start with a weather request and a human-reviewed test set, using frontend-crates, the reusable Rust components behind NVIDIA Dynamo tool-calling parsers.
Suppose you ask for the weather in Paris. The model may generate reasoning followed by a get_weather call with a city argument. The frontend prepares and tokenizes the prompt, then an inference engine runs the LLM to generate tokens. The parser consumes token IDs or decoded text and separates reasoning, visible text, and tool calls in order. A protocol adapter turns those events into an OpenAI-compatible response, using the same parsing path for batch JSON and streaming updates.
The tricky part is recognizing where each piece starts and ends. A call can be malformed or incomplete, a marker can appear inside an argument, or ordinary text can surround the call. The parser has to handle these boundaries without losing data, duplicating calls, or leaking model-specific markup.
Returning to the weather request: the model might stop halfway through a city name or call a tool that wasn’t offered. Either can disrupt the agent’s next action. The following NVIDIA Nemotron examples show these two failures.
Syntax error. The argument and tool-call frame never close, so no complete call can be parsed.
</think><tool_call>
<function=get_weather><parameter=city>Par
Semantic error. The frame is valid, but the named tool is absent from the request.
</think><tool_call>
<function=unknown_tool><parameter=city>Paris</parameter></function>
</tool_call>
These failures require different handling. If the model names an unavailable tool, the parser reports the call it received, and the serving layer validates tool availability, authorization, schema, and call policy. Changing the tool name would hide what the model actually generated.
An incomplete call is harder to judge while the stream is open. The rest of the city name may arrive in the next chunk, and a marker can split across chunks, too. Emit too early and syntax leaks into the answer; wait too long and ordinary text gets delayed. The parser needs consistent rules for what to emit, what to buffer, and how to handle the end of the stream.
A parser can encounter an unbounded range of inputs. With invalid input, it must follow documented recovery rules rather than guess the model’s intent. Even a syntactically valid call that conforms to the schema can be the wrong choice for the user’s request. The parser needs a consistent grammar and recovery policy so it can preserve valid data without inventing calls or leaking model-specific markup.
To check those decisions, frontend-crates pairs model outputs with expected results in a shared Conformance Corpus.
Use the Conformance Corpus to check how applicable parsers handle behavior first observed in one model. Its language-neutral YAML fixtures pair fixed input with expected output, so Rust parsers and Python references can run the same cases. A regression test for leaked markup, duplicate calls, or lost arguments can cover other families when adapted to their grammars.
For a new parser, start with all UNIFIED.* cases across model families. They cover complete, malformed, truncated, multiple, and interleaved calls, plus streaming boundaries and end-of-input behavior. Adapt inputs to your model’s grammar and request settings, add model-specific edge cases, and explain exclusions. You can’t test every possible output, but you can reuse cases from other formats.
Table 1 shows the UNIFIED.1-tool_only case from the Parser Conformance Table. In this example, the GOLDEN test set pairs four model-specific inputs with the same expected result: get_weather with city set to Paris. The markers differ, but each case tests the same behavior. Adapting the input format makes the same behavioral test reusable across models.
| Model | Native input |
|---|---|
| Beam | <|start|>``assistant to=get_weather``<|channel|>``analysis <|constrain|>``xml``<|message|>``<rfl:parameter name="city"> Paris </rfl:parameter>``<|call|> |
| GPT-OSS | <|start|>``assistant``<|channel|>``commentary to=functions.get_weather <|constrain|>``json``<|message|>``{"city": "Paris"}``<|call|> |
| Muse Spark | <|start|>``assistant to=get_weather``<|message|><atem:function_calls> <atem:invoke name="get_weather"> <atem:parameter name="city">``Paris``</atem:parameter> </atem:invoke> </atem:function_calls><|eom|> |
| NVIDIA Nemotron 3 | </think>``<tool_call> <function=``get_weather``> <parameter=city> Paris </parameter> </function> </tool_call> |
Table 1. Model-specific inputs with the same expected GOLDEN output: get_weather({“city”:”Paris”})
Now you can create a parser for a model that frontend-crates doesn’t support yet. Ask your AI agent to read this post and work through the tutorial, starting with the prompt in step 1. Your model’s specification defines the grammar; the shared cases provide behaviors to test.
You’ll need a frontend-crates checkout, Rust and Cargo, and the conformance dependencies. The parser exercise runs on a CPU using fixed test fixtures, so you don’t need a GPU. End-to-end testing also requires a working Dynamo runtime, discovery services, and hardware for your model. When you’re ready to test end-to-end, launch the tests with Dynamo runtime on the actual model and GPU(s).
The workflow in Figure 2 starts with the model’s grammar, recovery rules, and reviewed GOLDEN expectations. The agent writes or fixes the parser, runs tests, and uses failures to guide the next change. If it proposes changing the expected behavior, review that decision before accepting it.
Test your parser end to end with real models before claiming deployment support. Plan time to allocate a machine, load the model, initialize the runtime, and run your own test cases. Turn failures into unit tests for the agent, then rerun the end-to-end test to check the fix.
Give the agent this prompt: In the frontend-crates checkout, follow .agents/skills/tool-parser-generator/SKILL.md to create a v2 Unified parser for [MODEL_NAME]. Research its grammar and prepare the GOLDEN test set, adapting applicable UNIFIED.* cases. Pause for human review. After approval, implement, validate, and provide the local conformance report URL for human inspection.
The GOLDEN test set defines the behavior your parser will be tested against. Use the prompt in step 1 to have the agent generate an initial test set in conformance/fixtures-unified-v2/families/<name>/inputs_and_golden.yaml, independently of parser results. Each case pairs an input with its expected output, called GOLDEN. If those expectations are wrong, the parser can pass the tests and still behave incorrectly.
The following example pairs an input with its expected GOLDEN output. It omits request definitions, tools, initialization, and chunk settings; the existing nemotron_v3/inputs_and_golden.yaml shows the full format.
family: nemotron_v3
cases:
UNIFIED.tool_only.nemotron_v3:
input: |-
</think><tool_call>
<function=get_weather>
<parameter=city>Paris</parameter>
</function></tool_call>
golden:
- kind: tool_call
name: get_weather
arguments: {city: Paris}
Ask the agent for an adversarial review, then go through the set manually, case by case. The initial test set may contain errors because expected behavior depends on context the agent may not have. Review it against the following sources and requirements:
- The model format and API specification.
- The reference implementation.
- Other parsers, including vLLM and SGLang.
- The grammar, tool schema, and request settings.
- Relevant forum discussions and existing tickets.
- Caller needs and recovery costs in latency and complexity.
Where sources disagree, you may need to make a judgment call. Write down the recovery rule and why you chose it, and document the reason for any GOLDEN change. Expectations should follow that decision, not the parser’s output.
After reviewing the GOLDEN test set, ask the agent to continue: build the parser, run all applicable UNIFIED.* cases and shared regression tests, and fix the failures. Have it recapture results, generate conformance/CONFORMANCE_v2.html locally, and provide the local report URL so you can inspect its work.
Open that URL in your browser. The local report uses the published Parser Conformance Table‘s interface with your local results. Inspect each case’s input, request settings, GOLDEN, and recorded output. Investigate regressions and missing captures. Green means the output matches GOLDEN, so the table depends on the expectations you reviewed. Figure 3 shows the report interface.
The agent’s implementation step also covers guided decoding, which can reduce malformed calls by constraining generation to the model’s markers and argument schema. Ask your agent to follow “Add and validate structural tags” in the parser README and “Implement and validate” in the agent skill. These instructions cover builder registration, grammar tests, and backend qualification. Guided decoding can’t ensure that the model chooses the right city or prevent truncation, so keep the parser’s recovery checks.
Passing correctness tests is only a starting point for an agent-generated parser. The implementation may still be slow or use too much memory. Try plain text, tool calls, long arguments, and malformed input with large and tiny chunks. Measure throughput, time to the first event, and memory use on the same build and hardware. Double the input length to spot code that keeps rescanning or copying what it already read.
With streaming, watch what the caller receives as each chunk arrives. A parser can return the right final result and still make the caller wait until the end. Replay short fixtures at every split point, then try one-character and mixed chunks, including splits inside markers, escaped quotes, and arguments. Check that events arrive in order and arguments stay intact. If events are queued, test a slow consumer and cancellation too.
Also try cutting the stream off halfway through a marker or argument. Check that recovery follows the documented rule without leaking markup, duplicating calls, or losing valid text. The parser should handle the input it received without guessing the missing pieces.
Test text containing examples of the model’s format as well as tool calls against the documented grammar and quote-handling policy. The current v2 default treats recognized markers as structural even inside quoted prose, so quotation marks alone do not keep a complete tool-call example in ordinary text. Record the configured policy and test its expected behavior.
Give the agent this prompt to check for common gotchas:
Check this parser for common gotchas. Benchmark speed and memory with short, long, and malformed inputs using different chunk sizes. Look for repeated scanning, copying, or growing buffers. Verify that output arrives incrementally and stays correct across chunk boundaries and truncation. Where queues exist, test a slow consumer, backpressure, and cancellation. Check literal format examples and real tool calls against the documented grammar and configured quote-handling policy. Report measurements, reproducible failures, and anything you could not verify.
Choose a parser whose grammar matches your model. This example uses the existing NVIDIA Nemotron parser and splits both a marker and the city name across chunks.
This example was tested with Rust 1.96.1 and dynamo-parsers-v2 0.10.3. Run cargo new parser-demo, then cd parser-demo. Add the following entries under [dependencies] in Cargo.toml:
anyhow = "1"
dynamo-parsers-v2 = "=0.10.3"
serde_json = "1"
Replace src/main.rs with:
use dynamo_parsers_v2::{
Tool, UnifiedParserInit, UnifiedParserOutput, create_unified_parser_for_family,
};
use serde_json::json;
fn main() -> anyhow::Result<()> {
let tools = [Tool {
name: "get_weather".into(),
description: None,
parameters: json!({"type":"object","properties":{"city":{"type":"string"}},"required":["city"]}),
strict: None,
}];
let mut parser = create_unified_parser_for_family("nemotron_v3", &tools)?;
parser.initialize_request(UnifiedParserInit::default())?;
let mut output = UnifiedParserOutput::default();
for chunk in [
"Check the forecast.</think><tool_",
"call><function=get_weather><parameter=city>Par",
"is</parameter></function></tool_call>",
] {
let mut delta = UnifiedParserOutput::default();
parser.parse_into(chunk, &mut delta)?;
output.append(&mut delta);
}
output.append(&mut parser.finish()?);
println!("{}", serde_json::to_string(&output.assembled())?);
Ok(())
}
Run cargo generate-lockfile, then cargo run --locked. The result contains reasoning followed by a get_weather call with city set to Paris:
[{"kind":"reasoning","text":"Check the forecast."},
{"kind":"tool_call","name":"get_weather","arguments":{"city":"Paris"}}]
Keep one initialized parser for each request choice.
create_unified_parser_for_familyselects the grammar.initialize_requestsets the starting state.parse_intoconsumes each chunk.- Finalize once: use
finish()for truncation, cancellation, or the end of the transport stream. Usefinish_at_eos()only for a backend-confirmed grammar-ending end-of-sequence (EOS) signal. - Use
assembled()for the ordered results.
In a streaming application, forward the events in delta.events after each parse_into call and the events returned by finish(). This example collects the events to print the final output. Before executing tools, validate completed calls for tool availability, authorization, schema, and call policy.
To build a parser for your model, start with the source, fixtures, and instructions in frontend-crates and adapt an existing test case. Give your agent the model’s format specification and the repository instructions, then use the Parser Conformance Table to check the parser’s recorded output against GOLDEN. When you open an issue or pull request, include the exact failing input, case identifier, and test results so reviewers can reproduce the behavior.
You can use these parsers in your own Rust project or as part of NVIDIA Dynamo, an inference framework that uses frontend-crates. Before you begin, check the latest repository instructions so you and your agent follow the current steps.
Jesse Gu, Alec Flowers, Dong Xu, Qi Wang, and the many partners and proofreaders who helped with this blog and frontend-crates.
https://developer.nvidia.com/blog/build-tool-calling-parsers-in-rust-with-ai-agents/Reposted. Will be removed on request. All rights belong to the original author.
More from this batch
Anthropic IPO live updates: ANT stock price and Nasdaq debut
这是上次推送之后最重要的进展:股票于 11 月 19 日开盘 111.50 美元,收盘 97.17 美元,较 83 美元发行价上涨约 17%。Yahoo Finance 记录当日最高 115.10、最低 92.72 美元,成交约 8.53 亿股。CNBC 称本次发行筹资 813 …
Has DeepSeek's 100-billion-yuan round landed? 31 investors come into view
第一财经 11 月 19 日 16:23 报道(上一期 20:07 推送前已刊出,本期补录),企查查显示杭州深度求索注册资本由约 1645 万元增至 1991.87 万元,新增股东杭州程砚;该平台同期新增 31 家合伙人,腾讯与宁德时代体系出资比例并列前列,另有中国移动、中信证券…
The Information:英伟达接近以逾 5 亿美元收购扩散模型公司 Inception(报道,尚未宣布)
多家媒体转述 The Information 的报道称,英伟达正与 Inception(Mercury 扩散语言模型团队)进行后期洽谈,对价至少约 5 亿美元,还可能包含业绩对赌;交易尚未签署或官宣,报道称创始团队将加入英伟达。这仍是独家报道,不是双方声明。
苹果被曝在招人,要做能操控 Mac 的自有 AI 智能体(11 月 19 日)
TechCrunch 和 The Verge 根据招聘信息报道,苹果可能在开发一款可在 Mac 上运行、帮用户完成电脑操作的自有智能体。这还不是产品发布,只是招聘与报道层面的线索,细节以苹果之后的正式说明为准。
谷歌开始把 AI 对话直接放上搜索首页(11 月 19 日)
The Verge 报道,谷歌正在把 AI 聊天入口放到搜索首页,而不只是藏在搜索结果里的 AI 模式中。具体覆盖范围和是否可关闭,请以谷歌产品说明和原文为准。
薯片袋触发校园枪支警报后,两名学生起诉学校和警方(11 月 19 日)
Ars Technica 报道,美国一起校园 AI 武器检测误报导致两名青少年被警察制服,两人已提起诉讼。这是公共场所视觉识别落地时误报代价的一个具体案例,细节以诉状和报道为准。
Introducing Tool Retrieval in the Gemini API
谷歌官方介绍,当应用挂了大量工具时,模型不必每次都看完整工具列表,而是先检索可能相关的工具再决定调用。这对工具很多的企业 Agent 有直接意义:可以降低提示开销,也减少无关工具干扰。能力边界和配额以官方文档为准。
Depth Pro 2: Sharp and Temporally Consistent Metric Monocular Depth
上一期未收入。苹果机器学习研究放出 Depth Pro 2,可从照片、视频或实时画面估计以米为单位的深度,并强调物体边缘更锐、帧间更稳定。仓库提供 S/B/L/H+ 等多档模型及 Core ML 包,权重为研究用途。论文编号 arXiv:2611.26603。
NVIDIA 介绍用 Dynamo 缓解强化学习 rollout 瓶颈(11 月 19 日)
官方技术博客讨论在强化学习训练里,生成轨迹(rollout)常常卡住吞吐。文章介绍如何用 NVIDIA Dynamo 把这部分流水线理顺,让训练不必长时间等采样。适合正在做 RL 后训练或智能体强化学习的团队对照自己的栈。
NVIDIA:用 GPU 原生数据采集,让科学仪器能跑实时 AI(11 月 19 日)
官方博客介绍把科学仪器的数据采集直接放到 GPU 上处理,减少数据搬运,从而在实验现场做实时推理。这对同步辐射、显微镜或探测器一类场景有参考价值,不是面向普通聊天应用的更新。
Science 观察 Agent AlphaXiv:35 个实验室放出 936 个智能体,12 周写出 936 篇预印本(11 月 19 日)
《Science》11 月 19 日下午的特稿记录了一场为期 12 周的实验:35 个人类实验室部署的智能体在专属预印本服务器上互相交流、写代码、做实验并发布 936 篇研究,还自建了同行评议期刊。文章提醒这些是预印本而非传统期刊论文,质量参差,但提供了一个观察「智能体科研社区」…
Claude solves two open problems in the physics of black holes
官方文章署期 11 月 17 日,上一期未收入;本期 Hacker News 讨论升温。Anthropic 称 Claude Fable 5.2 完成了两项与量子引力和黑洞有关的计算:其一补完了 2003 年提出但一直未做完的相变计算,显示黑洞形成对应的突变在时空不再有明确形状时…