How heart-breaker-beep/lexagent works
This is a Chinese-language legal assistant offering chat-based legal consultation, law retrieval, contract review, risk and jurisdiction analysis, limitation-period calculations, document drafting, web search, and evidence/document handling. The principal workflow is user chat through the FastAPI chat endpoint into a LangGraph agent, which can retrieve legal material and invoke MCP tools before streaming a response. Supporting subsystems provide retrieval and vector storage, contract analysis, persistent conversation and memory state, and a separate MCP tool server. Several links reflect explicit imports or documentation; unsampled implementation details are not inferred.
Main entry points: chat.py Chat endpoint · nodes.py Agent nodes · main.py FastAPI application · graph.py Agent graph
Components 21
Application entry
- FastAPI application
main.py - Chat endpoint
api/chat.py - Other API routes
api
Agent workflow
- Agent graph
agent/graph.py - Agent nodes
agent/nodes.py - LLM gateway
services/llm.py - MCP client
services/mcp_client.py
Legal capabilities
- MCP tool server
mcp_server/server.py - Legal MCP tools
mcp_server/tools - Contract analysis
services/contract_agent/workflow.py - Legal analysis
services/legal_analysis.py - Evidence handling
services/evidence_video.py
Legal knowledge
- Hybrid retrieval
services/retriever/hybrid.py - Vector store interface
services/vectorstore/base.py - Law vector store
services/vectorstore/chroma_store.py - Law indexing
services/indexer
Conversation state
- Thread checkpoints
services/checkpoint.py - Conversation memory
services/memory.py - Context compaction
services/context_compaction.py
Other components
- User
- LLM provider
Connections 21
- User → Chat endpoint: sends message
- FastAPI application → Chat endpoint: registers route
main.py - FastAPI application → Other API routes: registers routes
main.py - FastAPI application → Agent graph: builds graph
main.py - Chat endpoint → Agent graph: streams run
- Agent graph → Agent nodes: dispatches nodes
agent/graph.py - Agent nodes → LLM gateway: calls model
agent/nodes.py - LLM gateway → LLM provider: sends requests
services/llm.py - Agent nodes → Legal analysis: uses analysis
agent/nodes.py - Agent nodes → Contract analysis: uses formatter and schema
- Agent nodes → MCP client: uses MCP tools
- MCP client → MCP tool server: starts subprocess
services/mcp_client.py - MCP tool server → Legal MCP tools: registers tools
mcp_server/server.py - Legal MCP tools → Hybrid retrieval: retrieves laws
mcp_server/tools/review.py - Hybrid retrieval → Vector store interface: uses interface
services/retriever/__init__.py - Law vector store → Vector store interface: implements interface
services/vectorstore/chroma_store.py - Chat endpoint → Thread checkpoints: reads thread state
api/chat.py - Chat endpoint → Conversation memory: extracts memory
api/chat.py - Chat endpoint → Context compaction: reports compaction
api/chat.py - Chat endpoint → Evidence handling: uses evidence service
api/chat.py - Law indexing → Law vector store: writes law vectors