This case demonstrates a simple legal consultation agent built utilizing RagPlanner
. The agent provides legal advice by retrieving relevant provisions from the Civil Law and the Criminal Law, and integrating them with the case background.
The case leverages the embedding and reranking features of DashScope in conjunction with the Qwen llm. Before using this, you need to configure the DASHSCOPE_API_KEY
in your environment variables.
The legal knowledge base is constructed using Knowledge Components from agentUniverse. By storing the original legal provisions in the both ChromaDB and Sqlite database, the knowledge base enables efficient retrieval and consultation for the agent. Original legal documents
name: "law_knowledge"
description: "中国民法与刑法相关的知识库"
stores:
- "civil_law_chroma_store"
- "criminal_law_chroma_store"
- "civil_law_sqlite_store"
- "criminal_law_sqlite_store"
query_paraphrasers:
- "custom_query_keyword_extractor"
insert_processors:
- "recursive_character_text_splitter"
rag_router: "nlu_rag_router"
post_processors:
- "dashscope_reranker"
readers:
pdf: "default_pdf_reader"
metadata:
type: 'KNOWLEDGE'
module: 'sample_standard_app.intelligence.agentic.knowledge.law_knowledge'
class: 'LawKnowledge'
For your convenience, we have placed the databases containing the relevant information in this directory. If you want to build the knowledge base from scratch, you can run the following code:
from agentuniverse.base.agentuniverse import AgentUniverse
from agentuniverse.agent.action.knowledge.knowledge_manager import KnowledgeManager
if __name__ == '__main__':
AgentUniverse().start(config_path='../../config/config.toml', core_mode=True)
civil_store_list = ["civil_law_sqlite_store", "civil_law_chroma_store"]
criminal_store_list = ["criminal_law_sqlite_store", "criminal_law_chroma_store"]
law_knowledge = KnowledgeManager().get_instance_obj("law_knowledge")
law_knowledge.insert_knowledge(
source_path="../resources/刑法.pdf",
stores=criminal_store_list
)
law_knowledge.insert_knowledge(
source_path="../resources/民法典.pdf",
stores=civil_store_list
)
This agent involves the following file:
- law_rag_agent.yaml: Defines the agent's related prompts