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