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.
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.
- 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
- Node.js - JavaScript runtime
- TypeScript - Static typing
- LangChain - Framework for LLM applications
- OpenAI GPT - Language model
- Axios - HTTP client
- Zod - Schema validation
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
- Node.js 18+
- npm or yarn
- OpenAI API key
- TypeScript
- Clone the repository:
git clone https://github.com/your-username/agents-ia-langchain_asimov.git
cd agents-ia-langchain_asimov
- Install dependencies:
npm install
# or
yarn install
- Configure environment variables:
cp .env.example .env
- Add your OpenAI API key to the
.env
file:
OPENAI_API_KEY=your_key_here
# 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
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?");
import { runDataFrameAgent } from './src/14_agent_toolkits';
// DataFrame analysis
const analysis = await runDataFrameAgent("What's the shape of the DataFrame?");
import { runSQLAgent } from './src/14_agent_toolkits';
// Database query
const query = await runSQLAgent("List all tables in the database");
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 |
The project includes a colorful logging system with different levels:
Logger.info()
- General informationLogger.success()
- Successful operationsLogger.debug()
- Debug informationLogger.error()
- Errors and exceptions
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,
});
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"),
}),
}
);
Contributions are welcome! To contribute:
- Fork the project
- Create a feature branch (
git checkout -b feature/AmazingFeature
) - Commit your changes (
git commit -m 'Add some AmazingFeature'
) - Push to the branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
Author: Natanael Lima
Email: taelima1997@gmail.com
Course: Asimov Academy - AI Agents with LangChain
- Asimov Academy for the excellent course
- LangChain for the incredible framework
- OpenAI for the GPT API
⭐ If this project helped you, consider giving it a star on the repository!