# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## [0.2.4] - 2025-01-26

### Added

- **MCP Server Integration** - Full support for Model Context Protocol (MCP) servers
  - `connectMCPServer()` - Connect to stdio-based MCP servers
  - `connectMCPServerHTTP()` - Connect to HTTP-based MCP servers
  - `disconnectMCPServer()` - Disconnect from specific servers
  - `disconnectAllMCPServers()` - Disconnect from all servers
  - `getMCPManager()` - Advanced MCP manager control
  - `MCPClientManager` class for managing multiple MCP connections
- **MCP Integration Example** - Complete example demonstrating MCP integration with Zomato food ordering
- **Updated Documentation** - Comprehensive MCP integration guide in README

### Dependencies

- Added `@modelcontextprotocol/sdk` v1.0.4 for MCP support

## [0.2.3] - Previous Release

### Added

- **API Key Management** - Configure API keys for external tools directly in `AgentController`
  - `apiKeys` option in constructor
  - `setApiKey()` and `getApiKey()` methods
  - Three-tier priority system: direct parameter → controller → environment variables
- **API Key Management Example** - Complete example demonstrating all API key configuration methods

### Changed

- **Pre-built Tools** - Now accept `context_variables` to access controller API keys
- **handleToolCalls** - Now passes controller instance via `_controller` in context variables

## [0.1.0] - 2025-01-04

### Added

#### Core Features

- **Lifecycle Callbacks** - `beforeModel`, `afterModel`, `beforeTool`, `afterTool` hooks for monitoring and controlling agent execution flow
- **Session Management** - `Session` and `MemoryStorage` classes for persistent conversation state
- **Tool Confirmation (HITL)** - `ToolConfirmation` class for human-in-the-loop approval of dangerous operations
- **Token Usage Tracking** - Automatic tracking of input/output tokens and cost calculation for all models
- **Agent Description** - Added `description` field to Agent class for better agent identification
- **Sub-agents Support** - Added `subAgents` array to Agent class for multi-agent hierarchies

#### Pre-built Tools

- **Web Search** - `serperSearch` tool for web search via Serper.dev API
- **Web Scraping** - `firecrawlScrape` and `firecrawlCrawl` tools for web content extraction via Firecrawl.dev
- **Calculator** - `calculate`, `add`, `subtract`, `multiply`, `divide` for mathematical operations
- **DateTime** - `getCurrentTime`, `getTimestamp`, `formatDate` for time operations

#### Developer Experience

- **TypeScript Definitions** - Comprehensive TypeScript type definitions in `index.d.ts`
- **Examples Directory** - 5 complete working examples demonstrating all features
- **Enhanced Documentation** - Completely rewritten README with comprehensive API reference
- **CHANGELOG** - Added this changelog file

#### Project Infrastructure

- **MIT License** - Added LICENSE file
- **Enhanced .gitignore** - Improved gitignore with common patterns
- **Package Metadata** - Updated keywords, added TypeScript types field

### Changed

- **AgentController Constructor** - Now accepts optional `options` object with `confirmationHandler`
- **Response Object** - Added `tokenUsage` and `cost` fields
- **Package Version** - Bumped from 0.0.5 to 0.1.0
- **Export System** - Added exports for new classes: `Session`, `MemoryStorage`, `ToolConfirmation`

### Enhanced

- **handleToolCalls** - Now supports tool confirmation and lifecycle callbacks
- **getChatCompletion** - Integrated lifecycle callbacks and tool confirmation support
- **run Method** - Added token usage tracking and cost calculation
- **Error Messages** - Improved error messages for tool execution failures

## [0.0.5] - Previous Release

### Features

- Basic agent creation and management
- OpenAI GPT integration
- Function/tool calling
- Context variables
- Multi-agent handoffs
- Streaming support
- Basic response handling

---

## Migration Guide

### From 0.0.5 to 0.1.0

#### New Optional Features (Backward Compatible)

All new features are backward compatible. Existing code will continue to work without changes.

#### Using New Features

**Lifecycle Callbacks:**

```javascript
const agent = new Agent({
  // ... existing config
  beforeModel: async ({ messages }) => {
    console.log("Calling model");
  },
});
```

**Session Management:**

```javascript
const { Session } = require("agents-js");
const session = new Session();
await session.set("key", "value");
```

**Token Tracking:**

```javascript
const response = await controller.run(agent, messages);
console.log(`Cost: $${response.cost}`);
```

**Pre-built Tools:**

```javascript
const { serperSearch } = require("agents-js/tools");

const agent = new Agent({
  functions: [serperSearch],
});
```

**Tool Confirmation:**

```javascript
const { ToolConfirmation } = require("agents-js");

const agent = new Agent({
  functions: [
    new ToolConfirmation({
      tool: myDangerousFunction,
      message: "Are you sure?",
    }),
  ],
});
```

---

For more details, see the [README](./README.md) and [examples](./examples).
