add cli.py
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
"""CLI for the RAG agent.
|
||||
|
||||
Commands:
|
||||
/add <text> — add text to the knowledge base
|
||||
/search <query> — 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 <text>, /search <query>, /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 <text>")
|
||||
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 <query>")
|
||||
continue
|
||||
result = search_knowledge_base.invoke({"query": query})
|
||||
print(result)
|
||||
|
||||
else:
|
||||
response = run_agent(user_input)
|
||||
print(f"Agent: {response}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user