Skip to content

Some AgentEvent are not serializable #4626

@woodside-david-francoeur

Description

Bug Description

We have a piece of code to record all the AgentEvent for a given session in a json file and write that to S3 for investigation and debugging purposes.

Is the AgentEvent class supposed to be serializable or did we assume wrong? This piece of code served as an inspiration for us:
https://github.com/livekit/agents/blob/f46b5916ef2c940930b357e49bce71553e9daee2/livekit-agents/livekit/agents/voice/report.py

Expected Behavior

No serialization error at runtime and fields that can't be serialized are skipped.

Reproduction Steps

Here is a minimal reproduction of the problem we have experienced:


def main_error_json():
    from collections.abc import Sequence

    from livekit.agents import AgentEvent, ErrorEvent
    from livekit.plugins.openai import LLM
    from pydantic import TypeAdapter

    TypeAdapter(Sequence[AgentEvent]).dump_json([ErrorEvent(type="error", error="oops",source=LLM())]),
    
if __name__ == '__main__':
    main_error_json()

Operating System

macos

Models Used

No response

Package Versions

livekit-agents = { version = "~1.3.10", extras = [
    "cartesia",
    "deepgram",
    "elevenlabs",
    "openai",
    "silero",
    "turn-detector",
] }


From the poetry lock:

[[package]]
name = "livekit"
version = "1.0.23"
description = "Python Real-time SDK for LiveKit"
optional = false
python-versions = ">=3.9.0"
groups = ["agent"]
files = [
    {file = "livekit-1.0.23-py3-none-macosx_10_9_x86_64.whl", hash = "sha256:e2cdea92fad7d1ccf97ee93c13b1577ef2a2e6faaae2f5e6b753d628c33eb618"},
    {file = "livekit-1.0.23-py3-none-macosx_11_0_arm64.whl", hash = "sha256:8a6638fc15025fc1fccb299ffaa4776f2bb5fa1accb749316e1d610a33086432"},
    {file = "livekit-1.0.23-py3-none-manylinux_2_28_aarch64.whl", hash = "sha256:e195f9b6e3afb66d8ef304bb4931367a161372cc078deaef2ead90aa0b25adbe"},
    {file = "livekit-1.0.23-py3-none-manylinux_2_28_x86_64.whl", hash = "sha256:9acb18617241a54a973bad2c1f22d097eb2254a7b0e7eed1d56b6e54face872b"},
    {file = "livekit-1.0.23-py3-none-win_amd64.whl", hash = "sha256:68adfd55ad54eb439eb67c8299fc47ae137180c60445786180f85811d28877d0"},
    {file = "livekit-1.0.23.tar.gz", hash = "sha256:890bf0b4062b1b6ea7213bef5c39a04c18cfa5021ca7171ce979219caf568f57"},
]
[...]
[[package]]
name = "livekit-agents"
version = "1.3.10"
description = "A powerful framework for building realtime voice AI agents"
optional = false
python-versions = "<3.14,>=3.9"
groups = ["agent"]
files = [
    {file = "livekit_agents-1.3.10-py3-none-any.whl", hash = "sha256:9395a20b3f0267f814117d8eae702bdac001ee03e06163953229a476ca00d74d"},
    {file = "livekit_agents-1.3.10.tar.gz", hash = "sha256:a5d49cd36122834b32f48d71e891b9f80c1c5f8a0860622e941eaf487a16ce6e"},
]
[...]

Session/Room/Call IDs

No response

Proposed Solution

Additional Context

No response

Screenshots and Recordings

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions