Skip to content

KishoreJegan/Python-based-AI-Agent

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Python-BasedAI-Agent

🧠 Smart AI Agent (with Memory & Tools)

Unlike a standard LLM that only knows what it was trained on, this agent has access to "tools" (Web Search and a Calculator) and possesses "memory" to remember your conversation history. It runs locally in your terminal but uses the powerful Llama 3.3 70B model via the Groq Cloud.

⚡ Why uv instead of pip?

You will notice I used uv for this project. If you haven't used it before: uv is a modern, extremely fast Python package manager (written in Rust).

It's Fast: It installs packages almost instantly compared to standard pip.

It's Clean: It handles virtual environments automatically.

It's Simple: No more python -m venv ... or pip freeze.

Install the uv

Windows (Recommended) Open PowerShell and run:

PowerShell

powershell -ExecutionPolicy ByPass -c

"irm https://astral.sh/uv/install.ps1 | iex"

🛠️ Tech Stack & Libraries Used

Here is what makes this agent tick:

Python 3.12+:

The core language.

LangGraph:

The "brain" logic. It allows the AI to decide: "Should I answer directly, or do I need to use a tool first?"

LangChain:

The framework that connects the AI to the tools.

Groq API (Llama 3.3 70B):

The intelligence engine. We use the 70B model because it is significantly better at following tool instructions than smaller models.

DuckDuckGo Search:

The "Eyes." Lets the agent search the live internet for real-time info (like stock prices or news).

Custom Calculator:

The "Brain Extension." A specific Python tool I wrote because LLMs are notoriously bad at math. It uses Python's math library for precision.

MemorySaver:

The RAM. Keeps track of the conversation so you don't have to repeat yourself.

🚀 How to Run This Project

1. Clone the Repository

git clone <your-repo-url-here>
cd <your-repo-name>

2. Install Dependencies (Using uv)

If you don't have uv installed, get it first: pip install uv (ironic, I know) or via their official guide.

Then, simply run:

uv sync

This will read the pyproject.toml (or you can manually add the packages below):

uv add langchain-groq langgraph langchain-community duckduckgo-search python-dotenv

3. Set Up Your API Key

This project requires a Groq API Key (it's free to get).

Create a file named .env in the root folder.

Add your key inside it:


GROQ_API_KEY="gsk_your_key_here..."

4. Run the Agent

Since uv manages the virtual environment for you, just run:
uv run main.py

🤖 What Can It Do?

Once the agent is running, you can try these commands:

Test Memory:

You: "Hi, my name is Alice."

Agent: "Hello Alice."

You: "What is my name?"

Agent: "Your name is Alice."

Test Web Search:

You: "Who won the Cricket World Cup in 2023?"

Agent: (Searches DuckDuckGo) "Australia won..."

Test Math:

You: "Calculate the square root of 144 * 5."

Agent: (Uses Calculator Tool) "The answer is 60."

📂 Code Structure

main.py:

The heart of the project.

@tool decorator:

Converts my Python math function into a format the AI understands.

thread_id:

This acts like a "Session ID." If you change this ID in the code, the AI forgets the previous conversation.

ChatGroq:

The connection to the Llama 3.3 model.

About

Executed a python based AI Agent using llm langchain ,langgraph and GROQ API

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages