Skip to content

Agent chat crashes on multi-turn: 'dict' object has no attribute 'conversation_id' #166

@w7-mgfcode

Description

@w7-mgfcode

Summary

Running a real task in the agent chat crashes the stream:

Error: Stream error: 'dict' object has no attribute 'conversation_id'

Root cause

AgentService._deserialize_messages (app/features/agents/service.py) returns the raw stored dicts unchanged (return data # type: ignore), on the assumption that PydanticAI's run() accepts dict message history. That is false for PydanticAI 1.96 — ModelRequest / ModelResponse now carry a conversation_id field, and PydanticAI accesses msg.conversation_id on every history item. A plain dict has no such attribute → crash.

_serialize_messages is the matching half of the bug: it hand-rolls dataclasses.asdict() + a str() fallback, producing lossy dicts that cannot round-trip back into ModelMessage objects.

Net effect: any session turn that runs with non-empty message history crashes.

Fix

Use PydanticAI's own ModelMessagesTypeAdapter:

  • _serialize_messagesModelMessagesTypeAdapter.dump_python(messages, mode='json')
  • _deserialize_messagesModelMessagesTypeAdapter.validate_python(data), falling back to an empty history (with a warning) if stored data is in the old lossy format.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions