fix(agent): skip tool injection for models without tool-call capability

Models that lack the "tool-call" compatibility flag now run without
tools, preventing provider errors when the model does not support
function calling.
This commit is contained in:
Acbox
2026-04-02 22:38:12 +08:00
parent a31995424c
commit a73bac05fe
+15 -7
View File
@@ -63,10 +63,14 @@ func (a *Agent) Generate(ctx context.Context, cfg RunConfig) (*GenerateResult, e
}
func (a *Agent) runStream(ctx context.Context, cfg RunConfig, ch chan<- StreamEvent) {
tools, err := a.assembleTools(ctx, cfg)
if err != nil {
ch <- StreamEvent{Type: EventError, Error: fmt.Sprintf("assemble tools: %v", err)}
return
var tools []sdk.Tool
if cfg.SupportsToolCall {
var err error
tools, err = a.assembleTools(ctx, cfg)
if err != nil {
ch <- StreamEvent{Type: EventError, Error: fmt.Sprintf("assemble tools: %v", err)}
return
}
}
tools, readMediaState := decorateReadMediaTools(cfg.Model, tools)
@@ -312,9 +316,13 @@ func (a *Agent) runStream(ctx context.Context, cfg RunConfig, ch chan<- StreamEv
}
func (a *Agent) runGenerate(ctx context.Context, cfg RunConfig) (*GenerateResult, error) {
tools, err := a.assembleTools(ctx, cfg)
if err != nil {
return nil, fmt.Errorf("assemble tools: %w", err)
var tools []sdk.Tool
if cfg.SupportsToolCall {
var err error
tools, err = a.assembleTools(ctx, cfg)
if err != nil {
return nil, fmt.Errorf("assemble tools: %w", err)
}
}
tools, readMediaState := decorateReadMediaTools(cfg.Model, tools)