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()