What Is the Fabric AI Framework? A Developer's Guide to the Open-Source Go CLI
The Fabric AI framework is an open-source Go-based CLI and REST API that treats AI prompts as reusable Patterns, enabling users to augment workflows across multiple AI vendors including OpenAI, Anthropic, and local Ollama instances.
The Fabric AI framework, maintained by Daniel Miessler at danielmiessler/fabric, provides a modular architecture for integrating large language models into automated workflows. Unlike standard chat interfaces, Fabric structures interactions through version-controlled Markdown Patterns and JSON strategies, offering both a command-line tool and a programmable HTTP API for cognitive task automation.
Core Architecture of the Fabric AI Framework
CLI and Command Dispatch
The entry point resides in cmd/fabric/main.go, which initializes the command-line interface and dispatches execution to cli.Cli(). This layer parses input flags, loads configuration from ~/.config/fabric, and constructs a domain.ChatRequest that drives the processing pipeline.
Core Engine and Chat Session Management
The central orchestration logic lives in internal/core/chatter.go, implementing the core.Chatter struct. This component builds chat sessions by aggregating system messages loaded from Patterns, prepending strategy modifiers, and managing response streaming to the terminal. According to the source code, the engine also handles special file-change patches when Patterns are configured to modify code files automatically.
Plugin System and Vendor Abstraction
Fabric abstracts AI providers through a uniform Vendor interface defined in internal/plugins/ai/vendor.go, which specifies methods Send, SendStream, and ListModels. The vendor manager in internal/plugins/ai/vendors.go handles registration, model discovery, and case-insensitive lookups for providers including OpenAI, Anthropic, Gemini, Azure, Bedrock, and Ollama. This plug-in architecture enables swapping AI backends without modifying application logic.
Pattern Store and Prompt Strategies
Patterns are Markdown files stored in data/patterns/, each containing a system.md file (and optionally user.md) that defines AI behavior. Users extend functionality by adding custom patterns to ~/.config/fabric/patterns, which persist across updates. Additionally, JSON-defined strategies in data/strategies/—such as cot.json for chain-of-thought or tot.json for tree-of-thought—prepend reasoning instructions to system prompts, enhancing output quality without altering base Patterns.
REST API Server
The framework exposes all CLI capabilities via HTTP through internal/server/serve.go, which implements a Gin-based server. This REST layer enables integration into existing applications through endpoints for chat completion, pattern CRUD operations, model listing, and YouTube extraction.
Key Source Files and Implementation Details
Understanding the codebase requires familiarity with these critical files:
cmd/fabric/main.go– Entry point that initializes the CLI environment and callscli.Cli().internal/core/chatter.go– Central request processing, streaming logic, and file-change patch application.internal/plugins/ai/vendor.go– Defines theVendorinterface contract for all AI providers.internal/plugins/ai/vendors.go– Manager handling vendor registration and model name resolution.internal/plugins/template/template.go– Template engine supporting variables ({{variable}}) and plugin filters ({{plugin:text:upper:hello}}).internal/server/serve.go– Gin server setup exposing REST endpoints at/api/v1/chat.data/patterns/– Built-in Markdown Patterns defining default AI behaviors.data/strategies/– JSON strategy files containing prompt modifiers for reasoning techniques.
Practical Usage Examples
Running Built-in Patterns from the CLI
# Summarize clipboard content (macOS example)
pbpaste | fabric -p summarize
The CLI loads data/patterns/summarize/system.md, sends the piped content to the configured default model, and streams the summary output to stdout.
Applying Chain-of-Thought Strategies
# Apply chain-of-thought reasoning while summarizing
pbpaste | fabric --strategy cot -p summarize
The cot.json strategy file prepends step-by-step reasoning instructions to the system prompt, forcing the model to articulate its thought process before generating the final summary.
Using Template Variables and Plugins
# Pass variables to a pattern template
fabric -p my-pattern -v name=alice -v project=fabric
Within the Pattern, the template engine processes expressions like {{plugin:text:upper:{{name}}}} through the text plugin implemented in template.go, transforming "alice" into "ALICE" before sending to the AI vendor.
Calling the REST API
# Start the server (default port 8080)
fabric --serve
# Post a chat request via curl
curl -X POST http://localhost:8080/api/v1/chat \
-H "Content-Type: application/json" \
-d '{"pattern":"summarize","message":"Quarterly earnings report..."}'
The Gin router in serve.go handles the request via NewChatHandler, returning JSON responses that mirror the CLI output format.
Creating Custom Patterns
mkdir -p ~/.config/fabric/patterns/my-report
cat > ~/.config/fabric/patterns/my-report/system.md <<'EOF'
You are a concise technical writer.
Write a one-paragraph report about the following:
{{input}}
EOF
Custom patterns stored in the user configuration directory remain independent of repository updates, ensuring portability across Fabric versions.
Summary
- Fabric AI framework structures AI interactions through reusable Markdown Patterns and JSON-defined Strategies rather than ad-hoc prompts.
- The architecture centers on
internal/core/chatter.gofor session orchestration andinternal/plugins/ai/vendor.gofor provider abstraction. - Users interact via the CLI entry point at
cmd/fabric/main.goor the REST API defined ininternal/server/serve.go. - Advanced templating in
internal/plugins/template/template.gosupports variable substitution and text transformation plugins. - The framework supports multiple AI vendors—OpenAI, Anthropic, Gemini, Azure, Bedrock, and Ollama—through a unified interface.
Frequently Asked Questions
What programming language is Fabric written in?
Fabric is implemented entirely in Go (Golang), providing a statically-linked binary with no runtime dependencies. The codebase leverages Go's concurrency primitives to handle streaming AI responses and concurrent plugin operations efficiently.
How does Fabric handle different AI providers?
The framework uses a Vendor interface defined in internal/plugins/ai/vendor.go to normalize provider-specific implementations. The vendor manager in internal/plugins/ai/vendors.go supports case-insensitive model name resolution across OpenAI, Anthropic, Gemini, Azure, Bedrock, and local Ollama instances, allowing users to switch models via the --model flag without changing workflow definitions.
Where are custom user patterns stored?
User-created patterns reside in ~/.config/fabric/patterns/ as self-contained directories containing system.md and optional user.md files. This filesystem-based storage separates user customizations from the core installation, preventing package updates from overwriting personal workflows.
Can Fabric modify code files automatically?
Yes. The core.Chatter implementation in internal/core/chatter.go includes specialized logic to parse and apply file-change patches when using Patterns designed for code generation or refactoring. This enables automated codebase modifications directly through the CLI or REST API by processing the AI's structured response into concrete file system changes.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →