This file is a reference for AI coding agents working on the mini-agent-ts project. It assumes no prior knowledge of the codebase.
mini-agent-ts is a TypeScript implementation of MiniMax's open-source Mini-Agent. It is a minimal, terminal-based LLM Agent with roughly 2,000 lines of core code. The agent supports:
- ReAct Mode: Multi-step reasoning and tool calling for complex tasks.
- Interleaved Chain of Thought: Streaming of reasoning content alongside regular responses.
- MCP Protocol: Integration with external tool ecosystems via the Model Context Protocol.
- Agent Skills: Domain-specific knowledge loaded from
SKILL.mdfiles. - Multi-Provider LLMs: OpenAI, Anthropic, MiniMax, DeepSeek, or any OpenAI-compatible API.
The project is an ESM-only Node.js package written in TypeScript. It is distributed as a CLI tool (mini-agent-ts) that can be installed globally via npm link.
| Layer | Technology |
|---|---|
| Language | TypeScript 5.9 (ES2022, strict mode) |
| Runtime | Node.js ≥ 18 |
| Module System | ESM ("type": "module") with NodeNext resolution |
| CLI Framework | Commander.js |
| Config Parsing | yaml + Zod validation |
| LLM SDKs | openai, @anthropic-ai/sdk |
| MCP SDK | @modelcontextprotocol/sdk |
| Testing | Vitest |
| Linting/Formatting | ESLint 9 + Prettier 3 |
| Git Hooks | Husky + lint-staged |
mini-agent-ts/
├── src/ # Source code
│ ├── index.ts # CLI entry point (ESM shebang → dist/index.js)
│ ├── cli.ts # Command-line parsing, startup, tool wiring
│ ├── agent.ts # Core ReAct loop and tool execution
│ ├── config.ts # YAML configuration loading and Zod schemas
│ ├── llm-client/ # LLM provider adapters
│ │ ├── llm-client.ts # Factory that selects OpenAI/Anthropic client
│ │ ├── llm-client-base.ts
│ │ ├── openai-client.ts
│ │ └── anthropic-client.ts
│ ├── schema/ # Shared types (Message, ToolCall, LLMStreamChunk)
│ │ ├── index.ts
│ │ └── schema.ts
│ ├── skills/ # Agent Skills loader and tool
│ │ ├── index.ts
│ │ ├── skill-loader.ts
│ │ ├── get-skill-tool.ts
│ │ └── types.ts
│ ├── tools/ # Built-in tools and MCP integration
│ │ ├── index.ts
│ │ ├── base.ts # Tool interface definitions
│ │ ├── file-tools.ts # read_file, write_file, edit_file
│ │ ├── bash-tool.ts # bash, bash_output, bash_kill
│ │ └── mcp/ # MCP client/transport wrappers
│ │ ├── index.ts
│ │ ├── connection.ts
│ │ ├── types.ts
│ │ └── utils.ts
│ └── util/ # Utilities
│ ├── logger.ts
│ └── terminal.ts
├── tests/ # Vitest tests
│ ├── bash-tool.test.ts
│ ├── tools.test.ts
│ ├── tool-schema.test.ts
│ └── llm-client.test.ts
├── config/ # Runtime configuration
│ ├── config-example.yaml
│ ├── config.yaml # Active config (gitignored; contains API key)
│ ├── system_prompt.md
│ └── mcp-example.json
├── skills/ # User-defined skills (gitignored)
├── skills-example/ # Example skill templates
│ ├── skill-creator/
│ └── template-skill/
├── package.json
├── tsconfig.json
├── eslint.config.js
├── .prettierrc
├── .husky/pre-commit
└── .github/workflows/ # CI workflows
npm run buildrunstsc && chmod +x dist/index.js.- TypeScript compiles
src/intodist/usingNodeNextmodule resolution. dist/index.jsis the executable CLI entry point (the sourcesrc/index.tsincludes#!/usr/bin/env node).tsconfig.jsonenablesstrict,composite,incremental,declaration, andsourceMap.
src/index.tscallsrun()fromsrc/cli.ts.- CLI parses
--workspace <dir>(defaults toprocess.cwd()). Config.findConfigFile('config.yaml')searches for config in this order:./config/config.yaml(current working directory)~/.mini-agent-ts/config/config.yaml{package_root}/config/config.yaml
Config.load()loads the YAML config and mergesMINI_AGENT_*environment variables on top. Env vars take precedence over YAML, and nested keys use double underscores (e.g.MINI_AGENT_RETRY__ENABLED).Config.fromYaml()is still available for direct YAML loading without env merging.- An
LLMClientis created based onprovider(openaioranthropic). - Built-in tools are instantiated:
ReadTool,WriteTool,EditTool,BashTool,BashOutputTool,BashKillTool. - Optional skills are loaded from
tools.skillsDir(./skillsby default). - Optional MCP tools are loaded from
tools.mcpConfigPath(mcp.jsonby default). Agent.run()executes the ReAct loop up tomaxSteps, streaming LLM output and dispatching tool calls.
The active config lives at config/config.yaml (gitignored). Create it from config/config-example.yaml. Key fields:
apiKey: 'YOUR_API_KEY'
apiBase: 'https://api.minimaxi.com/v1/'
model: 'MiniMax-M2.5'
provider: 'openai' # or 'anthropic'
enableLogging: false
verbose: false # Verbose console output (also --verbose CLI flag)
outputFormat: markdown # or 'text' for plain-text rendering
maxSteps: 100
systemPromptPath: 'system_prompt.md'
retry:
enabled: true
maxRetries: 3
tools:
skillsDir: './skills'
mcpConfigPath: 'mcp.json'
mcp:
connectTimeout: 10.0
executeTimeout: 60.0
sseReadTimeout: 120.0
heartbeatInterval: 30.0 # seconds, 0 disables keepalive
maxReconnectAttempts: 3
reconnectDelay: 1000 # milliseconds
maxToolResultTokens: 8000 # Truncate oversized tool results before sending to the LLMMCP servers are configured in config/mcp.json (copy from config/mcp-example.json). Supported connection types are stdio, sse, http, and streamable_http. The connection manager sends periodic heartbeat pings, reconnects automatically on connection failures, and closes all connections on process exit.
Before every LLM call, the agent prepares the message context: oversized tool results are truncated to tools.maxToolResultTokens, and the full history is compressed if it exceeds history.maxHistoryTokens. Because tool results are non-system messages, they can be compressed/dropped by the history manager rather than living forever in the system prompt. Multiple tool calls requested in a single assistant message are executed concurrently, with results pushed in declaration order.
- Run with
--verbose(or setverbose: true/MINI_AGENT_VERBOSE=true) to mirror logs to the console. - Each ReAct step emits
StepStats(LLM/tools/total timing) via theAgentRendererandLogger. LLMStreamChunkcarries optionalusagemetadata. OpenAI-compatible providers can return usage viastream_options: { include_usage: true }; Anthropic reports usage throughmessage_start/message_deltaevents. The agent aggregates per-step token counts when available.enableLogging: truewrites structured logs tologs/agent-<timestamp>.logregardless of verbose mode.outputFormat: text(or--text) strips Markdown from streamed response chunks and tool-result previews before printing to the terminal.
| Command | Description |
|---|---|
npm install |
Install dependencies |
npm run dev |
Run the CLI via tsx src/index.ts |
npm run build |
Compile TypeScript to dist/ and make dist/index.js executable |
npm start |
Run the compiled CLI |
npm run typecheck |
Run tsc --noEmit |
npm test |
Run Vitest in watch mode |
npm run test:run |
Run Vitest once |
npm run lint |
Lint src/**/*.ts with ESLint |
npm run lint:fix |
Lint and auto-fix issues |
npm run format |
Format src/**/*.ts with Prettier |
npm run format:check |
Check formatting without writing |
npm run preflight |
Build, test, lint, and npm link in one command |
- Language: English for all code comments, documentation, and user-facing strings.
- Imports: Use ESM syntax. In
src/, import sibling TypeScript files with the.jsextension (e.g.,import { Agent } from './agent.js'). TypeScript resolves these to.tssource during development and to compiled.jsindist/. - Formatting: Prettier with 80-character print width, 2-space indentation, single quotes, trailing commas where valid in ES5, and LF line endings.
- Types: Strict TypeScript is required. Avoid
any; useunknownwhen types are not known. Explicit function return types are not required by ESLint but are common. - Naming: Classes are
PascalCase. Tool names usesnake_case. File names usekebab-case. - Error Handling: Prefer returning structured
ToolResultobjects over throwing inside tools. In async code, avoid floating promises (ESLint enforces this). - Git Commits: Follow Conventional Commits (
feat,fix,docs,style,refactor,test,chore).
After every code modification, the agent should:
- Check whether related documentation or configuration files (e.g.,
README.md,AGENTS.md,package.json,config/config-example.yaml) need to be updated for consistency. If so, update them first. - Run tests with
npm run test:run. - If tests pass, stage the changed files with
git add. - Create a local
git commitusing Conventional Commits format (e.g.,feat:,fix:,docs:,style:,refactor:,test:,chore:).
Do NOT push to remote unless explicitly asked by the user.
- Tests are written with Vitest and live in
tests/. tests/bash-tool.test.tsis skipped on Windows because the bash implementation assumes a Unix shell.tests/llm-client.test.tsis an integration test that calls the live LLM API configured inconfig/config.yaml. It is automatically skipped if the config is missing or invalid.- CI runs
npm run test:runandnpm run preflighton every pull request and push tomain.
- API Keys:
config/config.yamlis gitignored, but the file on disk may contain a real API key. Never commit it or expose it in logs. The config search path also supports~/.mini-agent-ts/config/for storing secrets outside the repo. - Shell Execution:
BashToolexecutes arbitrary shell commands in the user environment. Validate and sanitize any command strings built from user input. - File Access: File tools resolve paths relative to the workspace directory but also accept absolute paths. Be mindful of path traversal when handling user-provided paths.
- MCP Tools: MCP servers run external processes or connect to remote endpoints. Treat their tools with the same caution as local shell commands.
- Workspace: The CLI creates the workspace directory if it does not exist. Ensure the agent runs in an intentional directory.
- The
Agentclass insrc/agent.tsis intentionally small. Most orchestration (config loading, tool wiring, I/O) lives insrc/cli.ts. Agentaccepts an optionalAgentRenderer(src/util/agent-renderer.ts). The core agent emits events (step start, thinking/response chunks, tool calls/results); the renderer handles presentation.TerminalAgentRendererprovides the default CLI output, andNoopRenderercan be used for tests or silent execution.- Conversation history is persisted under
~/.mini-agent-ts/history/{session-id}.json. Start with--resume <session-id>to restore a previous session. Usehistory.maxHistoryTokensinconfig.yamlto limit context length; older messages are summarized when the budget is exceeded. BashToolruns commands inside the workspace directory and enforces a security policy: destructive/system-wide commands are blocked, and sensitive commands likerm/del/formatrequire explicit allowlisting ortools.security.bash.allowDangerousCommands: true.ToolResultsupports aretriableflag. The Agent will automatically retry tools that fail withretriable: trueaccording toretry.maxRetries. LLM stream failures are also retried automatically.read_filesupports glob patterns (e.g.src/**/*.ts) for batch reads and automatically chunks large files when no line limit is provided.- When adding a new built-in tool, implement the
Toolinterface insrc/tools/, re-export it fromsrc/tools/index.ts, and instantiate it insrc/cli.ts. - When adding a new LLM provider, extend
LLMClientBaseinsrc/llm-client/and add the provider enum/case insrc/llm-client/llm-client.tsandsrc/schema/schema.ts. - Skills are loaded recursively from
SKILL.mdfiles. TheSkillLoaderparses YAML frontmatter and validates it againstSkillSchemainsrc/skills/types.ts. - MCP SDK classes are loaded dynamically in
src/tools/mcp/utils.tsto tolerate different package export layouts across versions.