iflytek/astron-agent · error · AuditServiceException
9020
9020
Error message
stage不可为空
What it means
In the text audit strategy, `_audit_api_output_text` requires a `stage` argument to route the output audit; when the computed `stage_arg` is None it raises `AuditServiceException(*c9020)` ('stage不可为空') before calling `audit_api.output_text`.
Solutions
- Ensure the input audit (`input_text`) runs before `output_text` so `last_content_stage` is populated.
- Pass an explicit valid `Stage` value to the audit strategy call.
- Check that the audit context object is correctly initialized and shared across the request lifecycle.
- Add an assertion/validation on the caller side that stage is set before triggering output audit.
Example fix
// before await strategy.output_text(content=answer, pindex=0, span=span) // after await strategy.output_text(content=answer, pindex=0, span=span, stage=Stage.AFTER_LLM)
Defensive patterns
Strategy: validation
Validate before calling
if stage is None and audit_context.last_content_stage is None:
raise ValueError("output audit requires a stage; run input audit first or pass stage explicitly") Type guard
from common.audit_system.audit_api.enum import Stage
def has_stage(stage: Stage | None) -> bool:
return isinstance(stage, Stage) Try / catch
try:
await strategy.output_text(...)
except AuditServiceException:
logger.error("stage missing for output audit; ensure input_text ran first")
raise Prevention
- Always run the input-stage audit before the output-stage audit in the pipeline.
- Make `stage` an explicit required parameter in audit helper wrappers.
- Initialize audit context (last_content_stage) at request start.
- Write a unit test asserting stage resolution for both first-turn and follow-up turns.
When it happens
Trigger: `_audit_api_output_text_async` resolves the stage from context (falling back to `context.last_content_stage` when it differs from the current stage) and both come out None, so `stage_arg is None`.
Common situations: Audit pipeline invoked for output without a prior input-stage audit (last_content_stage never set); caller omitted the stage parameter; strategy context initialized incompletely.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- PARAMS_ERROR
- BOT_NOT_EXISTS
- RESPONSE_FAILED
- Either fileUrl or file must be provided
- Failed to normalize publish approval snapshot spaceId
AI-assisted analysis of iflytek/astron-agent@5e758547a8 (2026-09-12).
Data as JSON: /api/errors/b3c44903531c462e.
Report an issue: GitHub.
Appendix: source
Thrown at core/common/audit_system/strategy/text_strategy.py:310
is_end = 1 if current_status == Status.STOP else 0
if current_status == Status.STOP:
is_stage_end = 1
if self.context.last_content_stage != current_stage:
is_stage_end = 1
try:
for audit_api in self.audit_apis:
span.add_info_event(f"当前审核API: {audit_api.audit_name}")
stage_arg = (
current_stage
if self.context.last_content_stage == current_stage
else self.context.last_content_stage
)
if stage_arg is None:
raise AuditServiceException(*c9020)("stage不可为空")
await audit_api.output_text(
stage=stage_arg,
content=need_audit_content,
pindex=pindex,
span=span,
is_pending=0,
is_stage_end=is_stage_end,
is_end=is_end,
chat_sid=self.context.chat_sid,
chat_app_id=self.context.chat_app_id,
uid=self.context.uid,
)
except AuditServiceException as e:
frame_audit_result.error = e
span.add_error_event(f"审核API调用异常: {str(e)}")
await self.context.output_queue_put(frame_audit_result, span)
except Exception as e:
span.add_error_event(f"审核API调用异常: {str(e)}")View on GitHub (pinned to 5e758547a8)