diff --git a/src/agents/tatlock.py b/src/agents/tatlock.py index e26a945..1c74175 100644 --- a/src/agents/tatlock.py +++ b/src/agents/tatlock.py @@ -587,16 +587,23 @@ class TatlockAgent(AgentInterface): ModelResponse(parts=[TextPart(content=content)]) ) - # Stream with scoped tools and tracker - async with scoped_agent.run_stream( + # Use run() instead of run_stream() to avoid Ollama 400 bug + # with streaming + tool calls (PydanticAI issues #1292, #2256) + # We yield the final response in chunks to maintain streaming interface + result = await scoped_agent.run( enriched_message, message_history=pydantic_history if pydantic_history else None, deps=tool_tracker - ) as stream: - async for chunk in stream.stream_text(delta=True): - yield chunk + ) - logger.info("tatlock_stream_complete") + # Stream the final response in chunks to maintain UX + response_text = result.output + chunk_size = 50 # characters per chunk + + for i in range(0, len(response_text), chunk_size): + yield response_text[i:i + chunk_size] + + logger.info("tatlock_scoped_run_complete") async def get_capabilities(self) -> dict: """Return current capabilities."""