funnel

module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 28, 2026 License: MIT

README

funnel

Out-of-band Map-Reduce MCP & CLI for AI agents.
Many inputs in, one synthesized output out — without blowing up your main agent's context window.


Why not just subagents?

Subagents funnel
Orchestration Parent LLM burns tokens & turns playing traffic cop Deterministic Go worker pool (zero orchestration tokens)
Context cost Every shard reply lands in the parent's context Shards stay out-of-band; parent receives only the final synthesis
File loading Agent must read 80 files into tool-call JSON first Pass glob: "**/*.go" — funnel reads .gitignore-filtered files directly
Large fan-outs Hits rate limits or overflows reducer context Bounded concurrency, retries, and automatic tree-reduction
Cost split Usually runs on the parent's expensive model Run map on fast/cheap models (<your-model>), reduce on whatever you want

Install

go install github.com/Lobarr/funnel/cmd/funnel@latest
Zero-config with an existing agent CLI

If you already have pi, claude, codex, or opencode installed and authenticated, funnel auto-detects it from PATH with no extra API keys:

funnel map-reduce --agent pi --model <your-model> --glob "**/*.go" ...
Or via OpenAI-compatible HTTP endpoint

Works with OpenRouter, LiteLLM, OpenAI, vLLM, Ollama:

export FUNNEL_BASE_URL="https://openrouter.ai/api/v1" # or http://localhost:11434/v1
export FUNNEL_API_KEY="sk-..."
export FUNNEL_MAP_MODEL="<your-model>"

MCP Setup

Local (stdio) — Claude Code, Cursor, pi, OpenCode
{
  "mcpServers": {
    "funnel": {
      "command": "funnel",
      "args": ["mcp"]
    }
  }
}

Or pin an agent preset / model explicitly: "args": ["mcp", "--agent", "pi", "--map-model", "<your-model>"].

Cluster / Shared Hub (Streamable HTTP)
funnel mcp --http :8080

Exposes / (MCP Streamable HTTP), /metrics (OTel/Prometheus), /healthz, and /debug/pprof/, with trace-correlated slog JSON logs on stderr and optional OTLP/HTTP export via OTEL_EXPORTER_OTLP_ENDPOINT.


Examples

See examples/ for copy-pasteable recipes:


MCP Tools

Tool What it does
funnel_map_reduce Fan out map_prompt across items / paths / glob / chunks_from, tree-reduce if needed, return only the final synthesis + stats
funnel_filter Evaluate a yes/no predicate_prompt in parallel and return only matching items with 1-line reasons
funnel_map Fan out map_prompt and return structured per-item outputs (supports json_mode)
funnel_reduce Standalone synthesis over an array of inputs with automatic tree-reduction

CLI Usage

# Audit every Go file (respects .gitignore) and synthesize a ranked report
funnel map-reduce \
  --glob "**/*.go" \
  --map "List any security or concurrency bugs in {{label}}." \
  --reduce "Deduplicate and rank the top 5 fixes."

# Filter a codebase to only files touching auth
funnel filter \
  --glob "**/*.go" \
  --predicate "Does this file implement authentication or JWT verification?"

# Pipe lines from stdin
git log --oneline -n 50 | funnel map-reduce \
  --map "Categorize this commit: {{item}}" \
  --reduce "Write concise release notes grouped by category."

Contributing

funnel is intentionally small, readable Go (internal/shard, internal/llm, internal/engine, internal/server, cmd/funnel).
Run tests with:

go test -race ./...

Directories

Path Synopsis
cmd
funnel command
Command funnel runs the funnel MCP server or CLI map-reduce commands.
Command funnel runs the funnel MCP server or CLI map-reduce commands.
internal
engine
Package engine executes bounded parallel map, filter, and tree-reduce operations over shard items using an LLM Completer.
Package engine executes bounded parallel map, filter, and tree-reduce operations over shard items using an LLM Completer.
llm
Package llm provides a minimal OpenAI-compatible chat completions client for executing map, filter, and reduce calls.
Package llm provides a minimal OpenAI-compatible chat completions client for executing map, filter, and reduce calls.
server
Package server exposes funnel's map-reduce, map, filter, and reduce primitives over the Model Context Protocol (MCP).
Package server exposes funnel's map-reduce, map, filter, and reduce primitives over the Model Context Protocol (MCP).
shard
Package shard loads and normalizes fan-out inputs from inline items, file paths, globs, or chunked files while enforcing safety guardrails.
Package shard loads and normalizes fan-out inputs from inline items, file paths, globs, or chunked files while enforcing safety guardrails.
telemetry
Package telemetry configures out-of-the-box OpenTelemetry metrics (Prometheus /metrics) and tracing (OTLP/HTTP when configured).
Package telemetry configures out-of-the-box OpenTelemetry metrics (Prometheus /metrics) and tracing (OTLP/HTTP when configured).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL