Nous Examples

View Source

Learn Nous through practical examples, from basic usage to advanced patterns.

Quick Start

# Run any example
mix run examples/01_hello_world.exs

# Requires LM Studio running locally (default)
# Or set API keys for cloud providers:
export ANTHROPIC_API_KEY="sk-..."
export OPENAI_API_KEY="sk-..."

Core Examples (01-10)

Progressive learning path from basics to advanced features:

FileDescription
01_hello_world.exsMinimal example - create agent, run, get output
02_with_tools.exsFunction-based tools and context access
03_streaming.exsReal-time streaming responses
04_conversation.exsMulti-turn conversations with context continuation
05_callbacks.exsMap callbacks and process messages (LiveView)
06_prompt_templates.exsEEx templates with variable substitution
07_module_tools.exsTool.Behaviour pattern for module-based tools
08_tool_testing.exsMock tools, spy tools, and test helpers
09_agent_server.exsGenServer-based agent with PubSub
10_react_agent.exsReAct pattern for complex reasoning
11_human_in_the_loop.exsHITL approval workflows (sync + async PubSub)
12_pubsub_agent.exsPubSub agent lifecycle, registry, persistence
13_sub_agents.exsSub-agents (single + parallel) with fan-out/fan-in
14_structured_output.exsEcto schemas, JSON schema, multi-schema selection
15_input_guard.exsPrompt injection detection and blocking
16_hooks.exsLifecycle hooks: blocking, modification, priority ordering
17_skills.exsSkills: modules, file-based (load from .md files/dirs), groups, matching, built-in catalog
18_workflow.exsDAG workflow engine: pipelines, branching, parallel, cycles, HITL, hooks, LLM agents
19_coding_agent.exsCoding agent: file/shell tools, permissions, session guardrails, transcript compaction

Workflow Examples

End-to-end workflows with real LLM agent steps:

FileDescription
workflow/research_pipeline.exsMulti-agent research: plan → parallel search → synthesize report
workflow/quality_loop.exsLLM generates content, loops until quality gate passes
workflow/human_review.exsHuman-in-the-loop: approve, edit, and suspend patterns
workflow/parallel_analysis.exsBatch sentiment analysis + multi-specialist parallel branches

Provider Examples

Provider-specific configuration and features:

FileDescription
providers/anthropic.exsClaude models, extended thinking, tools
providers/openai.exsGPT models, function calling, settings
providers/lmstudio.exsLocal AI with LM Studio
providers/vllm_sglang.exsvLLM & SGLang high-performance local inference
providers/vertex_ai.exsGoogle Vertex AI with Goth auth
providers/llamacpp.exsLocal NIF-based inference via llama.cpp
providers/switching_providers.exsProvider comparison and selection

Memory Examples

Persistent agent memory with hybrid search:

FileDescription
memory/basic_ets.exsSimplest setup — ETS store, keyword search, zero deps
memory/local_bumblebee.exsLocal semantic search via Bumblebee, no API keys
memory/sqlite_full.exsSQLite + FTS5, single-file production setup
memory/duckdb_full.exsDuckDB with FTS + vector search
memory/postgresql_full.exsPostgreSQL + tsvector + pgvector, full Store implementation
memory/hybrid_full.exsMuninn + Zvec for maximum search quality
memory/cross_agent.exsTwo agents sharing memory with scoping
memory/auto_update.exsAuto-update memory after each run (no explicit tool calls)

Advanced Examples

Production patterns and advanced features:

FileDescription
advanced/context_updates.exsTool context updates and state management
advanced/error_handling.exsRetries, fallbacks, circuit breakers
advanced/telemetry.exsCustom metrics and cost tracking
advanced/cancellation.exsTask and streaming cancellation
advanced/liveview_integration.exsPhoenix LiveView integration patterns
advanced/liveview_chat.exsFull chat UI: streaming, tools, sessions, auto-scroll
advanced/liveview_multi_agent.exsMulti-agent dashboard with real-time PubSub status
advanced/tool_permissions.exsPermission policies: presets, custom deny/approve, tool filtering

Running Examples

Most examples use LM Studio by default (free, local):

  1. Download LM Studio
  2. Load a model (e.g., Qwen)
  3. Start the local server
  4. Run: mix run examples/01_hello_world.exs

For cloud providers, set the appropriate API key:

ANTHROPIC_API_KEY="..." mix run examples/providers/anthropic.exs
OPENAI_API_KEY="..." mix run examples/providers/openai.exs

Project Examples

For larger project examples (multi-agent systems, trading bots, etc.), see: