README.md

 1# Fantasy
 2
 3<p>
 4  <img width="475" alt="The Charm Fantasy logo" src="https://github.com/user-attachments/assets/b22c5862-792a-44c1-bc98-55a2e46c8fb9" /><br>
 5  <a href="https://github.com/charmbracelet/fantasy/releases"><img src="https://img.shields.io/github/release/charmbracelet/fantasy.svg" alt="Latest Release"></a>
 6  <a href="https://pkg.go.dev/charm.land/fantasy?tab=doc"><img src="https://godoc.org/charm.land/fantasy?status.svg" alt="GoDoc"></a>
 7  <a href="https://github.com/charmbracelet/fantasy/actions"><img src="https://github.com/charmbracelet/fantasy/actions/workflows/build.yml/badge.svg?branch=main" alt="Build Status"></a>
 8</p>
 9
10Build AI agents with Go. Multi-provider, multi-model, one API.
11
121. Choose a model and provider
132. Add some tools
143. Compile to native machine code and let it rip
15
16> [!NOTE]
17> Fantasy is currently a preview. Expect API changes.
18
19```go
20import "charm.land/fantasy"
21import "charm.land/fantasy/providers/openrouter"
22
23// Choose your fave provider.
24provider, err := openrouter.New(openrouter.WithAPIKey(myHotKey))
25if err != nil {
26	fmt.Fprintln(os.Stderr, "Whoops:", err)
27	os.Exit(1)
28}
29
30ctx := context.Background()
31
32// Pick your fave model.
33model, err := provider.LanguageModel(ctx, "moonshotai/kimi-k2")
34if err != nil {
35	fmt.Fprintln(os.Stderr, "Dang:", err)
36	os.Exit(1)
37}
38
39// Make your own tools.
40cuteDogTool := fantasy.NewAgentTool(
41  "cute_dog_tool",
42  "Provide up-to-date info on cute dogs.",
43  fetchCuteDogInfoFunc,
44)
45
46// Equip your agent.
47agent := fantasy.NewAgent(
48  model,
49  fantasy.WithSystemPrompt("You are a moderately helpful, dog-centric assistant."),
50  fantasy.WithTools(cuteDogTool),
51)
52
53// Put that agent to work!
54const prompt = "Find all the cute dogs in Silver Lake, Los Angeles."
55result, err := agent.Generate(ctx, fantasy.AgentCall{Prompt: prompt})
56if err != nil {
57    fmt.Fprintln(os.Stderr, "Oof:", err)
58    os.Exit(1)
59}
60fmt.Println(result.Response.Content.Text())
61```
62
63🍔 For the full implementation and more [see the examples directory](https://github.com/charmbracelet/fantasy/tree/main/examples).
64
65## Multi-model? Multi-provider?
66
67Yeah! 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).
68
69## Work in Progress
70
71We built Fantasy to power [Crush](https://github.com/charmbracelet/crush), a hot coding agent for glamourously invincible development. Given that, Fantasy does not yet support things like:
72
73- Image models
74- Audio models
75- PDF uploads
76- Provider tools (e.g. web_search)
77
78For things you’d like to see supported, PRs are welcome.
79
80## Whatcha think?
81
82We’d love to hear your thoughts on this project. Need help? We gotchu. You can find us on:
83
84- [Slack](https://charm.land/slack)
85- [Discord][discord]
86- [Twitter](https://twitter.com/charmcli)
87- [The Fediverse](https://mastodon.social/@charmcli)
88- [Bluesky](https://bsky.app/profile/charm.land)
89
90[discord]: https://charm.land/discord
91
92---
93
94Part of [Charm](https://charm.land).
95
96<a href="https://charm.land/"><img alt="The Charm logo" src="https://stuff.charm.sh/charm-banner-next.jpg" width="400"></a>
97
98Charm热爱开源 • Charm loves open source