| |
| """ |
| Local runner for Memory-Enabled LangChain Agent |
| """ |
|
|
| from langchain_memory_tools import create_memory_enabled_agent |
|
|
|
|
| def main(): |
| print("🧠 Starting Memory-Enabled Chat with Ollama...") |
|
|
| |
| model_name = "llama3.2:3b" |
|
|
| try: |
| agent = create_memory_enabled_agent(model_name) |
|
|
| print(f"✅ Agent with model '{model_name}' ready!") |
| print("💡 Example commands:") |
| print( |
| " - Save this insight: 'Quantum computers use qubits' with title 'Quantum Computing Basics' and tags 'quantum,computing,physics'") |
| print(" - Search my memories for quantum") |
| print(" - List all my memories") |
| print(" - Show memory statistics") |
| print(" - Type 'quit' to exit") |
| print() |
|
|
| while True: |
| try: |
| user_input = input("You: ").strip() |
|
|
| if user_input.lower() in ['quit', 'exit', 'bye']: |
| print("👋 Goodbye!") |
| break |
|
|
| if not user_input: |
| continue |
|
|
| print("🤔 Thinking...") |
| response = agent.invoke({"input": user_input}) |
| print(f"🤖 Agent: {response['output']}") |
| print("-" * 50) |
|
|
| except KeyboardInterrupt: |
| print("\n👋 Goodbye!") |
| break |
| except Exception as e: |
| print(f"❌ Error: {e}") |
| print("Continuing...") |
| continue |
|
|
| except Exception as e: |
| print(f"❌ Failed to initialize agent: {e}") |
| print("\n🔧 Troubleshooting:") |
| print("1. Make sure Ollama is running: ollama serve") |
| print(f"2. Make sure model is available: ollama pull {model_name}") |
| print("3. Check if Ollama is accessible at http://localhost:11434") |
|
|
|
|
| if __name__ == "__main__": |
| main() |