-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.py
More file actions
85 lines (67 loc) · 2.15 KB
/
Copy pathcli.py
File metadata and controls
85 lines (67 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
"""
Ultra-minimal CLI for the agent
Made by Rodrigo de Sarasqueta
"""
import asyncio
import sys
from pathlib import Path
from config import Config
from core.agent import MinimalAgent
async def main():
"""Simple chat interface"""
print("AgentAlpha - Minimalist AI Agent")
print("Commands: 'quit' to exit, 'clear' to reset memory")
print("=" * 50)
# Initialize agent
try:
config = Config()
agent = MinimalAgent(config.to_dict())
await agent.initialize()
print("Agent ready!\n")
except Exception as e:
print(f"Error: {e}")
sys.exit(1)
# Chat loop
while True:
try:
user_input = input("You: ").strip()
if not user_input:
continue
if user_input.lower() in ['quit', 'exit']:
print("Goodbye!")
break
if user_input.lower() == 'clear':
await agent.clear_memory()
print("Memory cleared.\n")
continue
# Get response
result = await agent.chat(user_input)
if result["success"]:
print(f"Agent: {result['response']}\n")
else:
print(f"Error: {result['response']}\n")
except KeyboardInterrupt:
print("\nGoodbye!")
break
except Exception as e:
print(f"Error: {e}\n")
def add_pdf(file_path: str):
"""Add PDF to knowledge base"""
async def _add():
config = Config()
agent = MinimalAgent(config.to_dict())
await agent.initialize()
try:
doc_id = await agent.add_document(file_path)
print(f"Document added: {doc_id}")
except Exception as e:
print(f"Error: {e}")
asyncio.run(_add())
if __name__ == "__main__":
if len(sys.argv) > 1 and sys.argv[1] == "add-pdf":
if len(sys.argv) < 3:
print("Usage: python cli.py add-pdf <file.pdf>")
sys.exit(1)
add_pdf(sys.argv[2])
else:
asyncio.run(main())