From 9f01b8a908b1eb512fefd4625638ed072dcd36c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B8=D1=80=D0=B8=D0=BB=D0=BB=20=D0=9A=D1=83=D1=82?= =?UTF-8?q?=D0=BB=D0=B0=D1=85=D0=BC=D0=B5=D1=82=D0=BE=D0=B2?= Date: Thu, 28 May 2026 13:38:13 +0000 Subject: [PATCH] add cli.py --- cli.py | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 cli.py diff --git a/cli.py b/cli.py new file mode 100644 index 0000000..19a3eff --- /dev/null +++ b/cli.py @@ -0,0 +1,51 @@ +"""CLI for the RAG agent. + +Commands: + /add — add text to the knowledge base + /search — search the knowledge base + /quit — exit the program + +Any other input is forwarded to the agent as a normal question. +""" +from agent import run_agent, search_knowledge_base, add_to_knowledge_base + + +def main() -> None: + print("RAG Agent CLI. Commands: /add , /search , /quit") + while True: + try: + user_input = input("You: ").strip() + except (EOFError, KeyboardInterrupt): + print("\nExiting.") + break + + if not user_input: + continue + + if user_input == "/quit": + print("Goodbye!") + break + + elif user_input.startswith("/add "): + text = user_input[5:].strip() + if not text: + print("Usage: /add ") + continue + result = add_to_knowledge_base.invoke({"text": text}) + print(result) + + elif user_input.startswith("/search "): + query = user_input[8:].strip() + if not query: + print("Usage: /search ") + continue + result = search_knowledge_base.invoke({"query": query}) + print(result) + + else: + response = run_agent(user_input) + print(f"Agent: {response}") + + +if __name__ == "__main__": + main()