alibaba/nacos · error · IllegalArgumentException

Agent publish request must not be null

Error message

Agent publish request must not be null

What it means

The AgentPublishApplicationService.publish method requires a non-null AgentPublishRequest. This is the entry guard for the idempotent Agent draft-and-submit pipeline used by the client publish API. A null request means no publication data was provided, which is a programming or binding error.

Source

Thrown at ai/src/main/java/com/alibaba/nacos/ai/service/agent/AgentPublishApplicationService.java:59

    
    private final AgentOperationService operationService;
    
    public AgentPublishApplicationService(AgentOperationService operationService) {
        this.operationService = operationService;
    }
    
    /**
     * Publish one exact Agent Version and optionally submit it.
     *
     * @param namespaceId effective namespace
     * @param request publication request
     * @return resulting exact Version detail
     * @throws NacosException when validation, persistence, or submit fails
     */
    public AgentVersionDetail publish(String namespaceId, AgentPublishRequest request)
        throws NacosException {
        if (request == null) {
            throw new IllegalArgumentException("Agent publish request must not be null");
        }
        AgentValidationUtils.validateNamespaceId(namespaceId);
        request.validate();
        AgentVersionDetail current = findEquivalent(namespaceId, request);
        if (current == null) {
            try {
                current = operationService.createDraft(namespaceId, request);
            } catch (NacosException createFailure) {
                current = recoverEquivalent(namespaceId, request, createFailure);
            }
        }
        if (!request.isAutoSubmit()) {
            requireStatus(current, AiConstants.Agent.VERSION_STATUS_DRAFT);
            return current;
        }
        if (!AiConstants.Agent.VERSION_STATUS_DRAFT.equals(current.getStatus())) {
            return requireSubmittedState(current);
        }

View on GitHub (pinned to 9b989acdf1)

Solutions

  1. Construct and populate an AgentPublishRequest before calling publish.
  2. Validate non-null at the controller/client boundary before delegating to the service.
  3. Ensure the HTTP request body is valid JSON with agentName, version, and callInterfaces.

Example fix

// before
service.publish(ns, null); // throws

// after
AgentPublishRequest req = new AgentPublishRequest();
req.setAgentName("my-agent");
req.setVersion("1.0.0");
req.setCallInterfaces(List.of(callInterface));
req.setAutoSubmit(true);
service.publish(ns, req);
Defensive patterns

Strategy: validation

Validate before calling

if (request == null) {
    throw new IllegalArgumentException("Agent publish request must not be null");
}

Type guard

boolean isPublishable(AgentPublishRequest req) {
    return req != null && req.getAgentName() != null && req.getVersion() != null
        && req.getCallInterfaces() != null;
}

Prevention

When it happens

Trigger: Calling AgentPublishApplicationService.publish(namespaceId, null), or the client publish API endpoint with a missing/empty request body that deserializes to null.

Common situations: An SDK caller passes null instead of a constructed request. The HTTP request body is empty or malformed. A retry or callback invokes publish without reconstructing the request object.

Related errors


AI-assisted analysis of alibaba/nacos@9b989acdf1 (2026-08-14). Data as JSON: /api/errors/cd40d76d7d1e414f. Report an issue: GitHub.