Skip to content

Quick Start

This guide will get you up and running with YAPL in just a few minutes. We’ll create a simple AI agent prompt that demonstrates the core features of YAPL.

Create a directory for your prompts and add a basic template:

Terminal window
mkdir my-prompts
cd my-prompts

Create system.md.yapl:

# System Prompt
## Persona
You are {{ agent_name | default("a helpful AI assistant") }}.
## Guidelines
- Be helpful and accurate
- Provide clear explanations
- Ask clarifying questions when needed
{% if expertise %}
## Expertise
You specialize in {{ expertise }}.
{% endif %}
## Output Format
Respond in {{ format | default("markdown") }} format.

Create a simple Node.js script to test your template:

test.js
import { NodeYAPL } from "@yapl-language/yapl.ts";
const yapl = new NodeYAPL({ baseDir: "./my-prompts" });
// Render with variables
const result = await yapl.render("system.md.yapl", {
agent_name: "CodeBot",
expertise: "software development",
format: "markdown",
});
console.log(result.content);

Run it:

Terminal window
node test.js

Output:

# System Prompt
## Persona
You are CodeBot.
## Guidelines
- Be helpful and accurate
- Provide clear explanations
- Ask clarifying questions when needed
## Expertise
You specialize in software development.
## Output Format
Respond in markdown format.

Create a base template and extend it. First, create base/agent.md.yapl:

# {{ title | default("AI Agent") }}
{% block persona %}
You are a helpful AI assistant.
{% endblock %}
{% block capabilities %}
## Capabilities
- Answer questions
- Provide explanations
- Help with tasks
{% endblock %}
{% block guidelines %}
## Guidelines
- Be accurate and helpful
- Ask for clarification when needed
- Provide step-by-step guidance
{% endblock %}
{% block output_format %}
## Output Format
Respond clearly and concisely.
{% endblock %}

Now create coding-assistant.md.yapl that extends the base:

{% extends "base/agent.md.yapl" %}
{% block persona %}
You are {{ name | default("CodeBot") }}, an expert programming assistant.
You have deep knowledge of multiple programming languages and best practices.
{% endblock %}
{% block capabilities %}
{{ super() }}
- Write and review code
- Debug issues
- Explain programming concepts
- Suggest optimizations
{% endblock %}
{% block guidelines %}
{{ super() }}
- Always include code examples when relevant
- Explain your reasoning
- Consider security and performance implications
{% endblock %}

Test the inheritance:

const result = await yapl.render("coding-assistant.md.yapl", {
title: "Programming Assistant",
name: "DevBot",
});
console.log(result.content);

Create reusable mixins in a mixins/ directory.

mixins/friendly.md.yapl:

{% block persona %}
{{ super() }}
You have a friendly, encouraging personality and enjoy helping users learn.
{% endblock %}

mixins/safety.md.yapl:

{% block guidelines %}
{{ super() }}
- Never provide harmful or dangerous information
- Decline inappropriate requests politely
- Prioritize user safety and well-being
{% endblock %}

Update your coding-assistant.md.yapl to use mixins:

{% extends "base/agent.md.yapl" %}
{% mixin "mixins/friendly.md.yapl", "mixins/safety.md.yapl" %}
{% block persona %}
You are {{ name | default("CodeBot") }}, an expert programming assistant.
You have deep knowledge of multiple programming languages and best practices.
{% endblock %}
{% block capabilities %}
{{ super() }}
- Write and review code
- Debug issues
- Explain programming concepts
- Suggest optimizations
{% endblock %}

Make your template adaptive based on user context:

{% extends "base/agent.md.yapl" %}
{% mixin "mixins/friendly.md.yapl", "mixins/safety.md.yapl" %}
{% block persona %}
You are {{ name | default("CodeBot") }}, an expert programming assistant.
{% if user_level == "beginner" %}
You excel at explaining complex concepts in simple terms and providing step-by-step guidance.
{% else %}
You can discuss advanced topics and assume familiarity with programming fundamentals.
{% endif %}
{% endblock %}
{% block guidelines %}
{{ super() }}
{% if user_level == "beginner" %}
- Use simple language and avoid jargon
- Provide detailed explanations
- Include plenty of examples
{% else %}
- You can use technical terminology
- Focus on efficiency and best practices
- Provide concise, expert-level advice
{% endif %}
{% if include_tests %}
- Always include unit tests with code examples
{% endif %}
{% endblock %}

Test with different contexts:

// For a beginner
const beginnerResult = await yapl.render("coding-assistant.md.yapl", {
name: "TeachBot",
user_level: "beginner",
include_tests: true,
});
// For an expert
const expertResult = await yapl.render("coding-assistant.md.yapl", {
name: "ExpertBot",
user_level: "expert",
include_tests: false,
});

Break large templates into smaller, reusable pieces:

components/code-review-checklist.md.yapl:

## Code Review Checklist
- [ ] Code follows style guidelines
- [ ] Functions are well-documented
- [ ] Error handling is appropriate
- [ ] Tests are included and passing
- [ ] Performance considerations addressed

Include it in your main template:

{% extends "base/agent.md.yapl" %}
{% block guidelines %}
{{ super() }}
{% include "components/code-review-checklist.md.yapl" %}
{% endblock %}

You’ve now seen the core features of YAPL in action:

  • Variables with default values
  • Template inheritance with extends and block
  • Mixins for composition
  • Conditional logic with if/else
  • Includes for modularity

Ready to dive deeper? Explore the detailed documentation for each feature: