Skip to content

stutimahesh/cot-reasoning-agent

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

🧠 CoT Reasoning Agent

A structured Chain-of-Thought (CoT) reasoning agent built using LLMs with step-by-step planning, tool calling, and JSON-based structured outputs.


🚀 Project Overview

The agent:

  • ✅ Breaks down user queries step-by-step (START → PLAN → TOOL → OUTPUT)
  • ✅ Uses structured JSON responses
  • ✅ Calls external tools when required
  • ✅ Retrieves real-time weather information
  • ✅ Demonstrates tool-augmented reasoning

It acts as both:

  • 🧠 A Chain-of-Thought reasoning agent
  • 🌦️ A Current Weather Retrieval Agent

🚀 Features

  • Structured reasoning using START, PLAN, TOOL, and OUTPUT steps
  • Tool-calling capability
  • Real-time weather retrieval via wttr.in
  • JSON schema validation using Pydantic
  • Secure API key management using .env

📂 Project Structure

cot_reasoning_agent/ │ ├── aiAgent_pydantic.py ├── requirements.txt └── README.md


⚙️ Setup Instructions

1️⃣ Clone the repository

git clone https://github.com/your-username/cot-weather-agent.git


2️⃣ Create Virtual Environment

python -m venv .venv

Activate Environment

Windows (PowerShell):

.venv\Scripts\activate

Mac/Linux:

source .venv/bin/activate


3️⃣ Install Dependencies

pip install -r requirements.txt


4️⃣ Add Your API Key (Important 🔐)

Create a file named:

.env

Add your Google API key:

GOOGLE_API_KEY=your_api_key_here


▶️ Run the Agent

python cot_weather_agent.py


Example Queries

👉 What is the weather in Delhi? 👉 Solve 45*12/3 👉 What is the weather in Bangalore?


🧠 How It Works

  1. The user enters a query.
  2. The model reasons step-by-step using Chain-of-Thought.
  3. If required, it calls the get_weather(city) tool.
  4. The tool response is injected back into the reasoning loop.
  5. The agent generates the final structured OUTPUT.

🔧 Tool Used

get_weather(city: str)

Fetches current weather using:

https://wttr.in/{city}?format=%C+%t

Returns formatted weather information for the given city.


🎯 Learning Objectives

This project demonstrates:

  • How Chain-of-Thought improves reasoning transparency
  • How to build tool-augmented LLM agents
  • How to structure LLM outputs using JSON schemas
  • How to securely manage API keys

About

A Chain-of-Thought (CoT) reasoning agent that performs structured reasoning, tool calling, and real-time weather retrieval using LLMs

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages