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 bytecode 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-model combo.
24provider := openrouter.New(openrouter.WithAPIKey(myHotKey))
25model, err := provider.LanguageModel("moonshotai/kimi-k2")
26if err != nil {
27    fmt.Fprintln(os.Stderr, "Dang:", err)
28    os.Exit(1)
29}
30
31// Make your own tools.
32cuteDogTool := fantasy.NewAgentTool("cute_dog_tool", "Provide up-to-date info on cute dogs.", fetchCuteDogInfo)
33
34// Equip your agent.
35agent := fantasy.NewAgent(model, fantasy.WithTools(cuteDogTool))
36
37// Put that agent to work!
38const prompt = "Find all the cute dogs in Silver Lake, Los Angeles."
39result, err := agent.Generate(context.Background(), fantasy.AgentCall{Prompt: prompt})
40if err != nil {
41    fmt.Fprintln(os.Stderr, "Oof:", err)
42    os.Exit(1)
43}	
44fmt.Println(result.Response.Content.Text())
45```
46
47🍔 Hungry for more? [See the examples](https://github.com/charmbracelet/fantasy/tree/main/examples).
48
49## Multi-model? Multi-provider?
50
51Yeah! 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 package, many other 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).
52
53## Work in Progress
54
55We 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:
56
57- Image models
58- Audio models
59- PDF uploads
60
61For things you’d like to see supported, PRs are welcome.
62
63## Whatcha think?
64
65We’d love to hear your thoughts on this project. Need help? We gotchu. You can find us on:
66
67- [Slack](https://charm.land/slack)
68- [Discord][discord]
69- [Twitter](https://twitter.com/charmcli)
70- [The Fediverse](https://mastodon.social/@charmcli)
71- [Bluesky](https://bsky.app/profile/charm.land)
72
73[discord]: https://charm.land/discord
74
75---
76
77Part of [Charm](https://charm.land).
78
79<a href="https://charm.land/"><img alt="The Charm logo" src="https://stuff.charm.sh/charm-banner-next.jpg" width="400"></a>
80
81Charm热爱开源 • Charm loves open source