Tencent/WeKnora · error

custom agent configuration is required for agent QA

Error message

custom agent configuration is required for agent QA

What it means

AgentQA requires req.CustomAgent to be set; the handler is expected to have resolved the custom agent and done permission checks for shared agents. If CustomAgent is nil, it logs a warning and returns this error instead of proceeding with retrieval-augmented QA.

Source

Thrown at internal/application/service/session_agent_qa.go:38

func (s *sessionService) AgentQA(
	ctx context.Context,
	req *types.QARequest,
	eventBus *event.EventBus,
) error {
	sessionID := req.Session.ID
	// Propagate the session ID so stateful sandbox backends (CubeSandbox) can
	// bind script execution to a per-session MicroVM instance.
	ctx = types.WithSessionID(ctx, sessionID)
	sessionJSON, err := json.Marshal(req.Session)
	if err != nil {
		logger.Errorf(ctx, "Failed to marshal session, session ID: %s, error: %v", sessionID, err)
		return fmt.Errorf("failed to marshal session: %w", err)
	}

	// customAgent is required for AgentQA (handler has already done permission check for shared agent)
	if req.CustomAgent == nil {
		logger.Warnf(ctx, "Custom agent not provided for session: %s", sessionID)
		return errors.New("custom agent configuration is required for agent QA")
	}

	// Resolve retrieval tenant using shared helper
	agentTenantID := s.resolveRetrievalTenantID(ctx, req)
	logger.Infof(ctx, "Start agent-based question answering, session ID: %s, agent tenant ID: %d, query: %s, session: %s",
		sessionID, agentTenantID, req.Query, string(sessionJSON))

	var tenantInfo *types.Tenant
	if v := ctx.Value(types.TenantInfoContextKey); v != nil {
		tenantInfo, _ = v.(*types.Tenant)
	}
	// When agent belongs to another tenant (shared agent), use agent's tenant for KB/model scope; load tenantInfo if needed
	if tenantInfo == nil || tenantInfo.ID != agentTenantID {
		if s.tenantService != nil {
			if agentTenant, err := s.tenantService.GetTenantByID(ctx, agentTenantID); err == nil && agentTenant != nil {
				tenantInfo = agentTenant
				logger.Infof(ctx, "Using agent tenant info for retrieval scope, tenant ID: %d", agentTenantID)
			}

View on GitHub (pinned to 988cbb0330)

Solutions

  1. Populate req.CustomAgent with the agent configuration before calling AgentQA.
  2. Verify the handler resolved the agent (including shared-agent permission checks) before invoking the service.
  3. For sessions not bound to an agent, use the non-agent QA path instead.

Example fix

// before
req := &types.AgentQARequest{Query: "what is this doc about?"}
ans, err := svc.AgentQA(ctx, sessionID, req)
// after
agent, err := agentService.GetCustomAgent(ctx, agentID)
if err != nil { return err }
req := &types.AgentQARequest{Query: "what is this doc about?", CustomAgent: agent}
ans, err := svc.AgentQA(ctx, sessionID, req)
Defensive patterns

Strategy: validation

Validate before calling

if req.CustomAgent == nil {
    return fmt.Errorf("custom agent must be resolved before calling AgentQA")
}

Type guard

func hasCustomAgent(r *types.AgentQARequest) bool { return r != nil && r.CustomAgent != nil }

Prevention

When it happens

Trigger: Invoking AgentQA on a session whose request lacks a CustomAgent configuration — e.g. calling the service directly, or a handler path that skips agent resolution for non-agent sessions.

Common situations: Calling the application service directly in tests or scripts without populating CustomAgent, sessions created without an agent binding, or API clients omitting the custom_agent field.

Understand the failure class

Background: "X is required", "must be set", "cannot be empty": the missing-required-config error family, from Vertex AI project/location to WeChat keys — this error's family across 18 libraries.

Related errors


AI-assisted analysis of Tencent/WeKnora@988cbb0330 (2026-09-02). Data as JSON: /api/errors/5300fe4c1ba15924. Report an issue: GitHub.