feat: complete phase 1 -- core framework with chat loop, agents, and React UI
Backend: - FastAPI WebSocket /ws endpoint with streaming via LangGraph astream - LangGraph Supervisor connecting 3 mock agents (order_lookup, order_actions, fallback) - YAML Agent Registry with Pydantic validation and immutable configs - PostgresSaver checkpoint persistence via langgraph-checkpoint-postgres - Session TTL with 30-min sliding window and interrupt extension - LLM provider abstraction (Anthropic/OpenAI/Google) - Token usage + cost tracking callback handler - Input validation: message size cap, thread_id format, content length - Security: no hardcoded defaults, startup API key validation, no input reflection Frontend: - React 19 + TypeScript + Vite chat UI - WebSocket hook with reconnect + exponential backoff - Streaming token display with agent attribution - Interrupt approval/reject UI for write operations - Collapsible tool call viewer Testing: - 87 unit tests, 87% coverage (exceeds 80% requirement) - Ruff lint + format clean Infrastructure: - Docker Compose (PostgreSQL 16 + backend) - pyproject.toml with full dependency management
This commit is contained in:
68
backend/app/agents/order_lookup.py
Normal file
68
backend/app/agents/order_lookup.py
Normal file
@@ -0,0 +1,68 @@
|
||||
"""Order lookup tools -- read-only operations."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from types import MappingProxyType
|
||||
|
||||
from langchain_core.tools import tool
|
||||
|
||||
MOCK_ORDERS: MappingProxyType[str, dict] = MappingProxyType(
|
||||
{
|
||||
"1042": {
|
||||
"order_id": "1042",
|
||||
"status": "shipped",
|
||||
"items": ["Wireless Headphones", "USB-C Cable"],
|
||||
"total": 89.99,
|
||||
"placed_at": "2026-03-25",
|
||||
},
|
||||
"1043": {
|
||||
"order_id": "1043",
|
||||
"status": "processing",
|
||||
"items": ["Laptop Stand"],
|
||||
"total": 49.99,
|
||||
"placed_at": "2026-03-28",
|
||||
},
|
||||
"1044": {
|
||||
"order_id": "1044",
|
||||
"status": "delivered",
|
||||
"items": ["Mechanical Keyboard", "Mouse Pad"],
|
||||
"total": 159.99,
|
||||
"placed_at": "2026-03-20",
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
MOCK_TRACKING: MappingProxyType[str, dict] = MappingProxyType(
|
||||
{
|
||||
"1042": {
|
||||
"order_id": "1042",
|
||||
"carrier": "FedEx",
|
||||
"tracking_number": "FX-9876543210",
|
||||
"estimated_delivery": "2026-04-01",
|
||||
"current_location": "Distribution Center, Chicago IL",
|
||||
},
|
||||
"1044": {
|
||||
"order_id": "1044",
|
||||
"carrier": "UPS",
|
||||
"tracking_number": "1Z-5678901234",
|
||||
"estimated_delivery": "2026-03-22",
|
||||
"current_location": "Delivered",
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@tool
|
||||
def get_order_status(order_id: str) -> dict:
|
||||
"""Look up the current status of an order by order ID."""
|
||||
if order_id in MOCK_ORDERS:
|
||||
return dict(MOCK_ORDERS[order_id])
|
||||
return {"error": f"Order {order_id} not found", "order_id": order_id}
|
||||
|
||||
|
||||
@tool
|
||||
def get_tracking_info(order_id: str) -> dict:
|
||||
"""Get shipping and tracking information for an order."""
|
||||
if order_id in MOCK_TRACKING:
|
||||
return dict(MOCK_TRACKING[order_id])
|
||||
return {"error": f"No tracking information for order {order_id}", "order_id": order_id}
|
||||
Reference in New Issue
Block a user