Skip to content

How to avoid 400 internal error while developing multi-agents application #1891

@ziyilin

Description

@ziyilin

I'm developing a multi-agents application. There is a master agent that runs the workflow according to the predefined system message, and calls other agent to do certain sub-task. The code would be like:

public class MasterAgent {
@SessionScoped
@RegisterAiService
public interface MasterAgent {
    @SystemMessage("""
            You're an expert of .... 
            You can call subtaskagent to finish the subtask with the collected information.
            ...
            """)
    @ToolBox(SubTaskAgent.class)
    Multi<String> chat(String userMessage);
}

public class SubTaskAgent{
@SessionScoped
@RegisterAiService
public interface ConflictSolverAgent {

    @SystemMessage("""
     You're an expert of ... . Please summarize the {{information}}.
     ...
""")
    @Tool(name="subtaskagent", value = "...")
    String chat(@V("information") String information);
}

The application could work well sometimes, but it often failed with 400 error such as:

Response:
- status code: 400
- headers: [vary: Origin,Access-Control-Request-Method,Access-Control-Request-Headers, Accept-Encoding], [x-request-id: 25440da5-9cb7-4bcb-bfaf-f4d393e9b01d], [x-dashscope-call-gateway: true], [content-type: application/json], [content-length: 436], [req-cost-time: 526], [req-arrive-time: 1761564475982], [resp-start-time: 1761564476509], [x-envoy-upstream-service-time: 522], [set-cookie: acw_tc=25440da5-9cb7-4bcb-bfaf-f4d393e9b01dc59610161239f7dde1add1d1207eb086;path=/;HttpOnly;Max-Age=1800], [date: Mon, 27 Oct 2025 11:27:56 GMT], [server: istio-envoy]
- body: {"error":{"code":"invalid_parameter_error","param":null,"message":"<400> InternalError.Algo.InvalidParameter: An assistant message with \"tool_calls\" must be followed by tool messages responding to each \"tool_call_id\". The following tool_call_ids did not have response messages: message[3].role","type":"invalid_request_error"},"id":"chatcmpl-25440da5-9cb7-4bcb-bfaf-f4d393e9b01d","request_id":"25440da5-9cb7-4bcb-bfaf-f4d393e9b01d"}

How can I prevent such failure?

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions