Skip to content

Add tiny LLM agent example (and a small wc companion)#373

Draft
bobzhang wants to merge 1 commit into
mainfrom
add-agent-example
Draft

Add tiny LLM agent example (and a small wc companion)#373
bobzhang wants to merge 1 commit into
mainfrom
add-agent-example

Conversation

@bobzhang
Copy link
Copy Markdown
Contributor

Summary

  • Add 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.post over HTTPS, @process.spawn with @process.read_from_process using a task-group pipe drain so proc.wait() cannot deadlock on a full output buffer, and @fs read/write.
  • Bundle a moonbit_guide.md reference loaded into the system prompt at startup so the model has verified @async idioms 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.
  • Add examples/wc, a small cat-style example that counts lines/words/bytes via @fs.read_file, String::fold over chars, and @utf8.encode.

How to run

  1. Set DEEPSEEK to a DeepSeek API key. Optional: DEEPSEEK_MODEL (defaults to deepseek-chat; deepseek-v4-pro recommended).
  2. From examples/: moon run agent -- "<task description>".

Test plan

  • moon check examples/agent passes
  • moon check examples/wc passes
  • moon run examples/wc -- /tmp/some_file.txt prints <lines> <words> <bytes> <path>
  • moon run examples/agent -- "<small task>" finishes with a === finished === line and a === total usage === summary

Marked 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

`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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant