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