iflytek/astron-agent · warning · CotFormatIncorrectExc

无效的插件参数JSON格式

Error message

无效的插件参数JSON格式: {action_input_raw}

What it means

In the CoT (chain-of-thought) agent runner, _parse_action_input parses the Action Input block of an LLM step as JSON. When json.loads fails after stripping optional ``` fences, it raises CotFormatIncorrectExc '无效的插件参数JSON格式' (invalid plugin-parameter JSON format) including the raw input. This enforces the ReAct-style protocol where Action Input must be a JSON object/string the plugin dispatcher can use.

Solutions

  1. Strengthen the system prompt with explicit JSON-only examples for Action Input and few-shot correct outputs.
  2. Lower model temperature or use JSON mode/function-calling if the model supports it, so arguments are schema-constrained.
  3. Add a retry loop: catch CotFormatIncorrectExc and re-prompt the model with the validation error appended.
  4. Optionally pre-sanitize common issues (trailing commas, single->double quotes) before json.loads in a fork.

Example fix

// before (model output)
Action Input: {'query': 'weather'}
// after (prompt-enforced)
Action Input: {"query": "weather"}
Defensive patterns

Strategy: try-catch

Try / catch

try:
    step = await runner.parse_cot_step(content)
except CotFormatIncorrectExc as e:
    if "JSON" in str(e):
        content = sanitize_json_args(content)  # fix quotes/commas, then retry
    raise

Prevention

When it happens

Trigger: The LLM emits an Action Input block that is not valid JSON: unquoted keys, single quotes, trailing commas, Python-style dict repr, or prose mixed into the block.

Common situations: Weak/small models ignoring the JSON instruction; temperature too high causing malformed arguments; prompt template drift so the model mirrors examples with non-JSON syntax; multi-line strings without escaping.

Understand the failure class

Background: "Invalid JSON response" and "Failed to parse response" errors: when an API answers 200 but the body isn't the JSON your library expected — this error's family across 28 libraries.

Related errors


AI-assisted analysis of iflytek/astron-agent@5e758547a8 (2026-09-12). Data as JSON: /api/errors/1fd9b2c6e4a36fa2. Report an issue: GitHub.

Appendix: source

Thrown at core/agent/engine/nodes/cot/cot_runner.py:144

    async def create_user_prompt(self) -> str:
        user_prompt = COT_USER_TEMPLATE.replace(
            "{chat_history}", await self.create_history_prompt()
        )
        user_prompt = user_prompt.replace("{question}", self.question)
        return user_prompt

    async def _parse_action_input(self, action_input_raw: str) -> dict[str, Any]:
        """解析并验证 action_input JSON 格式"""
        normalized_input = action_input_raw.strip()
        normalized_input = re.sub(
            r"^```(?:json)?\s*", "", normalized_input, flags=re.IGNORECASE
        )
        normalized_input = re.sub(r"\s*```$", "", normalized_input)
        try:
            return json.loads(normalized_input)
        except json.decoder.JSONDecodeError:
            raise cot_exc.CotFormatIncorrectExc(
                f"无效的插件参数JSON格式: {action_input_raw}"
            )

    @staticmethod
    def _find_marker(step_content: str, marker: str) -> Match[str] | None:
        return PROTOCOL_MARKERS[marker].search(step_content)

    def _has_complete_action(self, step_content: str) -> bool:
        action = self._find_marker(step_content, "action")
        action_input = self._find_marker(step_content, "action_input")
        return bool(action and action_input and action.end() <= action_input.start())

    def _extract_final_answer(self, step_content: str) -> str | None:
        marker = self._find_marker(step_content, "final_answer")
        if marker is None:
            return None
        return step_content[marker.end() :]

View on GitHub (pinned to 5e758547a8)