Open
Description
I just tried Anthropic streaming (pydantic-ai v0.0.20) and the stream comes in as one big chunk, not as an actual stream (although there is no longer an error about anthropic streaming not being supported). I can confirm the code is correct since a simple switch to "openai:gpt-4o" model creates an actual stream.
...
async with agent.run_stream(
user_prompt=prompt,
deps=agent_deps,
message_history=message_history
) as result:
# Stream the model's response
async for chunk in result.stream():
print("\nStreaming chunk:", chunk)
yield f"event: document_messages\ndata: {json.dumps(chunk)}\n\n"
...
I discovered that this only happens if I specify the result_type
(streaming works fine without):
class DocumentModelResponse(TypedDict, total=False):
model_response: str
document_md: str
agent = Agent(
agent_data["model"],
deps_type=AgentDeps,
result_type=DocumentModelResponse,
tools=tools,
system_prompt=system_prompt
)