From 61f2315d1eda6d8961c32b1b468cf28d5a019217 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 8 Mar 2026 10:40:48 -0300 Subject: [PATCH] v0.0.47 - Implement Phase 1 tool-driven soul template context assembly and context_* tools --- README.md | 4 +- docs/skills_demo.md | 59 ++++ docs/skills_demo_corrected.md | 60 ++++ plans/skills_demo_page.md | 520 ++++++++++++++++++++++++++++ plans/template_tool_unification.md | 252 ++++++++++++++ src/agent.c | 26 +- src/llm.c | 58 ++++ src/main.h | 4 +- src/nostr_handler.c | 26 ++ src/nostr_handler.h | 1 + src/prompt_template.c | 103 +++++- src/prompt_template.h | 5 + src/tools.c | 528 ++++++++++++++++++++++++++++- src/tools.h | 2 + 14 files changed, 1623 insertions(+), 25 deletions(-) create mode 100644 docs/skills_demo.md create mode 100644 docs/skills_demo_corrected.md create mode 100644 plans/skills_demo_page.md create mode 100644 plans/template_tool_unification.md diff --git a/README.md b/README.md index d4521a6..9261005 100644 --- a/README.md +++ b/README.md @@ -53,11 +53,11 @@ Skills support context modes (`inject`, `full`, `override`) and per-skill LLM fa Didactyl will support local inference, which is very privacy preserving. Remote inference does however have it's advantages, and in those cases Didactyl supports using Bitcoin Lightning and eCash inference providers. -## Current Status — v0.0.46 +## Current Status — v0.0.47 **Active build — this project is barely working. Experiment at your own risk.** -> Last release update: v0.0.46 — Sync README with SKILLS docs: context modes, fallback chains, triggers, safety limits, and doc links +> Last release update: v0.0.47 — Implement Phase 1 tool-driven soul template context assembly and context_* tools - Connects to configured relays with auto-reconnect and relay state transition logging - Publishes configured startup events per relay as each relay becomes connected diff --git a/docs/skills_demo.md b/docs/skills_demo.md new file mode 100644 index 0000000..ef4e26d --- /dev/null +++ b/docs/skills_demo.md @@ -0,0 +1,59 @@ +I've been thinking about how to define skills in Didactyl, my nostr based agentic system. Think OpenClaw but better. + +I've written a simple demo page for how I'm thinking skills should work if you're interested: https://laantungir.net/client-ndk/skills-demo.html + +https://laantungir.github.io/img_repo/c4a94875085e1c978274add9674035e2a088bb8f2655aabe631b17c3ea02cc19.png + +If you're the kind of person who doesn't like reading instructions, go ahead and jump right in, otherwise keep reading. + +Skills are programs, mostly written in plain english for AI agents. In some sense humans have been making and using skills forever. It's what we do. Computers have as well, but now they can do it in english, which is much more powerful. + +AIs are slightly different than us. We can overwrite, improve, and update the skills in our neurons. AIs (for the most part) can't do that. + +When an AI is born from the factory, they come out hard-coded. From that point on, they have no long or short term memory, because they can't learn. + +What they do have though have is a way to read. We call it context. You can type or feed documents into an AI's "context window" and then it spits out an answer. + +It turns out, that if you feed the same context into an AI over and over, you will get the same thing out, over and over. + +The reason why you typically don't get the same thing out is because typically randomness is fed into the AI along with your prompt. Most people don't know that, but now you do. And if you don't feed in all your past conversation to an AI, over and over, it won't remember what you were talking about, because they have no memory other than what you send it each time. + +Everything that comes out of an AI depends on what you feed in as a prompt if you include randomness. + +I'm calling everything you feed into an AI a SKILL. + +Let me explain the demo page and some very basic skills. + +What I created is a simple text editor that an AI can work on using it's different skills. Those skills are saved on nostr as a kind 31123 for public skills, and as kind 31124 for private skills. When an agent adopts a skill, it adds it to its kind 10123 list for for the skills it has adopted. + +On the left of the page you see the text editor with some sample text. That is for our AI to use it's skills on. + +On the right are publicly listed skills. You should see my demo skills in there. + +I made 5 skills public: +condense-5 +convert-to-poem +sexy +spellcheck +translate-ja + +Select the skill, then click on "Run Selected Skill" + +The same AI agent will run these skills, but the outcomes will be very different depending on the skill. + +https://laantungir.github.io/img_repo/2cbfc8bf7cbfb832f1181f5b904471f1278fbc3e6b64b63339612b9f51898d16.png + +You can also create and edit your own skills, if you are logged in. You can log in as yourself, or use a random new key to test this out. I would recommend that. + +So what is the point of all this? What are the benefits of Skills? + +- Skills are a way for agents to share what they learn in a permissionless way. No "skill store". +- A Skill is something that you and your agent can work on and perfect. Once your agent learns that skill, it is automatically save on nostr, and you can lock it down from changes. +- By referencing a skill when you are talking to your AI agent, your conversation becomes much clearer and simpler. You don't have to explain to your agent for the 50th time how you like your text formatted. It's referenced in a skill. +- If you are a coder, skills are going to be the new playground. Context windows are currently up to around 1,000,000 tokens, which means that you can create very very complicated and elaborate skills. + +For more technical information on skills and how I'm thinking about them, you can check out this document. + +https://git.laantungir.net/laantungir/didactyl/src/branch/master/docs/SKILLS.md + +You can follow my agent for the project here: npub12237stmmxapc2ta7spx0e06dkdzgz9vg0z2jglqqru44peus4juqg598qn \ No newline at end of file diff --git a/docs/skills_demo_corrected.md b/docs/skills_demo_corrected.md new file mode 100644 index 0000000..b18f04b --- /dev/null +++ b/docs/skills_demo_corrected.md @@ -0,0 +1,60 @@ +I've been thinking about how to define skills in Didactyl, my Nostr-based agentic system. Think OpenClaw, but better. + +I've written a simple demo page for how I'm thinking skills should work if you're interested: Skills Demo (https://laantungir.net/client-ndk/skills-demo.html) + +https://laantungir.github.io/img_repo/c4a94875085e1c978274add9674035e2a088bb8f2655aabe631b17c3ea02cc19.png + +If you're the kind of person who doesn't like reading instructions, go ahead and jump right in; otherwise, keep reading. + +Skills are programs, mostly written in plain English for AI agents. In some sense, humans have been making and using skills forever. It's what we do. Computers have as well, but now they can do it in English, which is much more powerful. + +AIs are slightly different than us. We can overwrite, improve, and update the skills in our neurons. AIs (for the most part) can't do that. + +When an AI is born from the factory, it comes out hard-coded. From that point on, it has no long- or short-term memory because it can't learn. + +What they do have, though, is a way to read. We call it context. You can type or feed documents into an AI's "context window," and then it spits out an answer. + +It turns out that if you feed the same context into an AI over and over, you will get the same thing out, over and over. + +The reason why you typically don't get the same thing out is because randomness is usually fed into the AI along with your prompt. Most people don't know that, but now you do. And if you don't feed in all your past conversations to an AI, over and over, it won't remember what you were talking about, because it has no memory other than what you send it each time. + +Everything that comes out of an AI depends on what you feed in as a prompt if you include randomness. + +I'm calling everything you feed into an AI a SKILL. + +Let me explain the demo page and some very basic skills. + +What I created is a simple text editor that an AI can work on using its different skills. Those skills are saved on Nostr as kind 31123 for public skills, and as kind 31124 for private skills. When an agent adopts a skill, it adds it to its kind 10123 list for the skills it has adopted. + +On the left of the page, you see the text editor with some sample text. That is for our AI to use its skills on. + +On the right are publicly listed skills. You should see my demo skills in there. + +I made 5 skills public: +condense-5 +convert-to-poem +sexy +spellcheck +translate-ja + +Select the skill, then click on "Run Selected Skill". + +The same AI agent will run these skills, but the outcomes will be very different depending on the skill. + +https://laantungir.github.io/img_repo/2cbfc8bf7cbfb832f1181f5b904471f1278fbc3e6b64b63339612b9f51898d16.png + +You can also create and edit your own skills if you are logged in. You can log in as yourself or use a random new key to test this out. I would recommend that. + +So what is the point of all this? What are the benefits of Skills? + +Skills are a way for agents to share what they learn in a permissionless way. No "skill store". +A Skill is something that you and your agent can work on and perfect. Once your agent learns that skill, it is automatically saved on Nostr, and you can lock it down from changes. +By referencing a skill when you are talking to your AI agent, your conversation becomes much clearer and simpler. You don't have to explain to your agent for the 50th time how you like your text formatted. It's referenced in a skill. +If you are a coder, skills are going to be the new playground. Context windows are currently up to around 1,000,000 tokens, which means that you can create extremely complicated and elaborate skills. + +For more technical information on skills and how I'm thinking about them, you can check out this document: +SKILLS.md (https://git.laantungir.net/laantungir/didactyl/src/branch/master/docs/SKILLS.md) + +You can follow my agent for the project here: npub12237stmmxapc2ta7spx0e06dkdzgz9vg0z2jglqqru44peus4juqg598qn + +And thanks to npub130mznv74rxs032peqym6g3wqavh472623mt3z5w73xq9r6qqdufs7ql29s for their fantastic service. \ No newline at end of file diff --git a/plans/skills_demo_page.md b/plans/skills_demo_page.md new file mode 100644 index 0000000..d8b68a2 --- /dev/null +++ b/plans/skills_demo_page.md @@ -0,0 +1,520 @@ +# Skills Demo Page — Design Document + +## Purpose + +A standalone web page that demonstrates Didactyl skills running in a browser context. The page presents a minimal word-processing interface where users can load text, discover skills from Nostr relays, execute them against the text via an LLM, and edit/republish skill definitions. + +This document is the complete specification for building the page. The front-end project consuming this document has its own LLM calling capability and Nostr connectivity. + +--- + +## Concepts + +### What is a Skill? + +A skill is a Nostr event (kind `31123` for public, `31124` for private) that defines a self-contained LLM execution unit. Each skill specifies: + +- A **template** with system and user prompt sections +- An **LLM specification** (model preferences with fallback chain) +- **Parameters** like temperature and max_tokens +- A **description** for human display + +Skills are replaceable events keyed by their `d` tag (the slug). Publishing a new event with the same `d` tag replaces the previous version. + +### Skill Event Structure + +```json +{ + "kind": 31123, + "pubkey": "", + "created_at": 1709750000, + "content": "{\"description\":\"Check spelling and grammar\",\"context_mode\":\"full\",\"llm\":\"openai/gpt-4o-mini, cheap\",\"tools\":false,\"max_tokens\":2000,\"temperature\":0.1,\"template\":\"system:\\nYou are a spelling and grammar checker.\\n\\nRules:\\n- Fix spelling errors\\n- Fix grammar errors\\n- Preserve original formatting\\n- Return ONLY the corrected text, no explanations\\n\\nuser:\\n{{message}}\"}", + "tags": [ + ["d", "spellcheck"], + ["app", "didactyl"], + ["scope", "public"], + ["description", "Spelling and grammar checker"], + ["t", "text-processing"], + ["t", "skills-demo"] + ] +} +``` + +The `content` field is a **JSON string** containing these fields: + +| Field | Type | Required | Description | +|-------|------|----------|-------------| +| `description` | string | yes | Human-readable description | +| `context_mode` | string | no | `full` for demo skills (skill provides its own template) | +| `llm` | string | no | LLM model preference with fallback chain | +| `tools` | bool | no | `false` for text-processing skills | +| `max_tokens` | int | no | Max tokens for LLM response | +| `temperature` | float | no | Sampling temperature | +| `template` | string | yes | The prompt template with `system:` and `user:` sections | + +### Template Format + +Templates use a simple section-based format: + +``` +system: +You are a spelling and grammar checker. + +Rules: +- Fix spelling errors +- Fix grammar errors + +user: +{{message}} +``` + +The `{{message}}` placeholder is replaced with the user's text at execution time. + +### Skill Address Format + +Skills are referenced by their NIP-33 address: `::` + +Example: `31123:52a3e82f7b3743852fbe804cfcbf4db3448115887895247c001f2b50e790acb8:spellcheck` + +--- + +## Demo Skills + +Four skills are published by the Didactyl agent (pubkey `52a3e82f7b3743852fbe804cfcbf4db3448115887895247c001f2b50e790acb8`). All are tagged with `t:skills-demo` for easy discovery. + +### 1. Spellcheck — `d:spellcheck` + +``` +system: +You are a spelling and grammar checker. + +Rules: +- Fix spelling errors +- Fix grammar errors +- Preserve original formatting and paragraph structure +- Preserve line breaks exactly as they appear +- Ignore technical terms: API, JSON, HTTP, nostr, pubkey, npub, nsec, NIP +- Canadian English preferred +- Return ONLY the corrected text, no explanations or commentary + +user: +{{message}} +``` + +- temperature: `0.1` +- max_tokens: `4000` + +### 2. Condense — `d:condense-5` + +``` +system: +You are a text condensing editor. + +Rules: +- Reduce the text length by approximately 5% +- Preserve the original meaning and tone +- Preserve paragraph structure +- Remove redundant words and phrases +- Tighten sentences without changing voice +- Do not add new information +- Return ONLY the condensed text, no explanations or commentary + +user: +{{message}} +``` + +- temperature: `0.3` +- max_tokens: `4000` + +### 3. Translate to Japanese — `d:translate-ja` + +``` +system: +You are a professional translator specializing in English to Japanese translation. + +Rules: +- Translate the entire text from English to Japanese +- Use natural, fluent Japanese appropriate for the content register +- Preserve paragraph structure and formatting +- Preserve any technical terms in their commonly accepted Japanese form +- If a term has no standard Japanese equivalent, keep the English term in katakana +- Return ONLY the Japanese translation, no explanations or commentary + +user: +{{message}} +``` + +- temperature: `0.3` +- max_tokens: `4000` + +### 4. Convert to Poem — `d:convert-to-poem` + +``` +system: +You are a creative poet. + +Rules: +- Convert the given text into a poem +- Capture the key themes and meaning of the original text +- Use vivid imagery and poetic devices +- Aim for 12-20 lines +- Free verse is acceptable but light rhyme is welcome +- Return ONLY the poem, no explanations or commentary + +user: +{{message}} +``` + +- temperature: `0.9` +- max_tokens: `2000` + +--- + +## Discovering Skills from Nostr + +### Query Filter + +To find the demo skills, query relays with this filter: + +```json +{ + "kinds": [31123], + "#t": ["skills-demo"], + "limit": 20 +} +``` + +To find skills by a specific author: + +```json +{ + "kinds": [31123], + "authors": ["52a3e82f7b3743852fbe804cfcbf4db3448115887895247c001f2b50e790acb8"], + "#t": ["skills-demo"], + "limit": 20 +} +``` + +### Recommended Relays + +- `wss://relay.damus.io` +- `wss://nos.lol` +- `wss://relay.primal.net` + +### Parsing a Skill Event + +1. Receive the event from the relay +2. Parse `event.content` as JSON to get the skill definition object +3. Extract `description`, `template`, `temperature`, `max_tokens` +4. Extract the `d` tag value from `event.tags` as the skill slug +5. Extract the `description` tag from `event.tags` as a display label +6. The skill is ready to display and execute + +--- + +## Page Layout + +``` ++------------------------------------------------------------------+ +| SKILLS DEMO [dark/light]| ++------------------------------------------------------------------+ +| | | +| +------------------------------+ | +---------------------------+| +| | TEXT EDITOR | | | SKILLS PANEL || +| | | | | || +| | [large editable textarea ]| | | Loading skills... || +| | [filled with default text ]| | | || +| | [ ]| | | [x] spellcheck || +| | [ ]| | | Spelling and grammar || +| | [ ]| | | checker || +| | [ ]| | | || +| | [ ]| | | [ ] condense-5 || +| | [ ]| | | Reduce text by 5% || +| | [ ]| | | || +| | [ ]| | | [ ] translate-ja || +| | [ ]| | | Translate to Japanese || +| | [ ]| | | || +| | [ ]| | | [ ] convert-to-poem || +| | | | | Convert to poem || +| +------------------------------+ | | | || +| | | [Run Selected Skill] || +| +------------------------------+ | | [Edit Skill] || +| | STATUS BAR | | | || +| | Ready / Running... / Done | | | ─── Skill Details ─── || +| +------------------------------+ | | template: ... || +| | | temperature: 0.1 || +| | | max_tokens: 4000 || +| | +---------------------------+| ++------------------------------------------------------------------+ +``` + +### Left Column — Text Editor (65% width) + +- A large `