File size: 1,184 Bytes
6059138
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from __future__ import annotations

from langchain_core.messages import AIMessage, BaseMessage, HumanMessage

from memory_agent.agent import UniversalMemoryAgent
from memory_agent.config import AppConfig
from memory_agent.errors import RATE_LIMIT_MESSAGE, is_rate_limit_error


def main() -> None:
    config = AppConfig.from_env()
    agent = UniversalMemoryAgent(config=config)
    namespace = "local_cli_user"
    history: list[BaseMessage] = []

    print("Universal Memory Agent CLI. Type 'exit' to quit.")
    while True:
        user_input = input("You: ").strip()
        if not user_input:
            continue
        if user_input.lower() in {"exit", "quit"}:
            break

        try:
            response = agent.run(user_input=user_input, chat_history=history, namespace=namespace)
        except Exception as error:
            if is_rate_limit_error(error):
                response = RATE_LIMIT_MESSAGE
            else:
                response = f"Temporary error: {error}"
        print(f"Agent: {response}")
        history.append(HumanMessage(content=user_input))
        history.append(AIMessage(content=response))


if __name__ == "__main__":
    main()