Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

mycoder-agent

drivecore155MIT1.7.0TypeScript support: included

Agent module for mycoder - an AI-powered software development assistant

ai, agent, mycoder, swe, swe-agent, claude, auto-coder, typescript

readme

MyCoder Agent

Core AI agent system that powers the MyCoder CLI tool. This package provides a modular tool-based architecture that allows AI agents to interact with files, execute commands, make network requests, spawn sub-agents for parallel task execution, and automate browser interactions.

Overview

The MyCoder Agent system is built around these key concepts:

  • 🛠️ Extensible Tool System: Modular architecture with various tool categories
  • 🔄 Parallel Execution: Ability to spawn sub-agents for concurrent task processing
  • 🔌 Multi-LLM Support: Works with Anthropic Claude, OpenAI GPT models, and Ollama
  • 🌐 Web Automation: Built-in browser automation for web interactions
  • 🔍 Smart Logging: Hierarchical, color-coded logging system for clear output
  • 📝 Advanced Text Editing: Powerful file manipulation capabilities
  • 🔄 MCP Integration: Support for the Model Context Protocol

Please join the MyCoder.ai discord for support: https://discord.gg/5K6TYrHGHt

Installation

npm install mycoder-agent

API Key Required

Before using MyCoder Agent, you must have one of the following API keys:

  • Anthropic: Set ANTHROPIC_API_KEY as an environment variable or in a .env file (Get from https://www.anthropic.com/api)
  • OpenAI: Set OPENAI_API_KEY as an environment variable or in a .env file
  • Ollama: Use locally running Ollama instance

Core Components

Tool System

The tool system is the foundation of the MyCoder agent's capabilities:

  • Modular Design: Each tool is a standalone module with clear inputs and outputs
  • Type Safety: Tools use Zod for schema validation and TypeScript for type safety
  • Token Tracking: Built-in token usage tracking to optimize API costs
  • Parallel Execution: Tools can run concurrently for efficiency

Agent System

The agent system orchestrates the execution flow:

  • Main Agent: Primary agent that handles the overall task
  • Sub-Agents: Specialized agents for parallel task execution
  • Agent State Management: Tracking agent status and communication
  • LLM Integration: Supports multiple LLM providers (Anthropic, OpenAI, Ollama)

LLM Providers

The agent supports multiple LLM providers:

  • Anthropic: Claude models with full tool use support
  • OpenAI: GPT-4 and other OpenAI models with function calling
  • Ollama: Local LLM support for privacy and offline use

Model Context Protocol (MCP)

MyCoder Agent supports the Model Context Protocol:

  • Resource Loading: Load context from MCP-compatible servers
  • Server Configuration: Configure multiple MCP servers
  • Tool Integration: Use MCP-provided tools

Available Tools

File & Text Manipulation

  • textEditor: View, create, and edit files with persistent state
    • Commands: view, create, str_replace, insert, undo_edit
    • Line number support and partial file viewing

System Interaction

  • shellStart: Execute shell commands with sync/async modes
  • shellMessage: Interact with running shell processes
  • shellExecute: One-shot shell command execution
  • listShells: List all running shell processes

Agent Management

  • agentStart: Create sub-agents for parallel tasks
  • agentMessage: Send messages to sub-agents and retrieve their output (including captured logs)
  • agentDone: Complete the current agent's execution
  • listAgents: List all running agents

The agent system automatically captures log, warn, and error messages from agents and their immediate tools, which are included in the output returned by agentMessage.

Network & Web

  • fetch: Make HTTP requests to APIs
  • sessionStart: Start browser automation sessions
  • sessionMessage: Control browser sessions (navigation, clicking, typing)
  • listSessions: List all browser sessions

Utility Tools

  • sleep: Pause execution for a specified duration
  • userPrompt: Request input from the user

Project Structure

src/
├── core/               # Core agent and LLM abstraction
│   ├── llm/            # LLM providers and interfaces
│   │   └── providers/  # Anthropic, OpenAI, Ollama implementations
│   ├── mcp/            # Model Context Protocol integration
│   └── toolAgent/      # Tool agent implementation
├── tools/              # Tool implementations
│   ├── agent/          # Sub-agent tools
│   ├── fetch/          # HTTP request tools
│   ├── interaction/    # User interaction tools
│   ├── session/        # Browser automation tools
│   ├── shell/          # Shell execution tools
│   ├── sleep/          # Execution pause tool
│   └── textEditor/     # File manipulation tools
└── utils/              # Utility functions and logger

Technical Requirements

  • Node.js >= 18.0.0
  • pnpm >= 10.2.1

Browser Automation

The agent includes powerful browser automation capabilities using Playwright:

  • Web Navigation: Visit websites and follow links
  • Content Extraction: Extract and filter page content
  • Element Interaction: Click buttons, fill forms, and interact with UI elements
  • Waiting Strategies: Smart waiting for page loads and element visibility

Usage Example

import { toolAgent } from 'mycoder-agent';
import { textEditorTool } from 'mycoder-agent';
import { shellStartTool } from 'mycoder-agent';
import { Logger, LogLevel } from 'mycoder-agent';

// Create a logger
const logger = new Logger({ name: 'MyAgent', logLevel: LogLevel.info });

// Define available tools
const tools = [textEditorTool, shellStartTool];

// Run the agent
const result = await toolAgent(
  'Write a simple Node.js HTTP server and save it to server.js',
  tools,
  {
    getSystemPrompt: () => 'You are a helpful coding assistant...',
    maxIterations: 10,
  },
  {
    logger,
    provider: 'anthropic',
    model: 'claude-3-opus-20240229',
    apiKey: process.env.ANTHROPIC_API_KEY,
    workingDirectory: process.cwd(),
  },
);

console.log('Agent result:', result);

Contributing

We welcome contributions! Please see our CONTRIBUTING.md for development workflow and guidelines.

License

MIT

changelog

mycoder-agent-v1.7.0 (2025-03-21)

Bug Fixes

  • Fix TypeScript errors and tests for message compaction feature (d4f1fb5)

Features

  • Add automatic compaction of historical messages for agents (a5caf46), closes #338
  • Improve message compaction with proactive suggestions (6276bc0)

mycoder-agent-v1.6.0 (2025-03-21)

Features

  • browser: add system browser detection for Playwright (00bd879), closes #333

mycoder-agent-v1.5.0 (2025-03-20)

Bug Fixes

  • improve resource trackers and fix tests (c31546e)
  • properly format agentDone tool completion message (8d19c41)
  • resolve build and test issues (549f0c7)
  • resolve TypeError in interactive mode (6e5e191)
  • restore visibility of tool execution output (0809694), closes #328
  • shell message should reset output on each read (670a10b)
  • update CLI cleanup to use ShellTracker instead of processStates (3dca767)

Features

  • add colored console output for agent logs (5f38b2d)
  • Add interactive correction feature to CLI mode (de2861f), closes #326
  • add parent-to-subagent communication in agentMessage tool (3b11db1)
  • add stdinContent parameter to shell commands (5342a0f), closes #301
  • implement ShellTracker to decouple from backgroundTools (65378e3)
  • remove respawn capability, it wasn't being used anyhow. (8e086b4)

mycoder-agent-v1.4.2 (2025-03-14)

Bug Fixes

mycoder-agent-v1.4.1 (2025-03-14)

Bug Fixes

  • typescript compile error, unsure how it got past CI. (ed9960a)

mycoder-agent-v1.4.0 (2025-03-14)

Bug Fixes

  • disable respawn as it can confuse some LLMs (c04ee43)
  • perfect gpustack compatibility, fix openai edge case (9359f62)

Features

  • support multiple line custom prompts in mycoder.config.js (fa7f45e), closes #249

mycoder-agent-v1.3.1 (2025-03-13)

Bug Fixes

  • redo ollama llm provider using ollama sdk (586fe82)
  • update Ollama provider to use official npm package API correctly (738a84a)

mycoder-agent-v1.3.0 (2025-03-12)

Features

  • implement MCP tools support (2d99ac8)

mycoder-agent-v1.2.0 (2025-03-12)

Bug Fixes

  • Fix TypeScript errors in MCP implementation (f5837d3)

Features

  • Add basic Model Context Protocol (MCP) support (8ec9619)
  • agent: implement incremental resource cleanup for agent lifecycle (576436e), closes #236
  • background tools is now scope to agents (e55817f)

mycoder-agent-v1.1.0 (2025-03-12)

Bug Fixes

  • convert absolute paths to relative paths in textEditor log output (a5ea845)
  • implement resource cleanup to prevent CLI hanging issue (d33e729), closes #141
  • llm choice working well for openai, anthropic and ollama (68d34ab)
  • openai: add OpenAI dependency to agent package and enable provider in config (30b0807)
  • replace @semantic-release/npm with @anolilab/semantic-release-pnpm to properly resolve workspace references (bacb51f)
  • up subagent iterations to 200 from 50 (b405f1e)

Features

  • add agent tracking to background tools (4a3bcc7)
  • add Ollama configuration options (d5c3a96)
  • agent: implement agentStart and agentMessage tools (62f8df3), closes #111 #111
  • allow textEditor to overwrite existing files with create command (d1cde65), closes #192
  • implement background tool tracking (issue #112) (b5bb489)
  • implement Ollama provider for LLM abstraction (597211b)
  • llm: add OpenAI support to LLM abstraction (7bda811)
  • refactor: agent (a2f59c2)

mycoder-agent-v1.0.0 (2025-03-11)

Bug Fixes

  • monorepo: implement semantic-release-monorepo for proper versioning of sub-packages (96c6284)
  • only consider response empty if no text AND no tool calls (#127) (af20ec5)
  • Replace shell commands with Node.js APIs for cross-platform compatibility (07b4c24)
  • token caching (5972e59)
  • use maxTokens in generateTextProps (bfb9da9)

Features

  • add back token tracking, system prompt caching. (ddc04ab)
  • add showStdIn and showStdout options to shellMessage and shellStart (aed1b9f), closes #167
  • add token caching. issue 145 (d78723b)
  • remove modelProvider and modelName - instant decrepation (59834dc)

mycoder-agent

0.7.0 (2025-03-10)

Bug Fixes

  • change where anthropic key is declared (f6f72d3)
  • ensure npm publish only happens on release branch (ec352d6)

Features

  • add GitHub Action for issue comment commands (136950f), closes #162
  • allow for generic /mycoder commands (4b6608e)
  • release: implement conventional commits approach (5878dd1), closes #140

0.6.1

Patch Changes

  • 5f43eeb: Improve check for API keys with better help messages.

0.6.0

Minor Changes

  • Simplify browser message tool parameter schema to make it easier for AI to call.

0.5.0

Minor Changes

  • a51b970: Convert from JsonSchema7Type to ZodSchema for tool parameters and returns, required for Vercel AI SDK integration.
  • 27f73e3: Add GitHub mode to MyCoder for working with issues and PRs
  • 66ff39e: Add support for OpenAI models (o3 mini and GPT-4o) via Vercel AI SDK
  • 9b9d953: Add performance profiler via --profile to diagnose slow start-up times on some OSes.
  • 27c2ba5: Refactored toolAgent.ts into modular components for improved maintainability and testability. Split into config.ts, messageUtils.ts, toolExecutor.ts, tokenTracking.ts, and types.ts modules.
  • a4331b8: Add textEditor tool that combines readFile and updateFile functionality
  • 9b9d953: Use cross platform compatibility tooling to build up context, rather than Linux/MacOS specific tools.

Patch Changes

  • 870cbee: Re-implemented token caching for Vercel AI SDK usage with Anthropic provider to reduce token consumption during repeated API calls.

0.4.0

Minor Changes

  • Adds sentry error reporting for quality monitoring.

0.3.0

Minor Changes

  • Better browser experience: show browser, take over user session, content filter, robustness improvements to browsing.

0.2.1

Patch Changes

  • Removed debug logging, fixed package.json urls for git repo.

0.2.0

Minor Changes

  • Add token caching, better user input handling, token usage logging (--tokenUsage), the ability to see the browser (--headless=false), and log prefixes with emojis.

0.1.3

Patch Changes

  • Improved sub-agent directions, do not assume a lack of a response is an agent being done, rather look for explicit confirmation, allow for sub-agents to have optional custom working directorires, break agent framework into the mycoder-agent package