{"id":"TufSaORJ","creatorId":"anonymous","title":"#9945 baseline: no session lifecycle, no cross-run input owner, no connection/steering surface in current Pydantic AI core","createdAt":1791342052618,"updatedAt":1791342052618,"latestVersionNum":1,"versions":[{"versionNum":1,"version":null,"branchName":null,"branchSha":null,"runRelease":true,"runBranch":false,"sdkDeps":{"pip":["No network access required; uses only TestModel and FunctionModel in-tree doubles.","Run with pydantic-ai from the repository checkout."]},"snippets":[{"id":"session-surface","name":"No session surface for ordinary agents","code":"import asyncio\nfrom pydantic_ai import Agent\nfrom pydantic_ai.models.test import TestModel\n\nasync def main():\n    agent = Agent(TestModel())\n    print(\"Agent has .session:\", hasattr(agent, \"session\"))  # False\n    print(\"Agent MRO:\", [c.__name__ for c in type(agent).__mro__[:2]])  # ['Agent', 'AbstractAgent']\n    # the only session() in the package is realtime-only:\n    #   pydantic_ai_slim/pydantic_ai/agent/abstract.py:2371 (AgentRealtime facade)\n    facade = agent.realtime(TestModel())\n    print(\"facade is async CM:\", hasattr(facade, \"__aenter__\"))  # False\n\nasyncio.run(main())","primaryOutput":null,"comparisonOutput":null},{"id":"enqueue-dies-with-run","name":"Pending input owner dies with the run","code":"import asyncio\nfrom pydantic_ai import Agent\nfrom pydantic_ai.models.test import TestModel\n\nasync def main():\n    agent = Agent(TestModel())\n    async with agent.iter(\"first prompt\") as run:\n        async for _ in run:\n            pass\n    try:\n        run.enqueue(\"late input\")\n    except Exception as e:\n        print(f\"enqueue after end: {type(e).__name__}: {e}\")\n    # UserError: 'enqueue' is not available because the agent run has ended.\n    # enforcement: PendingMessageQueue.append, _enqueue.py:181-185; queue closes at run end (drain_at_end, _enqueue.py:191-198)\n    r2 = await agent.run(\"second prompt\")\n    print(\"2nd run sees 'late input':\", any(\"late input\" in str(p) for m in r2.all_messages() for p in m.parts))  # False\n\nasyncio.run(main())","primaryOutput":null,"comparisonOutput":null},{"id":"mid-response-delivery","name":"Mid-request input lands at the next model-request boundary","code":"import asyncio\nfrom pydantic_ai import Agent\nfrom pydantic_ai.messages import ModelRequest, ModelResponse, TextPart\nfrom pydantic_ai.models.function import AgentInfo, FunctionModel\n\nasync def main():\n    started, release = asyncio.Event(), asyncio.Event()\n    seen = []\n\n    async def function(messages, agent_info: AgentInfo) -> ModelResponse:\n        n_req = sum(isinstance(m, ModelRequest) for m in messages)\n        seen.append([type(p).__name__ + \":\" + str(getattr(p, 'content', ''))[:30] for p in messages[-1].parts])\n        if n_req <= 1:\n            started.set()\n            await release.wait()  # request #1 in flight\n            return ModelResponse(parts=[TextPart(\"response-1\")])\n        return ModelResponse(parts=[TextPart(\"response-2\")])\n\n    agent = Agent(FunctionModel(function=function))\n    holder = {}\n\n    async def drive():\n        async with agent.iter(\"go\") as run:\n            holder[\"run\"] = run\n            async for _ in run:\n                pass\n\n    task = asyncio.create_task(drive())\n    while \"run\" not in holder:\n        await asyncio.sleep(0)\n    run = holder[\"run\"]\n    await started.wait()\n    run.enqueue(\"mid-request input\")  # accepted while request #1 is in flight\n    release.set()\n    await task\n    print(\"final output:\", run.result.output)  # response-2\n    for i, parts in enumerate(seen):\n        print(f\"request #{i + 1} saw:\", parts)  # input arrives as a NEW request, never inside #1\n\nasyncio.run(main())","primaryOutput":null,"comparisonOutput":null}],"createdAt":1791342052618}]}