Skip to content

Examples

All examples are located in the /examples/ directory and can be run with:

Terminal window
bunx tsx examples/01-basic-usage.ts
ExampleDescription
01-basic-usage.tsCalculator gadget, three ways to run agents
02-custom-gadgets.tsClass-based vs functional gadgets, async, timeouts
03-hooks.tsMonitoring, custom observers, interceptors
04-human-in-loop.tsInteractive conversations with user input
05-streaming.tsEvent handling, collecting results
ExampleDescription
06-model-catalog.tsModel queries, cost estimation
07-logging.tsVerbose logging, debugging
08-hook-presets-advanced.tsAdvanced preset patterns, cost tracking, analytics
09-filesystem-gadgets.tsSecure file system operations with path sandboxing
10-text-handling.tsText response handling: textOnlyHandler, textWithGadgetsHandler
11-gadget-dependencies.tsGadget dependencies (DAG execution)
ExampleDescription
13-syntactic-sugar.tsFluent API showcase
14-hints.tsLLM assistance hints (iteration progress, parallel gadgets)
15-trailing-messages.tsEphemeral trailing messages injected per LLM request
ExampleDescription
16-image-generation.tsImage generation with DALL-E and cost tracking
17-speech-generation.tsText-to-speech generation with OpenAI TTS
18-multimodal-gadget.tsGadgets returning media (images, audio) with cost reporting
19-multimodal-input.tsVision and multimodal input support
ExampleDescription
20-external-gadgets.tsExternal gadgets from npm packages and git URLs
21-browseweb-multi-call.tsMulti-step web browsing with external gadget
FileDescription
cli.example.tomlCLI configuration file example

The /examples/gadgets/ directory contains production-ready gadgets you can use or learn from:

  • Calculator - Basic arithmetic operations
  • Strings - String manipulation utilities
  • Random - Random number and coin flip utilities
  • Filesystem - Secure file operations with sandboxing
  • Todo - Task planning system for agents
  • Web Search - Google search integration
const answer = await LLMist.createAgent()
.withModel('haiku')
.askAndCollect('Hello!');
const answer = await LLMist.createAgent()
.withModel('sonnet')
.withSystem('You are helpful')
.withGadgets(MyGadget)
.askAndCollect('Do something');
await LLMist.createAgent()
.withModel('flash')
.withGadgets(MyGadget)
.askWith('Do something', {
onText: (text) => console.log(text),
onGadgetResult: (r) => console.log(r.result),
});