MCPcopy Index your code
hub / github.com/charmbracelet/fantasy

github.com/charmbracelet/fantasy @v0.35.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.35.0 ↗ · + Follow
1,294 symbols 4,600 edges 104 files 683 documented · 53% updated 2d agov0.35.0 · 2026-06-30★ 87018 open issues
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Fantasy

The Charm Fantasy logo

Latest Release GoDoc Build Status

Build AI agents with Go. Multi-provider, multi-model, one API.

  1. Choose a model and provider
  2. Add some tools
  3. Compile to native machine code and let it rip
import "charm.land/fantasy"
import "charm.land/fantasy/providers/openrouter"

// Choose your fave provider.
provider, err := openrouter.New(openrouter.WithAPIKey(myHotKey))
if err != nil {
    fmt.Fprintln(os.Stderr, "Whoops:", err)
    os.Exit(1)
}

ctx := context.Background()

// Pick your fave model.
model, err := provider.LanguageModel(ctx, "moonshotai/kimi-k2")
if err != nil {
    fmt.Fprintln(os.Stderr, "Dang:", err)
    os.Exit(1)
}

// Make your own tools.
cuteDogTool := fantasy.NewAgentTool(
  "cute_dog_tool",
  "Provide up-to-date info on cute dogs.",
  fetchCuteDogInfoFunc,
)

// Equip your agent.
agent := fantasy.NewAgent(
  model,
  fantasy.WithSystemPrompt("You are a moderately helpful, dog-centric assistant."),
  fantasy.WithTools(cuteDogTool),
)

// Put that agent to work!
const prompt = "Find all the cute dogs in Silver Lake, Los Angeles."
result, err := agent.Generate(ctx, fantasy.AgentCall{Prompt: prompt})
if err != nil {
    fmt.Fprintln(os.Stderr, "Oof:", err)
    os.Exit(1)
}
fmt.Println(result.Response.Content.Text())

🍔 For the full implementation and more see the examples directory.

Multi-model? Multi-provider?

Yeah! Fantasy is designed to support a wide variety of providers and models under a single API. While many providers such as Microsoft Azure, Amazon Bedrock, and OpenRouter have dedicated packages in Fantasy, many others work just fine with openaicompat, the generic OpenAI-compatible layer. That said, if you find a provider that’s not compatible and needs special treatment, please let us know in an issue (or open a PR).

Work in Progress

We built Fantasy to power Crush, a hot coding agent for glamourously invincible development. Given that, Fantasy does not yet support things like:

  • Image models
  • Audio models
  • PDF uploads

For things you’d like to see supported, PRs are welcome.

Whatcha think?

We’d love to hear your thoughts on this project. Need help? We gotchu. You can find us on:


Part of Charm.

The Charm logo

Charm热爱开源 • Charm loves open source

Extension points exported contracts — how you extend this code

LanguageModel (Interface)
LanguageModel represents a language model that can generate responses and stream responses. [6 implementers]
model.go
ProviderOptionsData (Interface)
ProviderOptionsData is an interface for provider-specific options data. All implementations MUST also implement encoding [27 …
content.go
Agent (Interface)
Agent represents an AI agent that can generate responses and stream responses. [7 implementers]
agent.go
Provider (Interface)
Provider represents a provider of language models. [4 implementers]
provider.go
AgentTool (Interface)
AgentTool represents a tool that can be called by a language model. This matches the existing BaseTool interface pattern [2 …
tool.go
UnmarshalFunc (FuncType)
UnmarshalFunc converts raw JSON into a ProviderOptionsData implementation.
provider_registry.go
RetryFn (FuncType)
RetryFn is a function that returns a value and an error.
retry.go
Option (FuncType)
Option defines a function that configures Kronk provider options.
providers/kronk/options.go

Core symbols most depended-on inside this repo

Run
called by 385
tool.go
Generate
called by 139
agent.go
LanguageModel
called by 135
provider.go
GetType
called by 93
content.go
getCharAt
called by 92
jsonrepair/jsonrepair.go
Error
called by 83
errors.go
NewAgent
called by 76
agent.go
New
called by 71
providers/openai/openai.go

Shape

Function 724
Method 305
Struct 184
TypeAlias 38
FuncType 33
Interface 10

Languages

Go100%

Modules by API surface

agent.go77 symbols
content.go76 symbols
jsonrepair/jsonrepair.go63 symbols
providers/anthropic/anthropic_test.go54 symbols
providers/anthropic/anthropic.go49 symbols
agent_test.go49 symbols
providers/openai/openai_test.go48 symbols
content_json.go42 symbols
providers/google/google.go35 symbols
providers/openai/responses_options.go31 symbols
schema/schema_test.go29 symbols
providers/openai/responses_language_model.go29 symbols

For agents

$ claude mcp add fantasy \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page