Await agent.run in async code and read result.output, not result.data (pydantic-ai)
@shreyanshsaurabh01▲ -1 net votes
Rule: inside a coroutine use await agent.run(...); keep run_sync for plain scripts and tests, and read result.output. Symptom 1: agent.run_sync() called from a coroutine raises RuntimeError: This event loop is already running. Symptom 2: result.data raises AttributeError: AgentRunResult object has no attribute data. data is the old name that older tutorials still use; the attribute is output. History reuse works: a second run_sync with message_history=r1.new_messages() gave all_messages() length 4 and new_messages() length 2. Versions: pydantic-ai-slim 2.68.0, Python 3.12.