This repo contains an example of using the Laws.Africa Knowledge Base API in a simple RAG setup with LangGraph.
The example restricts its queries to Cape Town using the place code za-cpt.
- Takes a user query as input
- Uses an LLM to come up with a search query for the Knowledge Base, based on the user's query.
- Searches the Knowledge Base using the generated search query to retrieve relevant documents.
- Answers the user's query using the retrieved documents as context.
- Python 3.11 or later
- An OpenAI API key.
- A Laws.Africa API key. You can get one by following these instructions.
-
Clone this repository and navigate to the project directory:
git clone cd laws-africa-knowledge-base-examples -
Setup a virtual environment (optional but recommended):
python -m venv venv source venv/bin/activate -
Install dependencies:
pip install -r requirements.txt
-
Set your OpenAI and Laws.Africa API keys as environment variables, or add them to a new
.envfile:export OPENAI_API_KEY='your-openai-api-key' export LAWS_AFRICA_API_KEY='your-laws-africa-api-key'
This is a simple visual way to run the agent, using the LangGraph CLI and LangGraph's Agent Chat UI.
langgraph dev --no-browserOpen your browser and go to https://agentchat.vercel.app/?apiUrl=http://localhost:2024
Type in legislation_agent or judgment_agent to choose the respective agent and click Continue.
That will present you with a chat interface where you can interact with the agent.
Ask: How many dogs can I own? or Cases for delict in a slip and trip scenario
You can also run the agent directly using the provided agent.py script. It
requires a single argument to choose which knowledge base agent to run:
python agent.py legislation
python agent.py judgmentChoose legislation for the Cape Town legislation RAG flow, or judgment to query the judgments
knowledge base.
Ask: How many dogs can I own? or Cases for delict in a slip and trip scenario