diff --git a/cli.py b/cli.py
index e9f50be..65ae45a 100644
--- a/cli.py
+++ b/cli.py
@@ -1,19 +1,34 @@
import sys
-from agent import executor
+from rag_tools import search_knowledge_base, add_to_knowledge_base
-if __name__ == "__main__":
+def run_cli():
print("RAG Agent CLI. Commands: /add
, /search , /quit")
while True:
- line = input("> ")
- if line.startswith("/quit"):
+ try:
+ inp = input("> ")
+ except EOFError:
break
- if line.startswith("/add"):
- _, title, file = line.split(maxsplit=2)
- with open(file, "r", encoding="utf-8") as f:
- text = f.read()
- print(executor.invoke({"input": f"add {title} {text}"}))
- elif line.startswith("/search"):
- _, query = line.split(maxsplit=1)
- print(executor.invoke({"input": f"search {query}"}))
+ if not inp:
+ continue
+ if inp.startswith("/quit"):
+ break
+ if inp.startswith("/add"):
+ parts = inp.split(maxsplit=2)
+ if len(parts) < 3:
+ print("Usage: /add ")
+ continue
+ title, file_path = parts[1], parts[2]
+ try:
+ with open(file_path, 'r', encoding='utf-8') as f:
+ content = f.read()
+ print(add_to_knowledge_base(content, title))
+ except Exception as e:
+ print("Error:", e)
+ elif inp.startswith("/search"):
+ query = inp[7:].strip()
+ print(search_knowledge_base(query))
else:
print("Unknown command")
+
+if __name__ == "__main__":
+ run_cli()