How bymarcelolewin/care-assistant works
Purpose and Runtime Entry Points
CARE Assistant is a learning-focused insurance coverage chatbot. A FastAPI server starts at app/main.py, initializes mock data, mounts REST APIs, and serves the statically exported Next.js frontend. The operational entry point is uvicorn app.main:app; the browser client begins at frontend/app/page.tsx.
HTTP and Session Boundary
The backend API separates chat execution, graph inspection, and session lifecycle:
• app/api/chat.py accepts chat turns, retrieves/updates conversation context, invokes the agent, and returns response plus execution details.
• app/api/sessions.py owns server-side session/conversation management.
• app/api/graph.py exposes agent graph structure for UI visualization.
This is a single-server POC rather than a separately deployed frontend/backend system.
Agent State and LangGraph Orchestration
The core control flow is a LangGraph 1.0 agent:
• app/graph/state.py defines the shared typed state: messages, user context, tool results, and execution/trace information.
• app/graph/graph.py composes the executable workflow.
• app/graph/nodes.py runs the Ollama-backed LangChain model and tool-oriented stages; app/graph/edges.py conditionally routes between LLM/tool/final-response paths.
A chat request enters with session state, loops through LLM-directed tool calls when needed, then persists and returns the updated state.
LLM and External Observability
The agent uses a local Ollama model (default llama3.2), configured in app/graph/nodes.py; Ollama must run independently on the host. LangChain provides LLM/tool integration and LangGraph provides stateful execution. Optional LangSmith tracing is enabled through environment settings (.env.example) and is nonessential to local operation.
Domain Data and Tool Layer
Tools isolate insurance-domain lookups from orchestration:
• app/tools/coverage.py resolves plan coverage.
• app/tools/benefits.py verifies benefits.
• app/tools/claims.py retrieves claim status/history.
• app/data/loader.py loads root-level JSON fixtures from data/user_profiles.json, data/insurance_plans.json, and data/claims_data.json.
There is no database or live insurer integration; data access is local mock-data lookup.
Frontend Chat and Observability UI
The Next.js 15 static client calls FastAPI through frontend/lib/api.ts and renders the chat workflow from frontend/components/chat/ChatWindow.tsx. It presents messages and loading/thinking state, then conditionally surfaces execution internals through draggable windows:
• frontend/components/observability/DraggableMemoryWindow.tsx
• frontend/components/observability/DraggableGraphWindow.tsx
• frontend/components/observability/DraggableStepsWindow.tsx
These consume API response/state and graph endpoints, keeping agent observability distinct from the conversational UI.
Deployment Shape
Python 3.12–3.13 dependencies are managed by uv (pyproject.toml, uv.lock); frontend dependencies and static export are managed by npm under frontend/package.json. Building Next.js produces frontend/out/, which app/main.py serves. Required infrastructure is only the FastAPI process plus local Ollama; LangSmith is an optional cloud service.
Main entry points: main.py Application entry · loader.py Fixture loader · page.tsx Browser client · api.ts API client
Components 20
FastAPI server
- Application entry · Initializes mock data, mounts APIs, and serves the static client.
app/main.py - Chat API · Runs chat turns and returns responses with execution details.
app/api/chat.py - Sessions API · Manages server-side sessions and conversations.
app/api/sessions.py - Graph API · Exposes agent graph structure for visualization.
app/api/graph.py - Conversation state
Agent workflow
- LangGraph workflow · Executes the stateful LLM and tool loop.
app/graph/graph.py - Shared agent state · Carries messages, user context, tool results, and trace data.
app/graph/state.py - LLM and tool stages · Runs the Ollama-backed model and tool-oriented stages.
app/graph/nodes.py - Conditional routing · Routes among LLM, tool, and final-response paths.
app/graph/edges.py - Local Ollama · Independently runs the default llama3.2 model.
Mock domain data
- Insurance tools · Coverage, benefits, and claims lookups.
- Coverage lookup
app/tools/coverage.py - Benefits lookup
app/tools/benefits.py - Claims lookup
app/tools/claims.py - Fixture loader · Loads local user, plan, and claims JSON fixtures.
app/data/loader.py - JSON fixtures · User profiles, insurance plans, and claims data.
data/user_profiles.json
Static frontend
- Browser client · Starts the chat experience and observability UI.
frontend/app/page.tsx - API client
frontend/lib/api.ts - Chat window · Renders messages and thinking state.
frontend/components/chat/ChatWindow.tsx - Observability windows · Memory, graph, and execution-step views.
frontend/components/observability/DraggableGraphWindow.tsx
Connections 27
- Application entry → Chat API: mounts
- Application entry → Sessions API: mounts
- Application entry → Graph API: mounts
- Application entry → Fixture loader: initializes
- Application entry → Browser client: serves static export
- Browser client → Chat window: renders
- Browser client → API client: uses
- Browser client → Observability windows: shows
- API client → Chat API: chat turns
- API client → Sessions API: session lifecycle
- API client → Graph API: graph inspection
- Chat API → Conversation state: loads and persists
- Chat API → LangGraph workflow: invokes
- LangGraph workflow → Shared agent state: updates
- LangGraph workflow → LLM and tool stages: executes
- Conditional routing → LLM and tool stages: routes loop
- LLM and tool stages → Local Ollama: LLM inference
- LLM and tool stages → Insurance tools: tool calls
- Insurance tools → Coverage lookup: coverage
- Insurance tools → Benefits lookup: benefits
- Insurance tools → Claims lookup: claims
- Coverage lookup → Fixture loader: lookup
- Benefits lookup → Fixture loader: lookup
- Claims lookup → Fixture loader: lookup
- Fixture loader → JSON fixtures: loads
- Graph API → LangGraph workflow: inspects
- Observability windows → Graph API: visualizes