Skip to main content

Instructions

Instructions define how the model should respond to different input patterns. There are two main types of instructions.

All instructions are subject to the context snippets parameter of the protocol. This parameter determines the number of context snippets that will be provided to each instruction. An ExtendedInstruction will always have one more context snippet than an Instruction.

Key Differences

  • Instruction (Standard): Use for most cases. Defines structured input-output patterns with predefined response formats and contexts.
  • ExtendedInstruction (Advanced): Allows you to extend the context of the instruction by one line. The model's response is not tied to a TokenSet in this case, but is a specific string. Use for scenarios that require extended context.

Instruction (Standard)

The standard instruction type for most use cases. Defines structured input-output patterns with predefined response formats.

Parameters

  • context: Sequence of TokenSets that provide background information. The number of context samples provided is determined by the protocol's instruction_context_snippets parameter, and must be the same across all instructions.
  • response: The TokenSet that defines the model's structured response pattern
  • final: A Token that represents the final action or result. E.g. "Continue", "End", "Explode". Defaults to <NON>. Can be a Token or NumToken.

Creating Instructions

# Create TokenSets
cat_pondering = mtp.TokenSet(tokens=(tree, cat, ponder))
cat_grinning = mtp.TokenSet(tokens=(tree, cat, grin))

# Create an instruction for the Cat's internal thoughts
instruction = mtp.Instruction(
context=[cat_pondering],
response=cat_grinning,
final=disappear
)

Adding Samples to Instructions

add_sample() parameters:

  • context_snippets: List of context snippets that will be added to the Instruction
  • response_snippet: The model's response snippet
  • value: Optional numerical value (required if final Token is a NumToken)
# Samples must be made on their associated TokenSets
sample_context = cat_pondering.create_snippet(
string="Why do I keep vanishing and reappearing so suddenly?"
)
sample_response = cat_grinning.create_snippet(
string="Because it amuses me, and it keeps everyone wondering whether I'm truly here at all."
)

instruction.add_sample(
context_snippets=[sample_context],
response_snippet=sample_response
)

ExtendedInstruction (Advanced)

For scenarios that require extended context. The model's response is set a string, and lacks a TokenSet as the tradeoff for an extra context snippet. It is not possible to add a NumToken or NumListToken to an ExtendedInstruction response.

Parameters

  • context: Sequence of TokenSets that provide background information. The last TokenSet in the context represents the input pattern.
  • final: A Token that represents the final action or result

Creating ExtendedInstructions

# Create TokenSets for Alice and Cat interaction
alice_talk = mtp.TokenSet(tokens=(tree, alice, talk))
cat_talk = mtp.TokenSet(tokens=(tree, cat, talk))

# Create an extended instruction for scenarios requiring extended context
extended_instruction = mtp.ExtendedInstruction(
context=[alice_talk, cat_talk], # Last TokenSet represents input pattern
final=disappear
)

Adding Samples to ExtendedInstructions

add_sample() parameters:

  • context_snippets: List of context snippets that will be added to the Instruction (including the input snippet)
  • response_string: The model's response as a string
  • value: Optional numerical value (required if final Token is a NumToken)
# Samples must be made on their associated TokenSets
sample_context = alice_talk.create_snippet(
string="I don't much care where—"
)
sample_input = alice_talk.create_snippet(
string="Can you tell me which way I ought to go?"
)

extended_instruction.add_sample(
context_snippets=[sample_context, sample_input],
response_string="Then it doesn't matter which way you go."
)

Instruction Patterns

Conversational Patterns

# Conversational instruction
conversation_context = mtp.TokenSet(tokens=(speaker, context))
conversation_response = mtp.TokenSet(tokens=(responder, response))

conversation_instruction = mtp.Instruction(
context=[conversation_context],
response=conversation_response,
final=mtp.Token("Continue")
)

Question-Answer Patterns

# Q&A instruction
question_context = mtp.TokenSet(tokens=(question, context))
answer_response = mtp.TokenSet(tokens=(answer, response))

qa_instruction = mtp.Instruction(
context=[question_context],
response=answer_response,
final=mtp.Token("Complete")
)

Interactive Patterns

# Interactive instruction with user input
user_context = mtp.TokenSet(tokens=(user, context))
system_response = mtp.TokenSet(tokens=(system, response))

interactive_instruction = mtp.ExtendedInstruction(
context=[user_context, system_response],
final=mtp.Token("Respond")
)

Multi-Step Instructions

Complex instructions with multiple context steps:

# Multi-step instruction
step1_context = mtp.TokenSet(tokens=(step1, context))
step2_context = mtp.TokenSet(tokens=(step2, context))
final_response = mtp.TokenSet(tokens=(final, response))

multi_step_instruction = mtp.Instruction(
context=[step1_context, step2_context],
response=final_response,
final=mtp.Token("Complete")
)

Conditional Instructions

Instructions that depend on specific conditions:

# Conditional instruction
condition_context = mtp.TokenSet(tokens=(condition, context))
conditional_response = mtp.TokenSet(tokens=(conditional, response))

conditional_instruction = mtp.Instruction(
context=[condition_context],
response=conditional_response,
final=mtp.Token("Conditional")
)

Best Practices

  1. Clear Context: Provide clear context that helps the model understand the situation
  2. Appropriate Responses: Ensure responses match the expected behavior
  3. Consistent Patterns: Use consistent instruction patterns throughout your protocol
  4. Adequate Samples: Provide enough samples to train the model effectively
  5. Proper Token Usage: Use the correct token types for each instruction component

Instruction Validation

The MTP system ensures that:

  • All TokenSets in instructions are properly defined
  • ExtendedInstructions use the last TokenSet in context for user input patterns
  • Instructions define structured response patterns
  • All samples match the defined instruction structure
  • Final tokens are appropriate for the instruction type

Common Instruction Types

Educational Instructions

# Educational instruction
lesson_context = mtp.TokenSet(tokens=(lesson, topic, level))
explanation_response = mtp.TokenSet(tokens=(explanation, detail, example))

educational_instruction = mtp.Instruction(
context=[lesson_context],
response=explanation_response,
final=mtp.Token("Learned")
)

Creative Instructions

# Creative instruction
creative_context = mtp.TokenSet(tokens=(creative, prompt, style))
creative_response = mtp.TokenSet(tokens=(creative, output, result))

creative_instruction = mtp.Instruction(
context=[creative_context],
response=creative_response,
final=mtp.Token("Created")
)

Analytical Instructions

# Analytical instruction
analysis_context = mtp.TokenSet(tokens=(analysis, data, method))
analysis_response = mtp.TokenSet(tokens=(analysis, result, conclusion))

analytical_instruction = mtp.Instruction(
context=[analysis_context],
response=analysis_response,
final=mtp.Token("Analyzed")
)

Advanced Instruction Features

Dynamic Instructions

Instructions that adapt based on input:

# Dynamic instruction with multiple possible responses
dynamic_context = mtp.TokenSet(tokens=(dynamic, context, condition))
dynamic_response = mtp.TokenSet(tokens=(dynamic, response, adaptation))

dynamic_instruction = mtp.Instruction(
context=[dynamic_context],
response=dynamic_response,
final=mtp.Token("Adapted")
)

Hierarchical Instructions

Instructions with nested or hierarchical structures:

# Hierarchical instruction
parent_context = mtp.TokenSet(tokens=(parent, context))
child_context = mtp.TokenSet(tokens=(child, context, parent))
hierarchical_response = mtp.TokenSet(tokens=(hierarchical, response, level))

hierarchical_instruction = mtp.Instruction(
context=[parent_context, child_context],
response=hierarchical_response,
final=mtp.Token("Hierarchical")
)