Metadata-Version: 2.1
Name: wyn-agent-x
Version: 0.2.6
Summary: This package is an updated WYN-Agent package.
Author: Yiqiao Yin
Author-email: eagle0504@gmail.com
Requires-Python: >=3.9,<4.0
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Requires-Dist: google-search-results (>=2.4.2,<3.0.0)
Requires-Dist: openai (>=1.44.1,<2.0.0)
Requires-Dist: serpapi (>=0.1.5,<0.2.0)
Requires-Dist: twilio (>=9.3.0,<10.0.0)
Requires-Dist: yfinance (==0.2.50)
Requires-Dist: ypdf (==1.7.2)
Description-Content-Type: text/markdown

# 🌟 WYN-Agent-X

WYN-Agent-X is a dynamic and extendable chatbot that integrates with OpenAI and Twilio, allowing you to seamlessly handle user intents and trigger APIs (like sending SMS) based on natural language input. Plus, it’s super friendly and conversational! 🤖💬

### Features:
- **AI-Powered Conversations**: Uses OpenAI’s GPT models for general chit-chat. Just type away!
- **Trigger-Based API Calls**: Automatically detects when users want to perform specific tasks (like sending a message), and triggers the corresponding API call.
- **Easy to Extend**: Add more APIs by simply updating the `metadata.json` file. No need to dig into the core logic! 🌱

---

## 🚀 Installation

You can easily install the package via `pip`:

```bash
pip install wyn-agent-x
```

---

## 📂 Directory Structure

```bash
wyn-agent-x/
│
├── requirements.txt     # List of dependencies to install
├── wyn_agent_x/
│   ├── __init__.py      # Initializes the package
│   ├── main.py          # Main entry point for the chatbot
│   ├── helper.py        # Helper functions and processing logic
│   ├── list_of_apis.py  # All API functions registered here
│   ├── metadata.json    # Dynamic metadata for API calls and trigger words
│── pyproject.toml       # Optional config if packaging the project
└── README.md            # You're reading this!
```

## System Diagram

The system is designed with an *intent processor* interpreting the prompt's purpose from the user. After *intent processor* determines the necessary API required for execution, it attemps to fill up the required input parameters in the input payload. For the unfilled parameters, the *resolver* bounces the questions back to the user to seek more information before execution. This process interates until all required parameters are filled. 

```mermaid
sequenceDiagram
    participant S as Start
    participant U as User
    participant L as LLM
    participant A1 as Intent Classifier Agent
    participant A2 as Dependency Resolution Agent
    participant A3 as Librarian Agent
    participant ED as End

    S->>U: Start the conversation
    U->>L: User provides prompt: "I want to do X..."
    loop Self-correction cycle
        L->>A1: Classify the intent of the statement
        A1->>L: {"Chat": "0.1", "Functional Call": 0.9}
        alt High confidence for functional call
            L->>A2: Check the required dependency
            A2->>A3: Do we have anything we can use from history?
            A3->>A2: We have info1, info2, but need info3.
            A2->>A1: Almost done, but need info3 from user.

            loop Iteratively check scores
                A1->>L: Send the question to user
                L->>U: Can you provide us info3 (ex: can be name, address, etc..)?
                U->>L: My name is John and address is 123 Drive, New York.
                L->>A1: {"Chitchat": "0.1", "Functional Call": 0.1, "Useful Content": 0.8}
                alt High confidence for useful content
                    A1->>A3: Useful content, i.e., info3, is provided
                end
            end

            A3->>L: All dependency fulfilled, API call invoked and complete.
        else Low confidence for functional call
            alt High confidence for chitchat
                L->>U: Let's chitchat.
            end
            L->>A3: User provided useful content, put it aside.
        end
    end

    A1->>L: API Call complete
    L->>U: Task is finished.
    U->>ED: Finish the program
```

## 🎮 Sample Usage

Want to try it out? Just import the `AgentX` class, provide your API keys, and start chatting with your agent!

```python
from google.colab import userdata

# Fetch API credentials
OPENAI_API_KEY = userdata.get('OPENAI_API_KEY')
TWILIO_ACCOUNT_SID = userdata.get("YOUR_TWILIO_ACCOUNT_SID")
TWILIO_AUTH_TOKEN = userdata.get("YOUR_TWILIO_AUTH_TOKEN")
SERPAPI_API_KEY = userdata.get("SERPAPI_API_KEY")

# Import the agent
from wyn_agent_x.main import AgentX

# Initialize and start the chat!
agent = AgentX(
    api_key=OPENAI_API_KEY,
    account_sid=TWILIO_ACCOUNT_SID,
    auth_token=TWILIO_AUTH_TOKEN,
    serpapi_key=SERPAPI_API_KEY,
    protocol='You are a helpful assistant.')
agent.start_chat()
```

Once started, you'll see this friendly message:
```
👋 Welcome! Press 'EXIT' to quit the chat at any time.
```

Feel free to chat with the bot, ask it to send messages, or perform any task you've configured in the metadata. When you're done, simply type `EXIT` to end the session with a friendly goodbye! 👋

---

## 📖 How it Works

1. **Intent Detection**: The agent listens for specific trigger words (like "send a message" or "set a demo") from user input and matches them against the triggers defined in `metadata.json`.
   
2. **API Calls**: When an intent is detected (e.g., sending an SMS), it calls the corresponding API (like Twilio's SMS API) and logs the event in the `event_stream`.

3. **Dynamic Functions**: Adding a new API or intent is as simple as updating the `metadata.json` file and registering the new API in `list_of_apis.py`. No need to modify core logic! 🚀

---

## 🛠️ Extend and Customize

You can easily extend WYN-Agent-X by adding new API calls or intents:

1. **Update `metadata.json`** with new API information and trigger words:
   ```json
   {
       "send_email": {
           "trigger_word": ["send email", "notify via email"],
           "sample_payload": {"email": "string", "subject": "string"},
           "prerequisite": null
       }
   }
   ```

2. **Register your new API** in `list_of_apis.py` with a simple decorator:
   ```python
   @register_function("send_sms")
    def send_sms(payload: Dict[str, str], secrets: Dict[str, str], event_stream: list) -> Dict[str, Any]:
       # Code to send email goes here!
       pass
   ```

---

## 📜 License

MIT License - Enjoy, use, and extend this project freely! 🥳

---

## 👤 Author

**Yiqiao Yin**

📧 Email: eagle0504@gmail.com

Feel free to reach out if you have any questions, suggestions, or just want to say hi! 😊

