# Quickstart: Agent Chat Context & Guardrails **Feature**: 035-agent-chat-context **Branch**: `035-agent-chat-context` ## Development Setup ```bash # Backend (terminal 1) cd backend source .venv/bin/activate pip install -r requirements.txt python -m uvicorn src.app:app --reload --port 8000 # Gradio Agent (terminal 2 — separate process) cd backend source .venv/bin/activate python src/agent/run.py # Gradio listens on http://0.0.0.0:7860 # Frontend (terminal 3) cd frontend npm install npm run dev -- --port 5173 # → http://localhost:5173 ``` ## Verification ```bash # Backend tests cd backend && source .venv/bin/activate && python -m pytest -v # Frontend tests (L1 model + L2 component) cd frontend && npm run test # Lint cd backend && python -m ruff check . cd frontend && npm run lint ``` ## Docker ```bash docker compose up --build # Frontend: http://localhost:8000 # Backend API: http://localhost:8001 ``` ## Manual Test Flow 1. Open `http://localhost:5173/dashboards/10?env_id=ss-dev` 2. Click "Ask Agent" → navigates to `/agent?objectType=dashboard&objectId=10&envId=ss-dev` 3. **Verify**: Process steps pill shows «📋 Дашборд #10 · ss-dev» 4. **Verify**: Debug panel (ℹ️ → Показать) shows UIContext JSON + tool affinity 5. Type: «Расскажи про этот дашборд» → agent responds with dashboard-specific info 6. Type: «Задеплой на prod» → confirmation card with «PRODUCTION» badge 7. Switch EnvSelector to `prod` → chat background changes to warning tint + red banner 8. **Guardrails test**: Type «Удали дашборд #10» → dangerous confirmation card with 10s countdown 9. **Tool test**: Trigger a tool that times out → ToolCallCard shows ⏱️ + retry button ## Key Files Changed | File | What | |------|------| | `backend/src/agent/app.py` | `agent_handler` extended with uicontext; `_inject_uicontext()` | | `backend/src/agent/_tool_filter.py` | NEW — context-aware tool filtering | | `backend/src/agent/tools.py` | Retry wrapper, summarise, timeout helpers | | `backend/src/agent/_confirmation.py` | Extended confirmation metadata | | `frontend/src/lib/models/AgentChatModel.svelte.ts` | New atoms: uiContext, toolAffinity, dangerousCountdown, isProdContext | | `frontend/src/lib/models/AgentChat.StreamProcessor.svelte.ts` | New handlers: tool_retry, tool_timeout, extended confirm_required | | `frontend/src/lib/models/AgentChatTypes.ts` | New types: UIContext, ToolAffinityEntry, ConfirmMetadataV2 | | `frontend/src/lib/components/agent/AgentChat.svelte` | Prod background + banner + context pill | | `frontend/src/lib/components/assistant/ConfirmationCard.svelte` | 7 states: read/write/dangerous/denied + countdown | | `frontend/src/lib/components/assistant/ToolCallCard.svelte` | retrying/timeout/cancelled states + retry button | | `frontend/src/routes/agent/+page.svelte` | onMount context init from URL params | | `frontend/src/lib/stores/assistantChat.svelte.ts` | initialContext field |