4f8764334120d8aaa2aef13ef31e56bb079bb8c8
Rewrites NativeAgent.process() from single-turn to an iterative tool loop. When toolRegistry and toolExecutor are provided, the agent calls the model, executes any requested tool calls, feeds results back, and loops until the model returns a text response or max iterations hit. - Backward compatible: works exactly as before without tools - Supports onToolUse callback for frontend status display - Max iterations (default 10) prevents infinite loops - Handles multiple tool calls per model response - 5 new tests (8 total)
Flynn
Self-hosted personal AI assistant with Telegram and Terminal interfaces.
Features
- Multi-Frontend: Telegram bot + Terminal UI (minimal & fullscreen modes)
- Multi-Model: Anthropic Claude, OpenAI, Ollama with intelligent routing
- Model Switching: Switch between cloud/local models on demand
- Session Persistence: SQLite-backed conversation history
- Fallback Chains: Automatic failover when primary model fails
- Hook Engine: Confirmation system for sensitive operations
- Session Transfer: Move conversations between frontends
Quick Start
# Install dependencies
pnpm install
# Copy and configure
cp config/default.yaml ~/.config/flynn/config.yaml
# Edit config with your API keys and Telegram bot token
# Build and run
pnpm build
pnpm start
Configuration
Config location: ~/.config/flynn/config.yaml (or set FLYNN_CONFIG)
telegram:
bot_token: "your-telegram-bot-token"
allowed_chat_ids: [123456789] # Your Telegram user ID
models:
default:
provider: anthropic
model: claude-opus-4-5-20251101
api_key: sk-ant-api03-...
local:
provider: ollama
model: qwen2.5:14b
fallback_chain: [local]
hooks:
confirm: [shell.*, file.write]
log: [web.*, file.read]
silent: [notify]
Model Providers
| Provider | Config |
|---|---|
| Anthropic | provider: anthropic, api_key or auth_token |
| OpenAI | provider: openai, api_key, optional endpoint |
| Ollama | provider: ollama, model, optional endpoint |
Model Tiers
Configure multiple models for different purposes:
models:
fast: { provider: anthropic, model: claude-sonnet-4-... }
default: { provider: anthropic, model: claude-opus-4-5-... }
complex: { provider: anthropic, model: claude-opus-4-5-... }
local: { provider: ollama, model: qwen2.5:14b }
Telegram Commands
| Command | Description |
|---|---|
/start |
Initialize bot |
/reset |
Clear conversation history |
/status |
Show current model and status |
/local |
Switch to local model |
/cloud |
Switch to cloud model |
/model |
Show model info and options |
Terminal UI
# Minimal mode (readline)
pnpm tui
# Fullscreen mode (React/Ink)
pnpm tui:fs
TUI Commands
| Command | Description |
|---|---|
/help |
Show help |
/reset |
Clear history |
/status |
Show session info |
/fullscreen |
Switch to fullscreen mode |
/transfer telegram |
Transfer session to Telegram |
/quit |
Exit |
Running as Service
# Create systemd user service
mkdir -p ~/.config/systemd/user
cat > ~/.config/systemd/user/flynn.service << 'EOF'
[Unit]
Description=Flynn Personal AI Assistant
After=network.target ollama.service
[Service]
Type=simple
WorkingDirectory=/path/to/flynn
ExecStart=/usr/bin/pnpm start
Restart=on-failure
RestartSec=5
Environment=NODE_ENV=production
[Install]
WantedBy=default.target
EOF
# Enable and start
systemctl --user daemon-reload
systemctl --user enable --now flynn
# View logs
journalctl --user -u flynn -f
Hook Engine
Control sensitive operations with pattern matching:
hooks:
confirm: # Requires user approval via Telegram
- shell.*
- file.write
log: # Logs but doesn't block
- web.*
- file.read
silent: # Executes without notification
- notify
Session Management
- Sessions persist in
~/.local/share/flynn/sessions.db - Session ID format:
{frontend}:{userId}(e.g.,telegram:123456789) - History survives restarts
- Transfer sessions between frontends with
/transfer
Architecture
src/
├── index.ts # Daemon entry
├── tui.ts # TUI entry
├── config/ # YAML config + validation
├── models/ # Model providers + router
├── backends/native/ # Agent implementation
├── session/ # SQLite persistence
├── hooks/ # Confirmation engine
├── daemon/ # Lifecycle management
└── frontends/
├── telegram/ # Telegram bot
└── tui/ # Terminal UI
Development
# Dev mode with watch
pnpm dev # Daemon
pnpm tui:dev # TUI
# Type check
pnpm typecheck
# Lint
pnpm lint
# Test
pnpm test
Environment Variables
| Variable | Description |
|---|---|
FLYNN_CONFIG |
Override config path |
ANTHROPIC_API_KEY |
Anthropic API key (fallback) |
OPENAI_API_KEY |
OpenAI API key (fallback) |
License
MIT
Description
Languages
TypeScript
92.3%
JavaScript
6.4%
HTML
0.4%
Swift
0.3%
Makefile
0.2%
Other
0.1%