ShouldUseToolChoice 判断是否应该使用 tool_choice
(ctx context.Context, constraints ToolConstraints)
| 244 | |
| 245 | // ShouldUseToolChoice 判断是否应该使用 tool_choice |
| 246 | func (s *DefaultToolSelector) ShouldUseToolChoice(ctx context.Context, constraints ToolConstraints) (*ToolChoice, bool) { |
| 247 | if constraints == nil { |
| 248 | return nil, false |
| 249 | } |
| 250 | |
| 251 | switch constraints.GetConstraintType() { |
| 252 | case ConstraintTypeRequired: |
| 253 | // 必需工具约束 -> 使用 tool_choice |
| 254 | if req, ok := constraints.(*RequiredToolConstraints); ok { |
| 255 | return ToolChoiceRequired(req.GetRequiredTool()), true |
| 256 | } |
| 257 | return nil, false |
| 258 | |
| 259 | case ConstraintTypeAuto: |
| 260 | // 自动选择 -> 使用 auto |
| 261 | return ToolChoiceAuto, true |
| 262 | |
| 263 | default: |
| 264 | return nil, false |
| 265 | } |
| 266 | } |
| 267 | |
| 268 | // ConstraintsBuilder 约束构建器 |
| 269 | type ConstraintsBuilder struct { |