Files
task-6a02e23da6fe2e4ac16acf65/cli.py
T
2026-06-04 20:02:26 +00:00

49 lines
1.4 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""Simple interactive CLI for the RAG agent.
Commands:
/add title content add a document to the knowledge base.
/search query perform a semantic search.
/quit exit.
any other text will be sent to the agent for normal answering.
"""
import sys
from .agent import create_agent_executor
agent = create_agent_executor()
print("RAG Agent CLI. Type /quit to exit.")
while True:
try:
user_input = input(">>> ")
except EOFError:
break
if not user_input:
continue
if user_input.lower() == "/quit":
print("Goodbye!")
break
if user_input.startswith("/add "):
# Expected format: /add title content
parts = user_input.split(" ", 2)
if len(parts) < 3:
print("Usage: /add title content")
continue
title, content = parts[1], parts[2]
# Directly call the tool via the agent
result = agent.run({"input": f"Add document: {title} {content}"})
print(result)
continue
if user_input.startswith("/search "):
query = user_input[8:].strip()
result = agent.run({"input": f"Search for: {query}"})
print(result)
continue
# Normal conversation
result = agent.run({"input": user_input})
print(result)
if __name__ == "__main__":
# The CLI is already running in the main thread
pass