@ebowwa/glm-daemon-examples
v0.1.0
Published
Example applications demonstrating the GLM daemon in action
Maintainers
Readme
@ebowwa/glm-daemon-examples
Example applications demonstrating the GLM daemon in action.
Overview
This package contains comprehensive examples that demonstrate how to use the GLM daemon for autonomous AI agent workflows. Each example is self-contained, well-documented, and runnable.
Prerequisites
Required
- Node.js 18+ or Bun 1.0+
- @ebowwa/glm-daemon package installed
- @ebowwa/teammates package installed
- GLM API credentials configured
Optional (for specific examples)
- Git - for GitHub PR Bot example
- GitHub CLI (gh) - for creating actual PRs
- MCP servers - for tool integration examples
Installation
# Install the package
bun add @ebowwa/glm-daemon-examples
# Or install from source
cd packages/src/glm-daemon-examples
bun installQuick Start
# List all available examples
bun run example list
# Run a specific example
bun run example run simple-butler
# Get information about an example
bun run example info github-bot
# Run with custom task
bun run example run simple-butler --task "Write a hello world program"Examples
1. Simple Butler Demo
Complexity: Simple
File: examples/simple-butler.ts
Features:
- State persistence
- Hook usage (onSessionStart, onSessionEnd)
- Simple request/response pattern
- Clean shutdown
Description: A basic butler that demonstrates the most fundamental aspects of the GLM daemon. It shows how to create a daemon, monitor lifecycle events through hooks, and observe state persistence.
Run:
bun run example run simple-butlerCustom Task:
bun run example run simple-butler --task "Write a greeting to hello.txt"Expected Output:
[SimpleButler] ==================================================
[SimpleButler] Simple Butler Demo
[SimpleButler] ==================================================
[SimpleButler] Task: Write a simple greeting message...
[SimpleButler] Work directory: /path/to/dir
[SimpleButler] Team name: simple-butler-team
[SimpleButler]
[SimpleButler] --- Starting Butler ---
[SimpleButler] [onSessionStart] Session starting!
[SimpleButler] [onSessionStart] Initial state: {...}
[SimpleButler] ✓ Butler started!
...
[SimpleButler] --- Stopping Butler ---
[SimpleButler] ✓ Butler stopped!2. GitHub PR Bot
Complexity: Medium
File: examples/github-bot.ts
Features:
- Git workflow integration
- Worktree isolation for parallel execution
- Automatic commits and PR creation
- Clean cleanup of worktrees
Description: A dev personality that demonstrates automated PR workflows. It creates a git worktree for isolated changes, makes code changes based on a task, commits with descriptive messages, and can create a pull request.
Prerequisites:
- Git repository initialized
- GitHub CLI (gh) installed and authenticated (for actual PR creation)
Run:
# In your git repository
bun run example run github-bot
# With custom task
bun run example run github-bot --task "Add a new utility function"Expected Output:
[GitHubBot] ==================================================
[GitHubBot] GitHub PR Bot Demo
[GitHubBot] ==================================================
[GitHubBot] Repository: /path/to/repo
[GitHubBot] Task: Add a new utility function...
[GitHubBot] Base branch: dev
[GitHubBot] Auto commit: true
[GitHubBot]
[GitHubBot] --- Starting GitHub Bot ---
[GitHubBot] [onSessionStart] GitHub Bot starting!
[GitHubBot] [onSessionStart] Branch: feat/glm-...
[GitHubBot] ✓ GitHub Bot started!
[GitHubBot]
[GitHubBot] --- Monitoring progress ---
[GitHubBot] Status update:
[GitHubBot] Phase: executing
[GitHubBot] Iteration: 1
[GitHubBot] Progress: 2/5 subtasks
...
[GitHubBot] --- Bot Complete! ---
[GitHubBot] ✓ GitHub Bot stopped!3. Multi-Agent Coordination
Complexity: Complex
File: examples/team-coordination.ts
Features:
- Team creation and lifecycle
- Spawning multiple teammates with different roles
- Inter-agent messaging (direct and broadcast)
- Coordinated task execution
- Team cleanup
Description: Demonstrates multi-agent coordination using the teammates system. It creates a team with multiple specialized agents (planner, explorer, implementer, reviewer), shows how they communicate through messages, and coordinates their work.
Run:
bun run example run team-coordinationExpected Output:
[TeamCoordination] ==================================================
[TeamCoordination] Multi-Agent Coordination Demo
[TeamCoordination] ==================================================
[TeamCoordination] Task: Create a REST API...
[TeamCoordination] Team name: coordination-demo-team
[TeamCoordination]
[TeamCoordination] --- Creating Team ---
[TeamCoordination] ✓ Team created: coordination-demo-team
[TeamCoordination]
[TeamCoordination] --- Spawning Teammates ---
[TeamCoordination] Spawning planner...
[TeamCoordination] ✓ Spawned: planner
[TeamCoordination] Spawning explorer...
[TeamCoordination] ✓ Spawned: explorer
...
[TeamCoordination] Total teammates: 4
[TeamCoordination]
[TeamCoordination] --- Coordinating Work ---
[TeamCoordination] Sending task to planner...
[TeamCoordination] Sending exploration task...
...
[TeamCoordination] --- Coordinating Shutdown ---
[TeamCoordination] Requesting shutdown from planner...
...
[TeamCoordination] --- Cleaning Up Team ---
[TeamCoordination] ✓ Team deleted
[TeamCoordination]
[TeamCoordination] ==================================================
[TeamCoordination] Demo Complete!
[TeamCoordination] ==================================================4. Custom Hooks
Complexity: Medium
File: examples/custom-hooks.ts
Features:
- Priority-based execution
- Conditional execution with filters
- Pre-tool-use validation
- Post-tool-use logging and analysis
- Hook chaining
Description: Demonstrates advanced hook patterns including priority-based execution, conditional filtering, security validation, and performance monitoring. Shows how hooks can be chained and ordered.
Run:
bun run example run custom-hooksExpected Output:
[CustomHooks] ==================================================
[CustomHooks] Custom Hooks Demo
[CustomHooks] ==================================================
[CustomHooks] Active hooks:
[CustomHooks] - Session Logger (priority: 100)
[CustomHooks] - Security Validator (priority: 90)
[CustomHooks] - Performance Monitor (priority: 50)
[CustomHooks] - File Tracker (priority: 30)
[CustomHooks] - Conditional Logger (priority: 20)
[CustomHooks] - Token Monitor (priority: 10)
[CustomHooks]
[CustomHooks] --- Starting Daemon with Custom Hooks ---
[CustomHooks] [SessionLogger] ==================================================
[CustomHooks] [SessionLogger] Session Starting
[CustomHooks] [SessionLogger] Prompt: Create a TypeScript function...
[CustomHooks] [SessionLogger] Start time: 2026-02-05T...
...
[CustomHooks] [TokenMonitor] ==================================================
[CustomHooks] [TokenMonitor] Token Usage Summary
[CustomHooks] [TokenMonitor] Total input tokens: 1234
[CustomHooks] [TokenMonitor] Total output tokens: 5678
...
[CustomHooks] ✓ Custom hooks demonstrated!5. Tool Integration
Complexity: Medium
File: examples/tool-integration.ts
Features:
- MCP server integration
- Custom tool registration
- Tool filtering (allowed/blocked)
- Tool timeout configuration
- Retry logic with exponential backoff
Description: Shows how to integrate MCP tools, register custom tools, configure tool filtering, and handle timeouts and retries. Demonstrates both built-in tools and custom tool creation.
Run:
bun run example run tool-integrationExpected Output:
[ToolIntegration] ==================================================
[ToolIntegration] Tool Integration Demo
[ToolIntegration] ==================================================
[ToolIntegration] MCP enabled: true
[ToolIntegration] Tool timeout: 30000ms
[ToolIntegration] Max retries: 3
[ToolIntegration]
[ToolIntegration] --- Registering Custom Tools ---
[ToolIntegration] ✓ Custom tools registered:
[ToolIntegration] - factorial: Calculate n!
[ToolIntegration] - generatePassword: Generate secure passwords
[ToolIntegration] - fetchWeather: Get weather information
[ToolIntegration]
[ToolIntegration] --- Testing Custom Tools ---
[ToolIntegration] ✓ factorial(5) = 120
[ToolIntegration] ✓ Generated password: aB3$xY9...
[ToolIntegration] ✓ Weather in San Francisco: {...}
...
[ToolIntegration] ✓ Tool integration demonstrated!CLI Commands
List Examples
bun run example listShows all available examples with their descriptions, complexity, and features.
Get Example Info
bun run example info <name>Shows detailed information about a specific example, including prerequisites and usage options.
Run Example
# Run with default task
bun run example run <name>
# Run with custom task
bun run example run <name> --task "your custom task"
# Run in specific directory
bun run example run <name> --work-dir /path/to/dir
# Run with custom team name
bun run example run <name> --team-name my-teamValidate Installation
bun run example validateChecks that all required dependencies are installed.
Run All Examples
bun run example run-all
# Skip specific examples
bun run example run-all --skip simple-butler,github-botTips for Customization
1. Modify Tasks
Each example accepts a custom task:
import { simpleButlerExample } from "@ebowwa/glm-daemon-examples";
await simpleButlerExample("Your custom task here", {
workDir: process.cwd(),
teamName: "my-custom-team",
maxIterations: 5,
});2. Add Custom Hooks
const config = {
// ... other config
hooks: {
onSessionStart: async (state) => {
console.log("Custom session start logic");
},
onPreToolUse: async (tool, args) => {
// Custom validation
return true;
},
},
};3. Configure Tools
const config = {
// ... other config
tools: {
enableMCP: true,
allowedTools: ["Read", "Write", "Edit"],
blockedTools: ["rm", "delete"],
toolTimeout: 30000,
maxRetries: 3,
},
};4. Add Teammates
import { Teammate } from "@ebowwa/teammates";
const teammate = await Teammate.create("my-team", {
name: "custom-agent",
subagentType: "general-purpose",
prompt: "You are a specialized agent for...",
model: "glm-4.7",
});Architecture
Each example follows this structure:
example-name.ts
├── Example function (main entry point)
│ ├── Configuration setup
│ ├── Daemon creation
│ ├── Execution
│ └── Cleanup
└── Default run function (for CLI)Examples use shared utilities from src/utils/:
logger.ts- Colored console logginghelpers.ts- File operations, timeouts, retries
Troubleshooting
Daemon doesn't start
Check that:
- GLM API credentials are configured
- Working directory exists
- Required dependencies are installed
Run bun run example validate to check.
Hooks not executing
Verify:
- Hook functions return
truefor validation hooks - Hook IDs are unique
- Hooks are registered before daemon starts
Tools not available
Check:
- MCP servers are running
- Tools are in
allowedToolslist - Tools are not in
blockedToolslist
Contributing
To add a new example:
- Create file in
src/examples/ - Export example function and default run function
- Add to
EXAMPLESobject insrc/cli.ts - Document in this README
Example template:
/**
* Your Example Description
*/
export async function yourExample(
task: string,
options: { /* options */ } = {}
): Promise<void> {
// Implementation
}
export async function runYourExample(): Promise<void> {
await yourExample("default task");
}License
MIT
