This project implements an AI-powered assistant bot for Webex Teams, leveraging OpenAI's language models, LangChain, and LangGraph to provide intelligent responses and perform tasks. It uses SQLite to maintain conversation history, allowing for contextual interactions.
- Web search capabilities using Tavily Search
- Retrieval of Webex user information
- Mathematical operations (power calculation as example)
- Integration with Webex Teams
- Advanced AI reasoning using LangGraph
- Persistent conversation history for improved context awareness
- Conversation context maintenance using SQLite
This project utilizes several key technologies:
- LangChain: A framework for developing applications powered by language models.
- LangGraph: A library for building stateful, multi-actor applications with LLMs. It enables the creation of complex, graph-based workflows for AI agents.
- OpenAI: Provides the underlying language model for natural language processing and generation.
- Webex Bot: Facilitates integration with Webex Teams for message handling and response.
- SQLite: A lightweight, serverless database used to store conversation history locally.
The combination of these technologies allows for the creation of a sophisticated AI assistant capable of complex reasoning, task execution, and maintaining context across conversations.
The project is organized as follows:
project_root/
│
├── src/
│ ├── graph_reactagent/
│ │ ├── __init__.py
│ │ ├── interfaces.py
│ │ ├── graph.py
│ │ ├── invoker.py
│ │ ├── message_filter.py
│ │ ├── prompt_formatter.py
│ │ └── tools.py
│ │
│ └── webexbot/
│ ├── __init__.py
│ ├── commands.py
│ └── webexbot.py
│
├── tests/
│ ├── __init__.py
│ ├── test_graph_reactagent.py
│ ├── test_message_filter.py
│ ├── test_tools.py
│ └── test_webexbot.py
│
├── .env
├── .coveragerc
├── pyproject.toml
└── README.md
- graph_reactagent/: Module for graph-based react agent
- webexbot/: Module for Webex bot implementation
- tests/: Directory containing all test files
- .env: Environment variables file
- .coveragerc: Configuration file for coverage reports
- pyproject.toml: Project dependencies
- README.md: Project documentation
The following image illustrates the structure and flow of the ReAct agent used in this project:
This graph visualizes how the different components of the ReAct agent interact, including the decision-making process, tool usage, and response generation. The graph structure is implemented using LangGraph, which allows for complex, multi-step reasoning processes and dynamic tool selection.
- Python ^3.11
- langgraph ^0.2.35
- langchain ^0.3.3
- langchain-openai ^0.2.2
- python-dotenv ^1.0.1
- langgraph-checkpoint-sqlite ^2.0.0
- webex-bot ^0.5.2
- langchain-community ^0.3.2
- ruff ^0.6.8
- mypy ^1.11.2
- poethepoet ^0.29.0
- Clone the repository
- Install Poetry (if not already installed)
- Install project dependencies:
poetry install
- Set up environment variables:
- Copy the
.env-example
file to.env
in the project root directory - Fill in the required values in the
.env
file
- Copy the
The following environment variables need to be set in your .env
file:
# LLM ENVIRONMENT
OPENAI_API_BASE=<OpenAI API base URL>
OPENAI_API_KEY=<Your OpenAI API key>
# LANGCHAIN ENVIRONMENT
LANGCHAIN_ENDPOINT=<LangSmith endpoint URL>
LANGCHAIN_API_KEY=<Your LangSmith API key>
LANGCHAIN_PROJECT=<Name of your LangSmith project>
# WEBEX TEAMS ENVIRONMENT
WEBEX_TEAMS_ACCESS_TOKEN=<Your Webex Teams bot token>
WEBEX_TEAMS_DOMAIN=<The approved domain for your Webex Teams bot>
# Tools API
TAVILY_API_KEY=<Your Tavily API key for web search>
# Python Environment
PYTHONPATH=src
# SQLite Database for Conversation History
SQL_CONNECTION_STR=checkpoints.db
Make sure to replace the placeholders with your actual API keys and other required information.
Run the bot using:
poe start
The bot will connect to Webex Teams and respond to messages in approved domains. As conversations occur, they will be saved to a local SQLite database file (checkpoints.db
by default) to maintain context across interactions.
This project uses Poetry for dependency management and Poe the Poet for task running.
- Format code:
poe format
- This task runs ruff formatter, ruff linter, and mypy type checker
- Update dependencies:
poe update
- Start the bot:
poe start
- Run tests:
poe test
- Modify
src/webexbot/webexbot.py
to adjust bot settings such as approved rooms, users, or domains - Update
src/graph_reactagent/graph.py
to change the OpenAI model or system prompt - Extend
src/graph_reactagent/tools.py
to add new capabilities to the bot - Adjust the
SQL_CONNECTION_STR
in the.env
file to change the location or name of the SQLite database file
This project uses SQLite to store conversation history locally. This allows the AI assistant to maintain context across multiple interactions, even if the bot is restarted. The conversation history is stored in a .db
file (default: checkpoints.db
) in the project root directory.
Benefits of using SQLite for conversation history:
- Improved context awareness: The AI can reference previous messages to provide more relevant and coherent responses.
- Persistence across restarts: Conversation history is maintained even if the bot is stopped and restarted.
This project uses LangSmith, a platform for debugging, testing, and monitoring LLM applications. LangSmith helps in tracing the execution of LangChain applications, allowing for better understanding and optimization of the AI assistant's behavior.
If you encounter any issues while setting up or running the bot, please check the following:
- Ensure all environment variables in the
.env
file are correctly set. - Verify that you have the correct permissions for the Webex Teams bot token.
- Check that all API keys (OpenAI, Tavily, LangSmith) are valid and have the necessary permissions.
- Make sure the SQLite database file (
checkpoints.db
) is writable by the application.
If problems persist, please open an issue in the project repository with a detailed description of the error and the steps to reproduce it.
- Keep your
.env
file and SQLite database (checkpoints.db
) secure and never commit them to version control. - Ensure that the Webex Teams bot only has access to the necessary rooms and domains.
- Evgenii (lieranderl)