A from-scratch AI Agent Runtime in Go, built without any agent frameworks. Supports tool registration with JSON Schema, LLM autonomous decision-making, multi-turn multi-session conversations with real-time streaming, and disk-persisted session history.
📥 下载演示视频 (90MB) — 展示 momo 的实时流式响应、工具调用和多会话管理功能。
cmd/server/main.go Entry point, HTTP server
internal/
agent/
agent.go Core agent loop + tool execution
tool.go Tool interface + Registry + JSON Schema
session.go Session management + persistence + OpenAI format
context.go Context compression (turn-based, non-destructive)
prompts.go Go template system prompt (embedded templates)
store.go JSON file-backed session persistence
templates/
momo.md.tpl Main system prompt (rules, tools, workflow)
title.md Session title generation prompt
summary.md Context summary prompt
tools/
calculator.go Arithmetic expression evaluator
web.go Web fetch / search (URL fetching + HTML extraction)
read_docs.go Local file reader
time.go Current date/time
weather.go Real-time weather (wttr.in)
web/
handler.go Web UI with SSE streaming
User Input → LLM → Tool Call? → Execute → LLM → Tool Call? ...
↓ ↓
Final Answer Streaming via SSE
- Tool Registration: Each tool implements
Toolinterface with name, description, and JSON Schema parameters. LLM autonomously decides which tool to call. - Template System Prompt:
momo.md.tplrendered with env data (date, platform, working dir) — no hardcoded prompt strings. - SSE Streaming: Tool calls and results streamed to frontend via NDJSON over POST, no polling.
- Real-time Thinking Display: 🔧 tool calls, 📎 results, 🤔 LLM thinking shown live, latest step auto-expands and flows like water.
- Concurrent Sessions: Independent sessions with per-session mutex, concurrent-safe. Switch between sessions freely — each maintains its own context.
- Disk Persistence: Sessions saved as JSON files, survive server restart. Original messages never deleted — compression only affects LLM context.
- Turn-based Context Compression: 100-turn limit, oldest turns summarized into compact text when exceeded. Original data preserved on disk.
- Concurrency-safe:
sync.RWMutexon Session,SetStatus()for atomic status updates, per-request event callbacks via context (no shared mutable state).
| Tool | Description |
|---|---|
calculator |
Arithmetic expression evaluator (+, -, *, /, **, sqrt, sin, cos, etc.) |
web |
Fetch any URL and return readable text content. Also used for web search. |
read_docs |
Read any local file. |
get_time |
Get current date and time. |
weather |
Real-time weather via wttr.in (free, no API key). |
- Go 1.22+
- OpenAI API key (or any OpenAI-compatible API)
# Set your API key
export OPENAI_API_KEY=sk-...
# Run the web server
go run ./cmd/server/
# With custom model and API endpoint
go run ./cmd/server/ --model gpt-4o-mini --api-url https://api.openai.com/v1# 设置 DeepSeek API key(从 https://platform.deepseek.com/ 获取)
export OPENAI_API_KEY=sk-xxxxxxxxxxxxxxxx
# 使用 DeepSeek-V3 模型运行
go run ./cmd/server/ --model deepseek-chat --api-url https://api.deepseek.com/v1
# 使用 DeepSeek-R1 推理模型运行
go run ./cmd/server/ --model deepseek-reasoner --api-url https://api.deepseek.com/v1Open http://localhost:8080 in your browser.
- Calculator: "What is 2 + 2?" or "Calculate sqrt(144) * 3"
- Web: "What's the latest AI news?" or "Fetch https://example.com"
- Read Docs: "Read the file README.md"
- Weather: "What's the weather in Tokyo?"
- Multi-session: Open sidebar, create new sessions, ask different questions in parallel
go run ./cmd/server/ \
--api-key sk-... \ # OpenAI API key (default: OPENAI_API_KEY env)
--model gpt-4o-mini \ # LLM model (DeepSeek: deepseek-chat / deepseek-reasoner)
--api-url https://api.openai.com/v1 \ # OpenAI-compatible API base (DeepSeek: https://api.deepseek.com/v1)
--port 8080 \ # HTTP server port
--max-turns 999 \ # Max turns per request
--data-dir ./data # Session persistence directorygo test ./...github.com/sashabaranov/go-openai— OpenAI API clientgolang.org/x/net— HTML parsing for web content