# `Jido.Character.Renderer`
[🔗](https://github.com/agentjido/jido_character/blob/v1.0.0/lib/jido_character/renderer.ex#L1)

Behaviour and dispatcher for character renderers.

A renderer transforms a character map into:
- A system prompt string (`to_system_prompt/2`)
- A `ReqLLM.Context` struct (`to_context/2`)

## Configuration Priority

Renderers are resolved in this order:
1. Per-call options (`:renderer` key)
2. Global application config
3. Built-in Markdown renderer (default)

## Global Configuration

    # config/config.exs
    config :jido_character, Jido.Character.Renderer,
      renderer: MyApp.CustomRenderer,
      renderer_opts: [format: :json]

## Implementing a Custom Renderer

    defmodule MyApp.CustomRenderer do
      @behaviour Jido.Character.Renderer

      @impl true
      def to_system_prompt(character, opts) do
        # Return a string prompt
        "You are #{character.name}..."
      end

      @impl true
      def to_context(character, opts) do
        # Return a ReqLLM.Context
        prompt = to_system_prompt(character, opts)
        ReqLLM.Context.new([ReqLLM.Context.system(prompt)])
      end
    end

The `to_context/2` callback is optional. If not implemented, the dispatcher
will wrap the result of `to_system_prompt/2` in a `ReqLLM.Context`.

# `character`

```elixir
@type character() :: map()
```

# `opts`

```elixir
@type opts() :: keyword()
```

# `to_context`
*optional* 

```elixir
@callback to_context(character(), opts()) :: ReqLLM.Context.t()
```

Render a character to a ReqLLM.Context struct.

# `to_system_prompt`

```elixir
@callback to_system_prompt(character(), opts()) :: String.t()
```

Render a character to a system prompt string.

# `default_renderer`

```elixir
@spec default_renderer() :: module()
```

Returns the default renderer module.

# `to_context`

```elixir
@spec to_context(character(), opts()) :: ReqLLM.Context.t()
```

Render a character to a ReqLLM.Context struct.

If the renderer doesn't implement `to_context/2`, falls back to wrapping
the system prompt from `to_system_prompt/2`.

## Options

- `:renderer` - Module implementing `Jido.Character.Renderer` behaviour
- `:renderer_opts` - Options passed to the renderer

## Examples

    context = Jido.Character.Renderer.to_context(character)
    context = Jido.Character.Renderer.to_context(character, renderer: MyCustomRenderer)

# `to_system_prompt`

```elixir
@spec to_system_prompt(character(), opts()) :: String.t()
```

Render a character to a system prompt string.

## Options

- `:renderer` - Module implementing `Jido.Character.Renderer` behaviour
- `:renderer_opts` - Options passed to the renderer

## Examples

    prompt = Jido.Character.Renderer.to_system_prompt(character)
    prompt = Jido.Character.Renderer.to_system_prompt(character, renderer: MyCustomRenderer)

---

*Consult [api-reference.md](api-reference.md) for complete listing*
