Add max iterations

This commit is contained in:
dwrz
2026-07-05 17:55:07 +00:00
parent c4730eb8ce
commit 1e4c7f0334
6 changed files with 95 additions and 2 deletions

View File

@@ -446,6 +446,8 @@ type Request struct {
Model string `json:"model,omitempty"`
// SystemMessage overrides the configured system message for this request.
SystemMessage string `json:"system_message,omitempty"`
// MaxIterations caps the number of agent loop turns (0 = unlimited).
MaxIterations int `json:"max_iterations,omitempty"`
}
// Response is the response format for chat and voice endpoints.
@@ -541,7 +543,7 @@ func (svc *Service) chat(w http.ResponseWriter, r *http.Request) {
}
res, err := llmc.Completions(
ctx, model, req.SystemMessage, 0, req.Messages,
ctx, model, req.SystemMessage, req.MaxIterations, req.Messages,
)
if err != nil {
log.ErrorContext(
@@ -713,7 +715,7 @@ func (svc *Service) chatStream(w http.ResponseWriter, r *http.Request) {
)
go func() {
errs <- llmc.CompletionsStream(
ctx, model, req.SystemMessage, 0, req.Messages, events,
ctx, model, req.SystemMessage, req.MaxIterations, req.Messages, events,
)
close(errs)
}()