├── README.md └── paychain-examples ├── .gitignore ├── examples ├── __init__.py └── test_agent.py └── requirements.txt /README.md: -------------------------------------------------------------------------------- 1 | # Paychain 🔗💰 2 | 3 | Build AI agents that can send real money using natural language with LangChain and Payman. Paychain combines the power of LLMs with Payman's secure payment infrastructure to enable conversational financial transactions. 4 | 5 | ## Why Paychain? 6 | 7 | - 🤖 **Natural Language Payments**: Let AI agents process payments through simple conversations 8 | - 🔒 **Built on Payman**: Leverage Payman's enterprise-grade payment infrastructure 9 | - 🚀 **Quick Integration**: Get started in minutes with our Python SDK 10 | - 💡 **Flexible Tools**: Rich set of Payman payment operations including sending, requesting, and managing payees 11 | - 🛠️ **Built with LangChain**: Leverage the power of the LangChain ecosystem 12 | 13 | ## Quick Start 🚀 14 | 15 | 1. Get your API keys: 16 | - Go to [app.paymanai.com](https://app.paymanai.com) to get your Payman API key 17 | - Sign up takes just a few seconds and lets you send real money with Payman 18 | - Get your OpenAI API key from [platform.openai.com](https://platform.openai.com) 19 | 20 | 2. Clone the repository: 21 | ```bash 22 | git clone 23 | cd paychain-examples 24 | ``` 25 | 26 | 3. Create and activate virtual environment: 27 | ```bash 28 | python -m venv .venv 29 | source .venv/bin/activate # On Windows use: .venv\Scripts\activate 30 | ``` 31 | 32 | 4. Install dependencies: 33 | ```bash 34 | pip install -r requirements.txt 35 | ``` 36 | 37 | 5. Create a `.env` file in the root directory: 38 | ```env 39 | PAYMAN_API_SECRET=your_payman_api_secret # From app.paymanai.com 40 | OPENAI_API_KEY=your_openai_api_key 41 | PAYMAN_ENVIRONMENT=sandbox # or production 42 | ``` 43 | 44 | 6. Run the tests: 45 | ```bash 46 | # Test basic payment functionality 47 | python examples/test_payment.py 48 | 49 | # Test AI agent with all payment tools 50 | python examples/test_agent.py 51 | ``` 52 | 53 | ## Features ✨ 54 | 55 | - Direct payment processing 56 | - AI agent with natural language payment processing 57 | - Multiple payment tools: 58 | - Send payments 59 | - Search payees 60 | - Add new payees 61 | - Request money 62 | - Check balances 63 | 64 | ## Project Structure 📁 65 | 66 | ``` 67 | paychain-examples/ 68 | ├── .env # Environment variables (not in git) 69 | ├── .gitignore # Git ignore file 70 | ├── requirements.txt # Project dependencies 71 | └── examples/ # Test examples 72 | ├── __init__.py 73 | └── test_agent.py # AI agent test 74 | ``` 75 | 76 | ## Security 🔒 77 | 78 | - Never commit your `.env` file 79 | - Keep your API keys secure 80 | - Use sandbox environment for testing 81 | 82 | ## Contributing 🤝 83 | 84 | 1. Fork the repository 85 | 2. Create your feature branch 86 | 3. Commit your changes 87 | 4. Push to the branch 88 | 5. Create a Pull Request 89 | 90 | ## License 📄 91 | 92 | MIT 93 | -------------------------------------------------------------------------------- /paychain-examples/.gitignore: -------------------------------------------------------------------------------- 1 | # Virtual Environment 2 | .venv/ 3 | venv/ 4 | ENV/ 5 | 6 | # Environment variables 7 | .env 8 | 9 | # Python 10 | __pycache__/ 11 | *.py[cod] 12 | *$py.class 13 | *.so 14 | .Python 15 | build/ 16 | develop-eggs/ 17 | dist/ 18 | downloads/ 19 | eggs/ 20 | .eggs/ 21 | lib/ 22 | lib64/ 23 | parts/ 24 | sdist/ 25 | var/ 26 | wheels/ 27 | *.egg-info/ 28 | .installed.cfg 29 | *.egg 30 | 31 | # IDEs 32 | .idea/ 33 | .vscode/ 34 | *.swp 35 | *.swo 36 | .DS_Store -------------------------------------------------------------------------------- /paychain-examples/examples/__init__.py: -------------------------------------------------------------------------------- 1 | # Empty init file -------------------------------------------------------------------------------- /paychain-examples/examples/test_agent.py: -------------------------------------------------------------------------------- 1 | import os 2 | from dotenv import load_dotenv 3 | from typing import List 4 | 5 | # Load environment variables first 6 | dotenv_path = os.path.join(os.path.dirname(__file__), '..', '.env') 7 | load_dotenv(dotenv_path) 8 | 9 | from langchain.agents import AgentExecutor, create_openai_functions_agent 10 | from langchain_openai import ChatOpenAI 11 | from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder 12 | from langchain_payman_tool import ( 13 | SendPaymentTool, 14 | SearchPayeesTool, 15 | AddPayeeTool, 16 | AskForMoneyTool, 17 | GetBalanceTool 18 | ) 19 | 20 | def create_payment_agent(): 21 | # Initialize all tools 22 | tools = [ 23 | SendPaymentTool(), 24 | SearchPayeesTool(), 25 | AddPayeeTool(), 26 | AskForMoneyTool(), 27 | GetBalanceTool() 28 | ] 29 | 30 | # Create the prompt template - Removed chat_history 31 | prompt = ChatPromptTemplate.from_messages([ 32 | ("system", """You are a helpful payment processing assistant that can help with sending payments, 33 | managing payees, and checking balances. You have access to various payment tools and will use them 34 | appropriately based on user requests. 35 | 36 | Always verify amounts and payee information before processing payments. 37 | If you're unsure about any details, ask for clarification."""), 38 | ("human", "{input}"), 39 | MessagesPlaceholder(variable_name="agent_scratchpad"), 40 | ]) 41 | 42 | # Initialize the LLM 43 | llm = ChatOpenAI(temperature=0) 44 | 45 | # Create the agent 46 | agent = create_openai_functions_agent(llm, tools, prompt) 47 | 48 | # Create the agent executor 49 | agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True) 50 | 51 | return agent_executor 52 | 53 | def test_agent(): 54 | agent = create_payment_agent() 55 | 56 | # Test cases 57 | test_queries = [ 58 | "What's my current balance?", 59 | "Search for a payee named Alice", 60 | "Add a payee named Alice, make a mock routing and account number for testing" 61 | "Send $5 to Alice" 62 | ] 63 | 64 | for query in test_queries: 65 | print(f"\n\nTesting query: {query}") 66 | print("-" * 50) 67 | try: 68 | response = agent.invoke({"input": query}) 69 | print("Response:", response) 70 | except Exception as e: 71 | print(f"Error processing query: {str(e)}") 72 | 73 | if __name__ == "__main__": 74 | test_agent() -------------------------------------------------------------------------------- /paychain-examples/requirements.txt: -------------------------------------------------------------------------------- 1 | python-dotenv>=0.19.0 2 | langchain>=0.1.0 3 | langchain-openai>=0.0.3 4 | langchain-community>=0.0.10 5 | langchain-core>=0.1.0 6 | openai>=1.1.0 7 | langchain-payman-tool>=0.1.0 --------------------------------------------------------------------------------