Skip to content

l2yao/amtb_agent

Repository files navigation

AMTB Agent

A LangGraph-based Q&A assistant representing Venerable Master Chin Kung and the AMTB (Amitabha Buddhist Society).

Overview

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

Features

  • 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

Installation

  1. Clone the repository:
git clone <repo-url>
cd amtb_agent
  1. Create a virtual environment:
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
  1. Install dependencies:
pip install -r requirements.txt
  1. Set up environment variables:
cp .env.example .env
# Edit .env and add your OPENAI_API_KEY

Usage

Basic Example

from 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.

Response Format

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

Project Structure

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

Tools Available

  1. search_amtb_website(query): Searches AMTB website (https://www.amtb.tw) for teachings and information
  2. fetch_webpage(url): Fetches and extracts text from a webpage
  3. search_web(query): Searches the web for information using DuckDuckGo
  4. extract_text_from_webpage(url): Extracts clean text from a webpage

Environment Variables

  • GOOGLE_API_KEY: Your Google Gemini API key (required)
  • DEBUG: Enable debug mode (optional, default: false)
  • MAX_ITERATIONS: Maximum agent iterations (optional, default: 10)

Running Examples

python examples.py

Running Tests

pytest tests/

Architecture

The agent uses LangGraph to manage the following flow:

  1. Agent Node: Processes messages through Gemini LLM with system prompt aligned to Venerable Master Chin Kung's teachings
  2. Tool Node: Executes selected tools (especially AMTB website search) based on LLM output
  3. 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.

Requirements

  • Python 3.10+
  • LangGraph
  • LangChain
  • Google Gemini API key

Development

To install development dependencies:

pip install -e ".[dev]"

Run tests with coverage:

pytest --cov=amtb_agent tests/

Format code:

black amtb_agent tests examples.py

License

MIT License

Contributing

Contributions are welcome! Please open an issue or submit a pull request.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages