fix(agent): honor suggested-questions limit parameter

Treat limit as the authoritative upper bound instead of clamping it down
to the agent's Starters.Count, so ?limit=N no longer always returns 6.

Fixes #2238
This commit is contained in:
Jack Wang
2026-07-23 21:23:31 +08:00
committed by lyingbug
parent e0b6a71503
commit 43839f7830
10 changed files with 152 additions and 19 deletions
+23 -3
View File
@@ -23,6 +23,16 @@ var (
ErrAgentNameRequired = errors.New("agent name is required")
)
const (
// suggestionDefaultLimit is the fallback count when neither the caller nor
// the agent configuration specifies how many suggestions to return.
suggestionDefaultLimit = 6
// suggestionMaxLimit caps how many suggestions a single request may ask for.
// It bounds the downstream candidate pool (limit*5) so an oversized limit
// cannot turn into an unbounded chunk query.
suggestionMaxLimit = 30
)
// customAgentService implements the CustomAgentService interface
type customAgentService struct {
repo interfaces.CustomAgentRepository
@@ -497,8 +507,15 @@ func (s *customAgentService) getSuggestedQuestions(
limit int,
includeCurated bool,
) ([]types.SuggestedQuestion, error) {
if limit <= 0 {
limit = 6
// A non-positive limit means "unspecified": fall back to the agent's
// configured Starters.Count (below) or the default. An explicit limit is
// authoritative and only bounded by the safety cap.
limitProvided := limit > 0
if !limitProvided {
limit = suggestionDefaultLimit
}
if limit > suggestionMaxLimit {
limit = suggestionMaxLimit
}
if err := types.AuthorizeTenantAPIKeyKnowledgeTargets(ctx, kbIDs, knowledgeIDs); err != nil {
@@ -529,7 +546,10 @@ func (s *customAgentService) getSuggestedQuestions(
if suggestionConfig == nil || !suggestionConfig.Starters.Enabled {
return []types.SuggestedQuestion{}, nil
}
if limit > suggestionConfig.Starters.Count {
// Starters.Count is the agent-author default, applied only when the
// caller did not request a specific limit. An explicit limit stays
// authoritative so ?limit=N actually changes how many are returned.
if !limitProvided && suggestionConfig.Starters.Count > 0 {
limit = suggestionConfig.Starters.Count
}
starterMode = suggestionConfig.Starters.Mode