Hi, I’m receiving this error when I try to show the response from the agent using:agent.run(message, stream=True)
When I use await agent.aprint_response(message, stream=True) it works perfectly but i don’t want to show in terminal the response, i want to stream it to my web application.
If you guys can help me with a good approach to stream the agent responses to an web application
the error:
part of the code:
async def run_agent(message: str) → None:
“”“Run the filesystem agent with the given message.”“”
server_params = StdioServerParameters(
command=“python”,
args=[
“/home/hz/dev/mcp/server.py”,
],
)
# Create a client session to connect to the MCP server
async with stdio_client(server_params) as (read, write):
async with ClientSession(read, write) as session:
agent = await create_r_agent(session)
# Run the agent
# await agent.aprint_response(message, stream=True)
run_response = agent.run(message, stream=True)
for chunk in run_response:
print(chunk.content)
obs: is the same template as this example: Model Context Protocol - Agno