Skip to content

Latest commit

Β 

History

9 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Agent Base ⚑

Use this template

Node.js License: MIT OpenAI Compatible Express

A foundational starter kit for building task-specific autonomous AI agents.

Clone this repository, describe the capabilities you want to your coding assistant, and let it generate the tools and prompts. The execution loop, streaming dashboard, and safety controls are already wired up.


πŸ’‘ Why this exists

Whenever you want to build an AI agent for a specific task (DevOps, database operations, file transformations, web scraping, server management, personal assistant), 70% of the work is repetitive boilerplate plumbing:

  • Writing the multi-turn tool execution loop and managing token context limits
  • Wiring Server-Sent Events (SSE) with heartbeat pings and event buffers for late connections
  • Building a browser interface to view the agent's actions and text responses
  • Parsing reasoning tokens (thought, reasoning_content, and <think>...</think> tags) from thinking models
  • Working around upstream model quirks (such as Gemini emitting concatenated JSON chunks or repeating tool names)
  • Adding confirmation dialogs for destructive actions
  • Implementing provider switching between OpenAI, OpenRouter, Groq, and local Ollama or LM Studio models

Agent Base provides all of that plumbing in one place. Instead of building infrastructure from scratch, you or your coding assistant add domain-specific tools, set the system instructions, and start using the agent right away.


πŸ’¬ Direct prompts to build your agent

Open this repository in your AI coding assistant (Cursor, Claude Code, Windsurf, Copilot, or OpenCode) and ask it to adapt the codebase:

"Turn this repository into a Docker manager agent that inspects running containers, reads logs, restarts services, and prunes unused images. Require confirmation before pruning images."

"Turn this repository into a GitHub pull request reviewer that lists open pull requests, fetches diffs, checks for security issues, and posts comments."

"Turn this repository into a crypto portfolio agent that fetches prices from CoinGecko, checks wallet balances, and calculates 24-hour profit and loss."

"Turn this repository into a research agent that searches the web, extracts key details from articles, and saves markdown summaries."

Your coding assistant reads AGENTS.md, registers tools in src/agent/tools.js, updates the instructions in src/agent/systemPrompt.js, updates the sample prompts in the interface, runs the test suite, and gives you a working agent.


⚑ Quick start

1. Create your repository and install dependencies

Click the Use this template button at the top of the GitHub page to create your own repository, then clone it:

git clone https://github.com/YOUR_USERNAME/YOUR_AGENT_NAME.git
cd YOUR_AGENT_NAME
npm install

Or clone Agent Base directly:

git clone https://github.com/walsoup/agent-base.git
cd agent-base
npm install

2. Add your API credentials

Copy the environment template:

cp .env.example .env

Set your provider details in .env (or configure them in the browser using the Setup & Config button):

OPENAI_API_KEY=your-api-key-here
OPENAI_MODEL=gemini-3.7-flash

3. Start the server

npm start

Open http://127.0.0.1:3700 in your browser.


🎨 Built-in UI themes

The web dashboard comes with 5 switchable themes accessible from the top bar or via the data-theme attribute:

Theme Key Aesthetic
Midnight Dark (Default) dark Deep slate gray and blurple
OLED Black oled Pure pitch-black with emerald accents
Catppuccin Mocha catppuccin Warm pastel mauve and lavender
Nord Frost nord Arctic icy blues and cool slates
Paper Light light Crisp high-contrast editorial light theme

Selected themes persist in localStorage. You can add custom palettes in public/style.css by defining a new [data-theme="your-theme"] block with CSS variables.


πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                   Web Dashboard (UI)                     β”‚
β”‚  β€’ Model picker & presets      β€’ Live SSE stream reader  β”‚
β”‚  β€’ Chain-of-thought view       β€’ Batch progress bars     β”‚
β”‚  β€’ Resource explorer           β€’ Theme switcher (5 looks)β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                             β”‚ HTTP / SSE
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                   Express Server                         β”‚
β”‚  β€’ /api/chat     β€’ /api/stream/:id   β€’ /api/approve      β”‚
β”‚  β€’ /api/state    β€’ /api/config       β€’ /api/dry-run      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                             β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                 Autonomous Agent Loop                    β”‚
β”‚                                                          β”‚
β”‚   1. Build dynamic system prompt from current state      β”‚
β”‚   2. Query model (OpenAI, OpenRouter, Groq, Ollama)      β”‚
β”‚   3. Stream text, reasoning tokens, and tool calls       β”‚
β”‚   4. Clean tool names and repair malformed JSON          β”‚
β”‚   5. Validate arguments with Zod schemas                 β”‚
β”‚   6. Pause for user approval on destructive actions      β”‚
β”‚   7. Run tool handler (with live progress events)        β”‚
β”‚   8. Store results in history and repeat until finish    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                             β”‚
              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
              β”‚                             β”‚
    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”       β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
    β”‚     Agent Tools     β”‚       β”‚     State Store     β”‚
    β”‚  Add your custom    β”‚       β”‚  Connect to your    β”‚
    β”‚  tools in tools.js  β”‚       β”‚  database or files  β”‚
    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ“ Directory structure

agent-base/
β”œβ”€β”€ AGENTS.md             # Instructions for coding assistants adapting this project
β”œβ”€β”€ package.json          # Node dependencies (Express, OpenAI, Zod)
β”œβ”€β”€ .env.example          # Environment template
β”œβ”€β”€ .gitignore            # Git exclusion rules
β”œβ”€β”€ README.md             # Project documentation
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ server.js         # Web server and API endpoints
β”‚   β”œβ”€β”€ agent/
β”‚   β”‚   β”œβ”€β”€ loop.js       # Multi-turn loop, streaming, and approval logic
β”‚   β”‚   β”œβ”€β”€ tools.js      # Tool registry (where domain skills are added)
β”‚   β”‚   β”œβ”€β”€ systemPrompt.js # Dynamic system prompt generator
β”‚   β”‚   └── config.js     # Provider configuration (OpenAI, Groq, Ollama)
β”‚   β”œβ”€β”€ state/
β”‚   β”‚   └── state.js      # Environment state store and dry-run flag
β”‚   └── util/
β”‚       β”œβ”€β”€ sse.js        # SSE manager with heartbeats and replay buffers
β”‚       β”œβ”€β”€ log.js        # Audit logging to daily JSONL files
β”‚       └── env.js        # .env persistence utilities
β”œβ”€β”€ public/               # Browser interface (with theme switcher)
└── test/
    └── verify.js         # Unit verification suite (run with npm test)

πŸ› οΈ Guide

Adding tools

Register tools in src/agent/tools.js using registerTool. You only need a Zod schema; Agent Base derives the OpenAI JSON schema automatically:

import { z } from 'zod';
import { registerTool } from './agent/tools.js';

registerTool({
  name: 'restart_service',
  description: 'Restart a system service or background worker',
  destructive: true, // Prompts for confirmation when live mode is active
  schema: z.object({
    service_name: z.string().describe('Name of the service to restart')
  }),
  handler: async (args) => {
    return { ok: true, result: `Service ${args.service_name} restarted.` };
  }
});

Batch progress tools

Batch tools can report progress back to the interface using the context.onProgress callback:

registerTool({
  name: 'batch_convert_files',
  description: 'Convert a list of files with live progress feedback',
  destructive: false,
  schema: z.object({
    files: z.array(z.string().min(1)).describe('Files to convert')
  }),
  handler: async (args, { onProgress }) => {
    const total = args.files.length;
    for (let i = 0; i < total; i++) {
      if (onProgress) {
        onProgress({
          current: i + 1,
          total,
          item: args.files[i],
          message: `Converting file ${i + 1}/${total}: ${args.files[i]}`
        });
      }
      await processFile(args.files[i]);
    }
    return { ok: true, result: { count: total } };
  }
});

Customizing state and system prompts

You can edit src/state/state.js and src/agent/systemPrompt.js directly, or configure them programmatically:

import { setSystemPromptBuilder } from './agent/systemPrompt.js';
import { setInitialState } from './state/state.js';

// Set a custom initial state model
setInitialState({
  servers: [{ id: 'srv-1', name: 'api-gateway', status: 'healthy' }]
});

// Override the dynamic prompt generator
setSystemPromptBuilder((snapshot, dryRun) => {
  return `You are a system monitoring agent. Operating in ${dryRun ? 'dry-run' : 'live'} mode.`;
});

REST API and SSE endpoints

Endpoint Method Description
/api/state GET Environment summary, active model, and dry-run flag
/api/setup GET, POST Provider credentials and baseURL configuration
/api/config GET, POST Runtime model and reasoning effort settings
/api/models GET Dynamic model listing from the upstream provider
/api/snapshot GET Full JSON state snapshot
/api/chat POST Start run or inject mid-flight steering message
/api/stream/:runId GET Real-time Server-Sent Events (SSE) stream
/api/approve POST Approve or deny a pending destructive tool call
/api/dry-run POST Toggle simulation or live armed execution mode
/api/cancel POST Cancel active execution run via AbortController
/api/reset POST Clear conversation history and active session state

Running the test suite

npm test

πŸ“œ License

MIT License. Copyright (c) 2026 walsoup.

About

Extensible autonomous AI agent framework with live web dashboard, SSE streaming, reasoning display, and model switching

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages