mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-05-27 06:11:40 +00:00
feat(yuanbao): prioritize quote media refs over history backfill in DispatchMiddleware
This commit is contained in:
parent
80efe664ce
commit
3df26b925c
1 changed files with 50 additions and 19 deletions
|
|
@ -2510,7 +2510,38 @@ class DispatchMiddleware(InboundMiddleware):
|
||||||
media_urls = list(ctx.media_urls)
|
media_urls = list(ctx.media_urls)
|
||||||
media_types = list(ctx.media_types)
|
media_types = list(ctx.media_types)
|
||||||
|
|
||||||
# Backfill observed media from recent transcript history
|
# If user quoted a message (reply_to_message_id is set), resolve only
|
||||||
|
# quote_media_refs to avoid injecting unrelated history media.
|
||||||
|
# Otherwise, backfill observed media from recent transcript history.
|
||||||
|
if ctx.reply_to_message_id is not None:
|
||||||
|
# User quoted a message — resolve only media from the quote
|
||||||
|
for rid, kind, filename in ctx.quote_media_refs:
|
||||||
|
if kind not in ("image", "file"):
|
||||||
|
continue
|
||||||
|
try:
|
||||||
|
fresh_url = await MediaResolveMiddleware._resolve_by_resource_id(adapter, rid)
|
||||||
|
except Exception as exc:
|
||||||
|
logger.warning(
|
||||||
|
"[%s] quote media resolve failed: rid=%s kind=%s err=%s",
|
||||||
|
adapter.name, rid, kind, exc,
|
||||||
|
)
|
||||||
|
continue
|
||||||
|
cached = await MediaResolveMiddleware._download_and_cache(
|
||||||
|
adapter,
|
||||||
|
fetch_url=fresh_url,
|
||||||
|
kind=kind,
|
||||||
|
file_name=filename or None,
|
||||||
|
log_tag=f"quote rid={rid}",
|
||||||
|
)
|
||||||
|
if cached is None:
|
||||||
|
continue
|
||||||
|
path, mime = cached
|
||||||
|
# Avoid duplicates
|
||||||
|
if path not in media_urls:
|
||||||
|
media_urls.append(path)
|
||||||
|
media_types.append(mime)
|
||||||
|
else:
|
||||||
|
# No quote — backfill observed media from recent transcript history
|
||||||
extra_img_urls: List[str] = []
|
extra_img_urls: List[str] = []
|
||||||
extra_img_mimes: List[str] = []
|
extra_img_mimes: List[str] = []
|
||||||
try:
|
try:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue