A LangGraph-based Q&A assistant representing Venerable Master Chin Kung and the AMTB (Amitabha Buddhist Society).
AMTB Agent is a specialized question-answering system built with LangGraph that helps people solve real-life problems through Buddhist wisdom and teachings. The agent:
- Answers questions based on teachings from Venerable Master Chin Kung
- Searches and retrieves information from the AMTB website (https://www.amtb.tw)
- Provides compassionate, practical guidance rooted in Buddhist principles
- Helps users apply wisdom to their daily lives
- Web References for All Answers: Every response includes sources and URLs
- AMTB Website Search: Specialized tool to search https://www.amtb.tw for teachings
- Buddhist Q&A: Answers real-life problems using Buddhist wisdom
- Web Research: Fetch and analyze webpages for fact-finding
- Gemini AI: Uses Google's Gemini AI for intelligent reasoning
- LangGraph Architecture: Graph-based agent for reliable control flow
- Tool Binding: Seamless integration with langchain tools
- Clone the repository:
git clone <repo-url>
cd amtb_agent- Create a virtual environment:
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate- Install dependencies:
pip install -r requirements.txt- Set up environment variables:
cp .env.example .env
# Edit .env and add your OPENAI_API_KEYfrom amtb_agent import run_agent
from amtb_agent.utils import format_response_with_sources
# Ask about real-life problems with Buddhist wisdom
response = run_agent("How can I manage stress and anxiety in my life?")
# Format response with web references
formatted = format_response_with_sources(response)
print(formatted)The response includes both the answer and web references showing where information came from.
The agent returns a dictionary with the following structure:
{
"answer": "The Buddhist teaching on managing stress...",
"sources": [
{
"type": "webpage",
"tool": "fetch_webpage",
"url": "https://www.amtb.tw/...",
"query": None
},
{
"type": "search",
"tool": "search_amtb_website",
"url": None,
"query": "stress management"
}
]
}Use the format_response_with_sources() utility function to display answers with references:
from amtb_agent.utils import format_response_with_sources
response = run_agent("Your question")
print(format_response_with_sources(response))amtb_agent/
├── amtb_agent/ # Main package
│ ├── __init__.py # Package exports
│ ├── agent.py # Core agent logic
│ └── tools.py # Web tools definitions
├── tests/ # Test files
├── examples.py # Usage examples
├── requirements.txt # Python dependencies
├── pyproject.toml # Project configuration
└── README.md # This file
- search_amtb_website(query): Searches AMTB website (https://www.amtb.tw) for teachings and information
- fetch_webpage(url): Fetches and extracts text from a webpage
- search_web(query): Searches the web for information using DuckDuckGo
- extract_text_from_webpage(url): Extracts clean text from a webpage
GOOGLE_API_KEY: Your Google Gemini API key (required)DEBUG: Enable debug mode (optional, default: false)MAX_ITERATIONS: Maximum agent iterations (optional, default: 10)
python examples.pypytest tests/The agent uses LangGraph to manage the following flow:
- Agent Node: Processes messages through Gemini LLM with system prompt aligned to Venerable Master Chin Kung's teachings
- Tool Node: Executes selected tools (especially AMTB website search) based on LLM output
- Router: Determines whether to continue with tool use or end the conversation
The system prompt ensures all guidance is compassionate, practical, and rooted in Buddhist principles.
- Python 3.10+
- LangGraph
- LangChain
- Google Gemini API key
To install development dependencies:
pip install -e ".[dev]"Run tests with coverage:
pytest --cov=amtb_agent tests/Format code:
black amtb_agent tests examples.pyMIT License
Contributions are welcome! Please open an issue or submit a pull request.