diff --git a/examples/persistance-agent/.env.example b/examples/persistance-agent/.env.example index 1f3564b..4dc4944 100644 --- a/examples/persistance-agent/.env.example +++ b/examples/persistance-agent/.env.example @@ -1,3 +1,4 @@ OPENAI_API_KEY= RPC_URL= SOLANA_PRIVATE_KEY= +POSTGRES_DB_URL= \ No newline at end of file diff --git a/examples/persistance-agent/README.md b/examples/persistance-agent/README.md new file mode 100644 index 0000000..e451c29 --- /dev/null +++ b/examples/persistance-agent/README.md @@ -0,0 +1,66 @@ +# Persistent Agent with PostgreSQL + +This example showcases a persistent agent that retains memory across sessions using a PostgreSQL database. It ensures that the agent can remember previous conversations even after being restarted, enhancing the user experience in applications requiring long-term context retention. +[Reference](https://langchain-ai.github.io/langgraphjs/reference/classes/checkpoint_postgres.PostgresSaver.html) + +## Key Features + +- **Persistent Memory**: The agent stores chat history in a PostgreSQL database, allowing it to remember past interactions across sessions. +- **Seamless Integration**: Designed to integrate smoothly with existing setups. +- **Scalable Solution**: Ideal for applications requiring long-term memory capabilities. + +## Prerequisites + +To use this feature, ensure you have the following: + +1. **PostgreSQL Database URL**: Create and host ur PostgreSQL databse and enter the URL. It will be of the format "postgresql://user:password@localhost:5432/db" + +## Before applying persistance +``` +Available modes: +1. chat +- Interactive chat mode +2. auto +- Autonomous action mode +Choose a mode (enter number or name: 1 +Starting chat mode... Type 'exit' to end. +Prompt: i am arpit +Hello Arpit! How can I assist you today? +Prompt: ^С +® arpitsingh Mac persistance-agent & ts-node index.ts +Starting Agent... +Available modes: +1. chat +- Interactive chat mode +2. auto +- Autonomous action mode +Choose a mode (enter number or name): 1 +Starting chat mode... Type 'exit' to end. +Prompt: do u know my name +I don't know your name yet. If you'd like, you can share it. +``` +## After applying persistence +``` +Available modes: +1. chat +- Interactive chat mode +2. auto +- Autonomous action mode +Choose a mode (enter number or name: 1 +Starting chat mode... Type 'exit' to end. +Prompt: i am arpit +Hello Arpit! How can I assist you today? +Prompt: ^С +® arpitsingh Mac persistance-agent & ts-node index.ts +Starting Agent... +Available modes: +1. chat +- Interactive chat mode +2. auto +- Autonomous action mode +Choose a mode (enter number or name): 1 +Starting chat mode... Type 'exit' to end. +Prompt: do u know my name +Yes, you mentioned that your name is Arpit. How can I help you today? +``` + diff --git a/examples/persistance-agent/index.ts b/examples/persistance-agent/index.ts index 451bef7..d679829 100644 --- a/examples/persistance-agent/index.ts +++ b/examples/persistance-agent/index.ts @@ -9,7 +9,7 @@ import { PostgresSaver } from "@langchain/langgraph-checkpoint-postgres"; dotenv.config(); const checkpointer = PostgresSaver.fromConnString( - "postgresql://user:password@localhost:5432/db" + process.env.POSTGRES_DB_URL! ); function validateEnvironment(): void {