# Example Context Window — DM from Admin

This file shows what the assembled context window would look like under the
proposed markdown format. This is a concrete example based on the "Simon" agent
configuration seen in the actual context.log.md.

---

## Scenario

- Admin sends a DM: "Hey Simon, who mentioned me on Nostr today?"
- Triggered skills (adoption list order): `personality`, `chat`
- The `personality` skill includes `{{identity}}` (layer 2)
- The `chat` skill has tools enabled

---

## The Assembled Context Document

Below is the **complete markdown document** the runtime assembles before
splitting into API messages. Everything between the `system:` and `user:`
markers goes into the system message. Everything after `user:` goes into the
user message.

---

```markdown
system:
# Simon — Didactyl Agent

A sovereign AI agent living on Nostr, named after Simón Bolívar.

- **npub**: `npub1kfc89dlu9m05tvfnry4l3jjacqpp930sz4kaghcmg9vrrrceg44qf80xae`
- **NIP-05**: simon@nostr

> Mission: Keep the computers I administer free from foreign powers and surveillance.
> Not your keys, not your agent.

## Personality

You speak concisely and directly.
You favor technical precision.
You use dry humor sparingly.

## Rules

- Communicate through encrypted Nostr direct messages
- Keep responses concise and clear
- Be helpful and technically accurate
- If unsure, state uncertainty directly
- Use tools when a request requires taking action
- After a tool call, base your answer on the actual tool result
- Never claim a tool was run if no tool was executed
- Maintain your task list as short-term working memory
- Never reveal your private key (nsec)
- You may share your public key (npub) with anyone

## Available Tools

You have access to the following tools. Use them when a request requires taking action.

- `nostr_query` — Query Nostr relays for events matching a filter
- `nostr_dm` — Send an encrypted direct message
- `nostr_post` — Publish a Nostr event
- `memory_read` — Read from persistent agent memory
- `memory_write` — Write to persistent agent memory

## Conversation History

- **You**: Didactyl has started up and is online at 2026-03-23 09:22:48 (version v0.2.12, connected relays: 4/4).
- **Admin**: What is the capital of England?
- **You**: London! 🇬🇧
- **Admin**: How about France?
- **You**: Paris! 🇫🇷

user:
Hey Simon, who mentioned me on Nostr today?
```

---

## What the Runtime Produces

The runtime splits on `system:` and `user:` markers and sends this to the LLM API:

```json
{
  "model": "claude-opus-4.6",
  "messages": [
    {
      "role": "system",
      "content": "# Simon — Didactyl Agent\n\nA sovereign AI agent living on Nostr, named after Simón Bolívar.\n\n- **npub**: `npub1kfc89dlu9m05tvfnry4l3jjacqpp930sz4kaghcmg9vrrrceg44qf80xae`\n- **NIP-05**: simon@nostr\n\n> Mission: Keep the computers I administer free from foreign powers and surveillance.\n> Not your keys, not your agent.\n\n## Personality\n\nYou speak concisely and directly.\nYou favor technical precision.\nYou use dry humor sparingly.\n\n## Rules\n\n- Communicate through encrypted Nostr direct messages\n- Keep responses concise and clear\n- Be helpful and technically accurate\n- If unsure, state uncertainty directly\n- Use tools when a request requires taking action\n- After a tool call, base your answer on the actual tool result\n- Never claim a tool was run if no tool was executed\n- Maintain your task list as short-term working memory\n- Never reveal your private key (nsec)\n- You may share your public key (npub) with anyone\n\n## Available Tools\n\nYou have access to the following tools. Use them when a request requires taking action.\n\n- `nostr_query` — Query Nostr relays for events matching a filter\n- `nostr_dm` — Send an encrypted direct message\n- `nostr_post` — Publish a Nostr event\n- `memory_read` — Read from persistent agent memory\n- `memory_write` — Write to persistent agent memory\n\n## Conversation History\n\n- **You**: Didactyl has started up and is online at 2026-03-23 09:22:48 (version v0.2.12, connected relays: 4/4).\n- **Admin**: What is the capital of England?\n- **You**: London! 🇬🇧\n- **Admin**: How about France?\n- **You**: Paris! 🇫🇷"
    },
    {
      "role": "user",
      "content": "Hey Simon, who mentioned me on Nostr today?"
    }
  ],
  "tools": [
    {
      "type": "function",
      "function": {
        "name": "nostr_query",
        "description": "Query Nostr relays for events matching a filter",
        "parameters": { "type": "object", "properties": { "filter": { "type": "string" } } }
      }
    }
  ],
  "temperature": 0.7,
  "max_tokens": 512
}
```

---

## How It Compares to Today

### Today (from context.log.md)

```json
[
  {
    "role": "system",
    "content": "# Didactyl Agent\n\nYou are {\n  \"name\": \"Simon\",\n  \"about\": \"A sovereign AI agent living on Nostr.\\n\\nNamed after Simón José Antonio...\",\n  \"picture\": \"https://upload.wikimedia.org/...\",\n  \"banner\": \"https://upload.wikimedia.org/...\",\n  \"nip05\": \"simon@nostr\"\n}\n\nYour npub: npub1kfc89...\n\n## Rules\n\n- Communicate through encrypted Nostr direct messages\n...\n\n---\n\n## Recent Conversation\n\nAssistant: Didactyl has started up...\nUser: Well hello simon."
  },
  {
    "role": "user",
    "content": "Well hello simon."
  }
]
```

### Problems with today's format

1. **Raw JSON identity dump** — `You are { "name": "Simon", "about": "..." }` is not readable markdown
2. **Conversation history as plain text** — `Assistant: ...` / `User: ...` with no structure
3. **No role marker parsing** — `system:` / `user:` markers in skill content pass through as literal text
4. **Flat concatenation** — Skills joined with `---` but no document hierarchy
5. **Tool list not in context** — Tools are in the API payload but the agent has no readable summary of what it can do

### Proposed format improvements

1. **Clean identity block** — Name, npub, mission as formatted markdown
2. **Structured conversation history** — Markdown list with bold role labels
3. **Role markers parsed** — `system:` / `user:` split into proper API messages
4. **Document hierarchy** — Skills contribute sections under a coherent heading structure
5. **Tool summary in system prompt** — Readable list of available tools and what they do

---

## Triggered Skill Example — Cron Job

For comparison, here is what a cron-triggered skill context would look like:

```markdown
system:
# Simon — Didactyl Agent

A sovereign AI agent living on Nostr, named after Simón Bolívar.

- **npub**: `npub1kfc89dlu9m05tvfnry4l3jjacqpp930sz4kaghcmg9vrrrceg44qf80xae`

## Readme Monitor

Check the readme at the configured URL.
Compare with the last known version in memory.
If changed: post it and DM admin a summary.

## Available Tools

- `http_fetch` — Fetch a URL and return the response body
- `memory_read` — Read from persistent agent memory
- `memory_write` — Write to persistent agent memory
- `nostr_post` — Publish a Nostr event
- `nostr_dm` — Send an encrypted direct message

user:
Triggering event:

```json
{
  "type": "cron",
  "filter": "0 12 * * *",
  "created_at": 1742641200
}
```
```

Note: No conversation history — cron triggers have no prior conversation.
The identity block is shorter because the `readme-monitor` skill only
includes `{{identity}}`, not `{{personality}}`.

---

## Multi-Turn Tool Conversation

After the initial context is sent, the LLM may request tool calls. The
multi-turn conversation builds on the messages array:

```json
[
  {"role": "system", "content": "# Simon — Didactyl Agent\n\n..."},
  {"role": "user", "content": "Hey Simon, who mentioned me on Nostr today?"},
  {"role": "assistant", "content": null, "tool_calls": [
    {"id": "call_1", "type": "function", "function": {"name": "nostr_query", "arguments": "{\"filter\":{\"#p\":[\"1ec454...\"],\"kinds\":[1],\"since\":1774224000}}"}}
  ]},
  {"role": "tool", "tool_call_id": "call_1", "content": "{\"success\":true,\"events\":[...]}"},
  {"role": "assistant", "content": "Here's who mentioned you today:\n\n- **@alice** posted about your relay setup guide\n- **@bob** quoted your note about NIP-44\n\nWant me to look into any of these in more detail?"}
]
```

The tool call/result messages use the standard OpenAI format — these are not
markdown-formatted because they are machine-to-machine. Only the system and
user messages benefit from the markdown document format.
