Supported Parsers
Quick Start
Launch Server
The
--tool-call-parser argument specifies which parser to use for interpreting function calls in the model’s output.Define Tools
Make Requests
Non-Streaming
Streaming
Multi-Tool Support
Define multiple tools for the model to choose from:Tool Choice Control
Control when and how the model calls tools:Multi-Turn Conversations
Implement agentic workflows with tool execution:Parallel Tool Calls
Some models support calling multiple tools in one turn:Pythonic Tool Calling
Some models can output function calls as executable Python code:Model-Specific Notes
DeepSeek Models
DeepSeek Models
DeepSeek-V3 family supports thinking before tool calls:
GPT-OSS
GPT-OSS
GPT-OSS uses analysis channels. The parser filters these out, but content may be empty if all output is in analysis channel. Complete the tool round by returning tool results to get final content.
Kimi K2
Kimi K2
For Kimi K2 with thinking, use both parsers:
Implementation Details
Tool calling is implemented through theFunctionCallParser system:
python/sglang/srt/function_call/function_call_parser.py:39
Each detector implements:
- Pattern detection: Identify tool call syntax in output
- Argument extraction: Parse JSON/Python arguments
- Streaming support: Handle incremental parsing
- Validation: Ensure arguments match schema
Combining with Structured Outputs
You can combine tool calling with structured outputs for precise control:Best Practices
1. Provide Clear Descriptions
1. Provide Clear Descriptions
Write descriptive tool names and clear parameter descriptions. This helps the model understand when and how to use each tool.
2. Use Required Fields
2. Use Required Fields
Mark essential parameters as
required in the schema. This ensures the model provides all necessary information.3. Handle Errors Gracefully
3. Handle Errors Gracefully
Always validate tool call arguments before execution. Handle parsing errors and missing parameters appropriately.
4. Implement Timeouts
4. Implement Timeouts
Set reasonable timeouts for tool execution to prevent hanging on slow APIs.
5. Use Enums for Constrained Values
5. Use Enums for Constrained Values
Define
enum fields for parameters with fixed options (e.g., units, categories).Performance Considerations
- Parser overhead: Minimal (<1ms per request)
- Streaming latency: Tool calls appear incrementally in stream
- Multi-tool calls: Some parsers support multiple calls per turn
- Validation: Schema validation adds negligible overhead
