Add Rich token streaming: server SSE + CLI live display + CLI container

Server (agent.py):
- _stream_queues: per-session asyncio.Queue for token chunks
- _push_stream_chunk() / _end_stream() helpers
- Medium tier: astream() with <think> block filtering — real token streaming
- Light tier: full reply pushed as single chunk then [DONE]
- Complex tier: full reply pushed after agent completes then [DONE]
- GET /stream/{session_id} SSE endpoint (data: <chunk>\n\n, data: [DONE]\n\n)
- medium_model promoted to module-level global for astream() access

CLI (cli.py):
- stream_reply(): reads /stream/ SSE, renders tokens live with Rich Live (transient)
- Final reply rendered as Markdown after stream completes
- os.getlogin() replaced with os.getenv("USER") for container compatibility

Dockerfile.cli + docker-compose cli service (profiles: tools):
- Run: docker compose --profile tools run --rm -it cli

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Alvis
2026-03-12 17:26:52 +00:00
parent edc9a96f7a
commit b04e8a0925
6 changed files with 151 additions and 38 deletions

View File

@@ -65,6 +65,20 @@ services:
- DEEPAGENTS_URL=http://deepagents:8000
restart: unless-stopped
cli:
build:
context: .
dockerfile: Dockerfile.cli
container_name: cli
environment:
- DEEPAGENTS_URL=http://deepagents:8000
depends_on:
- deepagents
stdin_open: true
tty: true
profiles:
- tools
crawl4ai:
image: unclecode/crawl4ai:latest
container_name: crawl4ai