> ## Documentation Index
> Fetch the complete documentation index at: https://simplellmfunc.cn/llms.txt
> Use this file to discover all available pages before exploring further.

# Examples

> Categorized runnable examples from the SimpleLLMFunc repository

# Examples

All examples are in the [`examples/`](https://github.com/NiJingzhe/SimpleLLMFunc/tree/master/examples) directory. Each is self-contained and runnable.

## Quick Start

| Example                      | What It Shows                                       |
| ---------------------------- | --------------------------------------------------- |
| `basic_usage.py`             | Minimal `@llm_function` call with typed output      |
| `template_params_example.py` | Dynamic docstring templates with `_template_params` |

## Tool Usage

| Example                      | What It Shows                           |
| ---------------------------- | --------------------------------------- |
| `tool_usage_example.py`      | `@tool` decorator, multi-tool agent     |
| `multimodal_tool_example.py` | Tools returning `ImgPath`/`ImgUrl`      |
| `agent_as_tool_example.py`   | Nesting one agent as a tool for another |

## Chat & Streaming

| Example                   | What It Shows                                        |
| ------------------------- | ---------------------------------------------------- |
| `streaming_example.py`    | Consuming `LLMChunkArriveEvent` for real-time output |
| `event_stream_example.py` | Full event stream consumption pattern                |
| `abort_example.py`        | `AbortSignal` for cancellation                       |

## PyRepl & Runtime

| Example                               | What It Shows                                                                        |
| ------------------------------------- | ------------------------------------------------------------------------------------ |
| `pyrepl_example.py`                   | Persistent REPL: variables, streaming, reset                                         |
| `pyrepl_seaborn_multimodal_images.py` | PyRepl image artifact capture and multimodal tool return with multiple seaborn plots |
| `selfref_example.py`                  | `runtime.selfref.context.*` primitives                                               |

## Full Agent

| Example                        | What It Shows                                                                  |
| ------------------------------ | ------------------------------------------------------------------------------ |
| `tui_general_agent_example.py` | Complete coding agent with TUI, PyRepl, FileToolset, SelfRef, fork, compaction |

This is the reference implementation for building a production agent. See [Harness Patterns](/advanced/harness-patterns) for an architectural walkthrough.

## Running Examples

```bash theme={null}
# Clone the repo
git clone https://github.com/NiJingzhe/SimpleLLMFunc.git
cd SimpleLLMFunc

# Install dependencies
poetry install

# Copy and configure provider.json
cp examples/provider_template.json examples/provider.json
# Edit examples/provider.json with your API keys

# Run any example
poetry run python examples/basic_usage.py
poetry run python examples/tui_general_agent_example.py
```

## Building Your Own

Start from one of these patterns:

<CardGroup cols={3}>
  <Card title="One-shot Function" icon="bolt" href="/quickstart">
    `@llm_function` — typed input/output, no state
  </Card>

  <Card title="Chat Agent" icon="comments" href="/first-agent">
    `@llm_chat` + tools — multi-turn with ReAct loop
  </Card>

  <Card title="Full Agent" icon="robot" href="/advanced/harness-patterns">
    PyRepl + SelfRef + FileToolset + TUI — production-grade
  </Card>
</CardGroup>
