Add tiny LLM agent example (and a small wc companion)#373
Draft
bobzhang wants to merge 1 commit into
Draft
Conversation
`agent` is a ~270-line LLM agent that drives a small loop of three tools (shell, read, write) against the DeepSeek chat API to complete tasks described on the command line. It exercises `@http.post` over HTTPS, `@process.spawn` + `@process.read_from_process` with a task-group pipe drain so `proc.wait()` cannot deadlock on a full buffer, and `@fs` read/write. A bundled MoonBit reference (`moonbit_guide.md`) is loaded into the system prompt at startup so the model has verified idioms for the `@async` stack on hand. `wc` is a small companion example modeled on `cat`: counts lines, words, and bytes in a file using `@fs.read_file`, `String::fold` over chars, and `@utf8.encode`. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
examples/agent, a ~270-line MoonBit agent that drives a small loop of three tools (shell,read,write) against the DeepSeek chat API to complete tasks given on the command line. Demonstrates@http.postover HTTPS,@process.spawnwith@process.read_from_processusing a task-group pipe drain soproc.wait()cannot deadlock on a full output buffer, and@fsread/write.moonbit_guide.mdreference loaded into the system prompt at startup so the model has verified@asyncidioms on hand. The agent reports DeepSeek's prompt-cache hit/miss tokens per call and a session total so users can see the cache working.examples/wc, a smallcat-style example that counts lines/words/bytes via@fs.read_file,String::foldover chars, and@utf8.encode.How to run
DEEPSEEKto a DeepSeek API key. Optional:DEEPSEEK_MODEL(defaults todeepseek-chat;deepseek-v4-prorecommended).examples/:moon run agent -- "<task description>".Test plan
moon check examples/agentpassesmoon check examples/wcpassesmoon run examples/wc -- /tmp/some_file.txtprints<lines> <words> <bytes> <path>moon run examples/agent -- "<small task>"finishes with a=== finished ===line and a=== total usage ===summaryMarked as draft for review — happy to drop the bundled guide, split the two examples into separate PRs, or rework the protocol (currently ad-hoc JSON; switching to DeepSeek's native function-calling API is a likely follow-up).
🤖 Generated with Claude Code