Skip to content

🤖 AI Agents study project using LangChain and OpenAI. Includes practical examples of tools, agents, memory and external integrations.

License

Notifications You must be signed in to change notification settings

Natanaelvich/ai-agents-langchain

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AI Agents with LangChain

Node.js TypeScript LangChain License

A comprehensive educational project demonstrating intelligent agent implementations using LangChain and TypeScript. This repository contains practical and advanced examples of how to build, configure, and use AI agents for different scenarios and use cases.

🚀 Overview

This project is part of the Asimov Academy course on AI Agents with LangChain, offering a complete collection of examples from basic implementations to advanced use cases with specialized toolkits.

📋 Features

  • Basic Agents: Fundamental agent implementation with LangChain
  • Memory Executor: Agents with persistent memory capabilities
  • Agent Types: Different agent architectures and patterns
  • Specialized Toolkits: Tools for data analysis and SQL queries
  • API Integration: Weather and Wikipedia tools
  • Logging System: Detailed execution monitoring
  • Modular Architecture: Organized and reusable code

🛠️ Technologies Used

  • Node.js - JavaScript runtime
  • TypeScript - Static typing
  • LangChain - Framework for LLM applications
  • OpenAI GPT - Language model
  • Axios - HTTP client
  • Zod - Schema validation

📦 Project Structure

src/
├── tools/                          # Custom tools
│   ├── weather.ts                  # Weather API
│   ├── wikipedia.ts               # Wikipedia search
│   ├── dataframe.ts               # Data analysis
│   └── sql.ts                     # SQL queries
├── utils/
│   └── routeResponse.ts           # Routing utility
├── 03_adding_external_functions_openai.ts    # OpenAI functions
├── 04_adding_external_functions_langchain.ts # LangChain functions
├── 09_chatmodels_with_tools.ts               # Models with tools
├── 11_agents.ts                              # Basic implementation
├── 12_agent_executor_e_memory.ts             # Agents with memory
├── 13_agent_types.ts                         # Agent types
├── 14_agent_toolkits.ts                      # Specialized toolkits
└── Logger.ts                                 # Logging system

🚦 Prerequisites

  • Node.js 18+
  • npm or yarn
  • OpenAI API key
  • TypeScript

⚙️ Installation

  1. Clone the repository:
git clone https://github.com/your-username/agents-ia-langchain_asimov.git
cd agents-ia-langchain_asimov
  1. Install dependencies:
npm install
# or
yarn install
  1. Configure environment variables:
cp .env.example .env
  1. Add your OpenAI API key to the .env file:
OPENAI_API_KEY=your_key_here

🔧 How to Use

Running Individual Examples

# Basic agents
npx ts-node src/11_agents.ts

# Agents with memory
npx ts-node src/12_agent_executor_e_memory.ts

# Agent types
npx ts-node src/13_agent_types.ts

# Specialized toolkits
npx ts-node src/14_agent_toolkits.ts

Usage Examples

1. Basic Agent

import { runAgent } from './src/11_agents';

// Temperature query
const tempResponse = await runAgent("What's the temperature in São Paulo?");

// Wikipedia search
const wikiResponse = await runAgent("Who was Isaac Asimov?");

2. Data Analysis

import { runDataFrameAgent } from './src/14_agent_toolkits';

// DataFrame analysis
const analysis = await runDataFrameAgent("What's the shape of the DataFrame?");

3. SQL Queries

import { runSQLAgent } from './src/14_agent_toolkits';

// Database query
const query = await runSQLAgent("List all tables in the database");

🔍 Detailed Features

Available Tools

Tool Description Usage
getCurrentTemperature Gets current temperature by coordinates Weather queries
searchWikipedia Searches information on Wikipedia General knowledge search
dfTools Data analysis toolkit DataFrame manipulation
sqlTools SQL toolkit Database queries

Logging System

The project includes a colorful logging system with different levels:

  • Logger.info() - General information
  • Logger.success() - Successful operations
  • Logger.debug() - Debug information
  • Logger.error() - Errors and exceptions

📚 Code Examples

Creating a Custom Agent

import { ChatOpenAI } from "@langchain/openai";
import { ChatPromptTemplate } from "@langchain/core/prompts";

const prompt = ChatPromptTemplate.fromMessages([
  ["system", "You are an assistant specialized in {domain}"],
  ["user", "{input}"],
  new MessagesPlaceholder("agent_scratchpad"),
]);

const chat = new ChatOpenAI({
  modelName: "gpt-3.5-turbo-0125",
  temperature: 0,
});

Implementing Custom Tools

import { tool } from "@langchain/core/tools";
import { z } from "zod";

export const myCustomTool = tool(
  async (input: { query: string }): Promise<string> => {
    // Your logic here
    return "Tool result";
  },
  {
    name: "myCustomTool",
    description: "Tool description",
    schema: z.object({
      query: z.string().describe("Input parameter"),
    }),
  }
);

🤝 Contributing

Contributions are welcome! To contribute:

  1. Fork the project
  2. Create a feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

📞 Contact

Author: Natanael Lima
Email: taelima1997@gmail.com
Course: Asimov Academy - AI Agents with LangChain

🙏 Acknowledgments


⭐ If this project helped you, consider giving it a star on the repository!

About

🤖 AI Agents study project using LangChain and OpenAI. Includes practical examples of tools, agents, memory and external integrations.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published