Skip to content

paultparker/Claude1

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

React Agent with LangChain and OpenAI

A small React (ReAct) agent implementation using LangChain and OpenAI.

Features

  • React Agent: Uses the ReAct (Reasoning and Acting) pattern to solve problems
  • Multiple Tools: Includes calculator, weather, and search tools
  • Streaming Output: Shows the agent's reasoning process step by step
  • TypeScript: Fully typed implementation

Setup

  1. Install dependencies:
npm install
  1. Create a .env file with your OpenAI API key:
cp .env.example .env
# Edit .env and add your OPENAI_API_KEY
  1. Run the demo:
npm run demo

Usage

Running the Demo

npm run demo

This will run several test queries demonstrating the agent's capabilities.

Running Tests

npm test

Programmatic Usage

import { runAgent, runAgentVerbose } from "./src/agent";

// Simple usage - returns final response
const response = await runAgent("What is 25 multiplied by 17?");
console.log(response);

// Verbose usage - shows reasoning process
await runAgentVerbose("What's the weather in Tokyo?");

Available Tools

  1. Calculator - Performs basic arithmetic (add, subtract, multiply, divide)
  2. Weather - Gets simulated weather for major cities
  3. Search - Searches for information on topics

Project Structure

├── src/
│   ├── agent.ts       # Main React agent implementation
│   ├── tools.ts       # Tool definitions
│   ├── index.ts       # Module exports
│   ├── demo.ts        # Demo script
│   └── __tests__/     # Test files
├── package.json
├── tsconfig.json
└── jest.config.js

Configuration

You can customize the agent:

import { createAgent } from "./src/agent";

const agent = createAgent({
  modelName: "gpt-4",        // OpenAI model to use
  temperature: 0.7,          // Creativity (0-1)
});

Requirements

  • Node.js 18+
  • OpenAI API key

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors