Skip to content

sathvik1607/Agents_experiment

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

7 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ€– LangChain Agent with Gmail Integration

An AI-powered agent built using LangChain, OpenAI, and Gmail API that can dynamically invoke tools based on user requests.


πŸš€ Features

🌀️ Weather Tool

Retrieve weather information for a specified city.

Example

What is the weather in Hyderabad?

πŸ“° Post Retrieval Tool

Fetch post details from JSONPlaceholder using a Post ID.

Example

Get post 20

API:

https://jsonplaceholder.typicode.com/posts/{id}

πŸ’‘ Daily Motivational Thought generator

Uses the OpenAI language model to generate a short, inspirational thought that can provide daily motivation and encouragement. .

Example

Generate today's thought

πŸ“§ Gmail Subject Retrieval Tool

Connects securely to Gmail using OAuth 2.0 and retrieves the latest email subjects from the user's Primary Inbox.

Example

Show my latest 2 email subjects

πŸ—οΈ Architecture

                 β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                 β”‚    User     β”‚
                 β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜
                        β”‚
                        β–Ό
              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
              β”‚ LangChain Agent  β”‚
              β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                       β”‚
                       β–Ό
               β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
               β”‚ OpenAI LLM  β”‚
               β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜
                      β”‚
      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
      β”‚               β”‚                β”‚
      β–Ό               β–Ό                β–Ό

🌀️ Weather     πŸ“° Posts      πŸ“§ Gmail Tool

      β”‚               β”‚                β”‚
      β–Ό               β–Ό                β–Ό

 External API   JSONPlaceholder   Gmail API

                      β”‚
                      β–Ό

              Final AI Response

πŸ› οΈ Tech Stack

Technology Purpose
🐍 Python Core Programming Language
🦜 LangChain Agent Framework
πŸ•ΈοΈ LangGraph Agent Execution Engine
πŸ€– OpenAI API LLM Integration
πŸ“§ Gmail API Email Retrieval
πŸ” OAuth 2.0 Authentication
🌐 Requests HTTP Requests
βš™οΈ Python Dotenv Environment Variables

πŸ“¦ Installation

Install required packages:

pip install langchain
pip install langchain-openai
pip install langgraph
pip install python-dotenv
pip install requests
pip install google-api-python-client
pip install google-auth-oauthlib
pip install google-auth-httplib2

πŸ”‘ Environment Setup

Create a .env file:

OPENAI_API_KEY=your_openai_api_key

πŸ“§ Gmail API Setup

Step 1

Create a Google Cloud Project.

Step 2

Enable Gmail API.

Step 3

Configure OAuth Consent Screen.

Step 4

Create OAuth Client ID.

Select:

Desktop Application

Step 5

Download credentials file.

Rename to:

credentials.json

Project Structure:

project/
β”‚
β”œβ”€β”€ dynamic_agent_input.py
β”œβ”€β”€ credentials.json
β”œβ”€β”€ .env
β”œβ”€β”€ token.json
└── README.md

πŸ” Authentication Flow

User
 ↓
Google Login
 ↓
OAuth Consent
 ↓
Access Granted
 ↓
token.json Generated
 ↓
Gmail API Access

First run requires login.

Subsequent runs use the stored token.


▢️ Running the Agent

Fetch Post

python dynamic_agent_input.py "Get post 20"

Generate Thought

python dynamic_agent_input.py "Generate a daily thought"

Gmail Subjects

python dynamic_agent_input.py "Show my latest email subjects"

πŸ“Š Agent Execution Flow

User Query
     ↓
LangChain Agent
     ↓
OpenAI Model
     ↓
Tool Selection
     ↓
Tool Execution
     ↓
External API
     ↓
Tool Result
     ↓
LLM Formatting
     ↓
Final Response

⚠️ Security Best Practices

Never commit:

credentials.json
token.json
.env

Add to .gitignore:

credentials.json
token.json
.env
__pycache__/
venv/

πŸ“š Concepts Demonstrated

βœ… Tool Calling

βœ… Agent Architecture

βœ… OAuth 2.0 Authentication

βœ… Gmail API Integration

βœ… OpenAI Integration

βœ… External API Consumption

βœ… Dynamic Workflow Execution

βœ… LangChain Agent Development


🎯 Future Enhancements

  • πŸ“© Email Summarization
  • βœ‰οΈ Email Draft Generation
  • πŸ“… Calendar Integration
  • 🌦️ Real Weather API Integration
  • πŸ—„οΈ Database Connectivity
  • πŸ”Ž Multi-Tool Agent Workflows

πŸ‘¨β€πŸ’» Author

Sathvik Chekkali

Built for learning Agentic AI, LangChain, Tool Calling, and External API Integration.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages