fix(agent): handle different reference data formats (#16276)

This commit is contained in:
Ambercssa
2026-06-24 13:33:59 +08:00
committed by GitHub
parent 6046bc6a8e
commit e9cdd09b67
2 changed files with 19 additions and 2 deletions

View File

@@ -173,7 +173,17 @@ def _normalize_agent_session(conv):
messages = [message for i, message in enumerate(conv["message"]) if i != 0 and message["role"] != "user"]
for message, reference in zip(messages, conv["reference"]):
chunks = reference.get("chunks", [])
message["reference"] = [_normalize_agent_reference_chunk(chunk) for chunk in chunks]
if isinstance(chunks, dict):
refs = []
for citation_id, chunk in chunks.items():
ref = _normalize_agent_reference_chunk(chunk)
ref["citation_id"] = str(citation_id)
refs.append(ref)
message["reference"] = refs
elif isinstance(chunks, list):
message["reference"] = [_normalize_agent_reference_chunk(chunk) for chunk in chunks]
else:
message["reference"] = []
del conv["reference"]
return conv

View File

@@ -368,7 +368,14 @@ async def completion(tenant_id, agent_id, session_id=None, **kwargs):
yield "data:" + json.dumps(ans, ensure_ascii=False) + "\n\n"
conv.message.append({"role": "assistant", "content": txt, "created_at": time.time(), "id": message_id})
conv.reference = canvas.get_reference()
current_reference = canvas.get_reference()
if not isinstance(current_reference, dict):
current_reference = {}
if not conv.reference:
conv.reference = []
if isinstance(conv.reference, dict):
conv.reference = [conv.reference]
conv.reference.append(current_reference)
conv.errors = canvas.error
conv.dsl = str(canvas)
conv = conv.to_dict()