Repository navigation
Description
Description
BaseRunOutputEvent.from_dict (libs/agno/agno/run/base.py:268) rebuilds the media fields
with pydantic model_validate:
images->Image.model_validate(line 268)videos->Video.model_validate(line 272)audio->Audio.model_validate(line 276)response_audio->Audio.model_validate(line 286)image->Image.model_validate(line 290)
to_dict/to_json writes base64-encoded content for these fields, and pydantic coerces a
str straight to bytes, so the deserialized content becomes the ASCII of the base64
text instead of the decoded payload. An event carrying media therefore does not survive
to_dict -> from_dict.
Three lines above, in the same function, files is handled correctly with
agno.utils.media.reconstruct_files (lines 280-282). The sibling
RunOutput.from_dict (libs/agno/agno/run/agent.py) uses
reconstruct_images / reconstruct_videos / reconstruct_audio_list /
reconstruct_response_audio for exactly these fields and round-trips the same payload
losslessly.
Reachability: run_output_event_from_dict (libs/agno/agno/run/agent.py:609) dispatches to
BaseRunOutputEvent.from_dict, and it is the parser for the AgentOS client SSE stream
(libs/agno/agno/client/os.py:650, :736, and the team/workflow variants at :927, :1049,
:1235, :1336), as well as for stored/session-loaded runs via
RunOutput.from_dict (run/agent.py:879) and TeamRunOutput.from_dict (run/team.py:979).
Any run stored with stream_events=True whose model produced image/video/audio content, and
any AgentOS client consuming such a stream, is affected.
Steps to Reproduce
import json
from agno.media import Audio, Image, Video, File
from agno.run.agent import RunCompletedEvent, RunOutput, run_output_event_from_dict
RAW = b"\x00\x01\x02\xffhello-media"
event = RunCompletedEvent(
run_id="r1",
response_audio=Audio(id="a1", content=RAW, transcript="hi"),
audio=[Audio(id="a2", content=RAW)],
images=[Image(id="i1", content=RAW)],
videos=[Video(id="v1", content=RAW)],
files=[File(id="f1", filename="a.bin", content=RAW)],
)
restored = run_output_event_from_dict(json.loads(event.to_json()))
run_output = RunOutput(
run_id="r1",
response_audio=Audio(id="a1", content=RAW, transcript="hi"),
audio=[Audio(id="a2", content=RAW)],
images=[Image(id="i1", content=RAW)],
videos=[Video(id="v1", content=RAW)],
files=[File(id="f1", filename="a.bin", content=RAW)],
)
ro = RunOutput.from_dict(json.loads(run_output.to_json()))
print(f"response_audio | {restored.response_audio.content == RAW} | {ro.response_audio.content == RAW}")
print(f"audio[0] | {restored.audio[0].content == RAW} | {ro.audio[0].content == RAW}")
print(f"images[0] | {restored.images[0].content == RAW} | {ro.images[0].content == RAW}")
print(f"videos[0] | {restored.videos[0].content == RAW} | {ro.videos[0].content == RAW}")
print(f"files[0] | {restored.files[0].content == RAW} | {ro.files[0].content == RAW}")The same script is the reproduction used by both verifiers below
(/tmp/repro_event_media_base64.py), plus an SSE round-trip through the AgentOS client.
- Create a
RunCompletedEventwith bytes-typed image/video/audio/response_audio content. - Serialize with
to_json()and deserialize withrun_output_event_from_dict. - Compare
contentagainst the original bytes.
Agent Configuration (if applicable)
Not required to reproduce; the failure is in the event (de)serializer and shows up with any
agent or team whose model returns media, e.g. an audio/image/video-capable model streamed to
an AgentOS client or persisted with stream_events=True.
Expected Behavior
type(event).from_dict(json.loads(event.to_json())) should be lossless for media content, the
same way RunOutput.from_dict already is: base64 content strings must be decoded back to
bytes.
Concrete basis:
- Sibling branch in the same function,
libs/agno/agno/run/base.py:280-282, already uses
agno.utils.media.reconstruct_filesforfiles— the same situation, handled correctly. RunOutput.from_dict(libs/agno/agno/run/agent.py, and likewise
TeamRunOutput.from_dictrun/team.py:1013-1026,WorkflowRunOutput.from_dict
run/workflow.py:1033-1037) callsreconstruct_images/reconstruct_videos/
reconstruct_audio_list/reconstruct_response_audiofor exactly these fields.agno/utils/media.pydocuments the contract:reconstruct_image_from_dict— "Handles media
references (from external storage), base64-encoded content (from database) ... # If content
is base64 string, decode it back to bytes" and then callsImage.from_base64(same shape for
video/audio/file at lines 294, 347, 394, 443), whileImage.to_dictdocuments "Convert to
dict, optionally including base64-encoded content" and emitsself.to_base64(). The
round-trip is symmetric by design.- The field annotations are
images: Optional[List[Image]]andresponse_audio: Optional[Audio],
i.e. bytes-typed media, not base64 text.
Actual Behavior
Media comes back as the ASCII bytes of the base64 text (length 344 instead of 256 for the test
payload; files — the one field using reconstruct_files — is correct):
Verifier 1 (run on the default branch, same script):
images[0] equal=False len=344 head=b'AAECAwQFBgcICQoLDA0O'
videos[0] equal=False len=344 head=b'AAECAwQFBgcICQoLDA0O'
audio[0] equal=False len=344 head=b'AAECAwQFBgcICQoLDA0O'
response_audio equal=False len=344 head=b'AAECAwQFBgcICQoLDA0O'
files[0] equal=True len=256 head=b'\x00\x01\x02\x03\x04\x05\x06\x07...'
SSE: server frame "content":"iVBORw0KGgoAAQID" -> client b'iVBORw0KGgoAAQID', PNG magic False
Verifier 2 (independent, same script, base64 content):
EVENT images equal=False got=b'iVBORw0KGgoAAQL/YmluYXJ5LW1lZGlhLWJ5dGVz'
EVENT videos equal=False got=b'iVBORw0KGgoAAQL/YmluYXJ5LW1lZGlhLWJ5dGVz'
EVENT audio equal=False got=b'iVBORw0KGgoAAQL/YmluYXJ5LW1lZGlhLWJ5dGVz'
EVENT response_audio equal=False got=b'iVBORw0KGgoAAQL/YmluYXJ5LW1lZGlhLWJ5dGVz'
EVENT files equal=True got=b'\x89PNG\r\n\x1a\n\x00\x01\x02\xffbinary-media-bytes'
SSE frame response_audio equal=False b'iVBORw0KGgoAAQL/YmluYXJ5LW1lZGlhLWJ5dGVz'
Downstream, the "image"/"audio" is no longer a valid media file: it is base64 text stored in a
bytes field, so any consumer writing it to disk or handing it to a model gets a corrupt file
(PNG magic check fails in the SSE case above).
Screenshots or Logs (if applicable)
Not applicable — the console output above is the full evidence.
Environment
- OS: macOS 26.6.2 (Darwin 25.6.0)
- Agno Version: 3.0.9 (editable install), commit 44219f8532e2fe6ce936850455f4b9a2567e4194 (main)
- External Dependency Versions: pydantic 2.13.5
- Additional Environment Details: Python 3.12.14
Possible Solutions (optional)
In BaseRunOutputEvent.from_dict use the same helpers the files branch and
RunOutput.from_dict already use: reconstruct_images(images), reconstruct_videos(videos),
reconstruct_audio_list(audio), reconstruct_response_audio(response_audio) (and
reconstruct_image(image) for the single image field at line 290), imported from
agno.utils.media. Those helpers already handle both the base64-string case and the
media_reference case, so behaviour would match RunOutput.from_dict.
Additional Context (optional)
- Collision check (search of issues/PRs in the repo for this bug and for the affected file)
found no existing issue or PR for it. The only open PR touching
libs/agno/agno/run/base.pyis feat: verifiers — pure checks, per-check policy, three mounts [SDK-596] #9818 (verifiers — pure checks), a different feature area,
so the fix does not overlap with it. Previous related work of mine in this repo: [Bug] Sync tool execution sends an empty tool result to the model when the tool returns 0 / False / [] (async path sends "0") #9947/[fix] keep falsy tool results (0, False, []) on the sync tool execution path #9948,
unrelated to media serialization. - I am happy to open a PR with the approach above (with a round-trip test for the event path
mirroring theRunOutput.from_dictbehaviour) if that is welcome. - AI disclosure: this report was drafted with AI assistance (Claude Code) and I reproduced and
verified every command and output quoted above in a local checkout of the commit named in
Environment.
Activity
BlueX888 commentedon Sep 16, 2026
Reproduced this. Root cause: libs/agno/agno/run/base.py:268-290: images/videos/audio/response_audio/image are rebuilt with Image/Video/Audio.model_validate while files on the next branch uses agno.utils.media.reconstruct_files, and pydantic coerces the base64 text to bytes, so content becomes the ASCII of the base64 instead of the decoded payload; in the output above column 1 is run_output_event_from_dict and column 2 is RunOutput.from_dict.
Minimal reproduction:
Observed output:
Happy to open a PR with this fix, or to be assigned if you prefer to take it.