Here's a design for a simple language for interacting with a language model, addressing your requirements. I'll call it LM-Flow.
LM-Flow: A Simple Language for LM Interaction
LM-Flow is designed to be intuitive and direct, focusing on conversational flow, context management, and structured interaction with a language model.
Core Principles
- Context-Aware: The LM remembers the ongoing conversation and explicitly added context.
- Referential: Easily refer back to previous questions or answers.
- Action-Oriented: Commands clearly indicate desired actions (ask, decompose, list, iterate).
- Simple Syntax: Human-readable keywords, minimal punctuation.
Data Types
- Text: Enclosed in double quotes (
"...").
- References: Pointers to previous interactions or parts of them.
- Lists: Ordered collections of text or references.
Core Concepts
-
Interaction ID (_N): Each question-answer pair generated by the ASK command is assigned a unique, sequential ID, starting from _1.
_N.question: Refers to the question asked in interaction N.
_N.answer: Refers to the answer received in interaction N.
_last: A shortcut to refer to the most recent interaction (_last.question, _last.answer).
-
Parts (.parts): When an answer is decomposed, it becomes a list of component parts, accessible via .parts on the interaction reference.
_N.parts: A list of the decomposed components of _N.answer.
_N.parts[index]: Accesses a specific part (0-indexed).
-
Current Context: A persistent block of text that influences all subsequent ASK commands unless overridden.
Language Commands
1. ASK <text_query> / ASK <text_query> WITH CONTEXT <text>
2. ADD CONTEXT <text> / CLEAR CONTEXT
- Purpose: Manages the persistent context for future
ASK commands.
ADD CONTEXT <text>: Appends the given text to the current persistent context.
CLEAR CONTEXT: Empties the persistent context.
- Example:
ADD CONTEXT "User is a history enthusiast interested in European monarchies."
ASK "Who was Louis XIV?"
# Output (Interaction _4): LM answers, potentially focusing on his reign and impact on monarchy.
CLEAR CONTEXT
ASK "Who was Louis XIV?"
# Output (Interaction _5): LM answers more generally, without the specific history/monarchy focus.
3. DECOMPOSE <reference> INTO <description>
- Purpose: Instructs the LM to break down a previous answer (or part of it) into its constituent components based on a user-provided description.
- Behavior: The LM analyzes the
<reference> (e.g., _N.answer) and attempts to break it into a list of parts according to the <description>. These parts are then accessible via .parts on the original reference.
- Example:
ASK "What are the pros and cons of renewable energy?"
# Output (Interaction _6):
# Pros: Low emissions, sustainable, etc.
# Cons: Intermittent, high initial cost, etc.
DECOMPOSE _6.answer INTO "pros and cons sections"
# Internal: _6.parts would now contain something like:
# _6.parts[0]: "Pros: Low emissions, sustainable..."
# _6.parts[1]: "Cons: Intermittent, high initial cost..."
ASK "Elaborate on the environmental benefits from _6.parts[0]"
# Output (Interaction _7): Focuses on the environmental aspects of the pros section.
Note: The LM-Flow interpreter would display or make available the structure of _N.parts after decomposition.
4. LIST RESPONSES FOR <text_query_or_reference>
- Purpose: Asks the LM to generate a list of different ways to respond to a given question or situation.
- Behavior: The LM returns a list of text strings, which can then be iterated over. This command doesn't create a new interaction ID itself, but its result can be used in subsequent commands.
- Example:
LET options = LIST RESPONSES FOR "How can I respectfully decline a job offer?"
# Output: (Internally, 'options' now holds a list like)
# ["Option 1: Thank them, state your decision clearly, and offer to keep in touch.",
# "Option 2: Express gratitude, decline politely, and mention accepting another opportunity.",
# "Option 3: Ask for more time to consider (if applicable), then decline if necessary."]
Note: LET is introduced here for variable assignment, crucial for iteration.
5. LET <variable_name> = <value>
6. FOR EACH <item_var> IN <list_var> DO ... END
- Purpose: Iterates through a list, performing a set of commands for each item.
- Behavior: The commands between
DO and END are executed for every item in the <list_var>, with the current item available in <item_var>.
- Example (combining with
LIST RESPONSES):
LET interview_tips = LIST RESPONSES FOR "What are some common interview questions and good answers?"
# Output: interview_tips now holds a list of suggested question/answer pairs.
ADD CONTEXT "User is assessing these tips for a software engineering role."
FOR EACH tip IN interview_tips DO
ASK "Assess the practicality and effectiveness of this tip for a software engineer: {{tip}}"
# For each tip in the list, an ASK command is executed, using the tip as part of the query.
# This will generate multiple new interactions (_N, _N+1, etc.), each with an assessment.
END
CLEAR CONTEXT # Clean up persistent context
Example Full Workflow: Researching a Topic and Evaluating Perspectives
# 1. Initial Research
ADD CONTEXT "User is a university student researching climate change mitigation strategies."
ASK "What are the main approaches to carbon capture and storage (CCS)?"
# Output (Interaction _1): Detailed explanation of post-combustion, pre-combustion, oxy-fuel combustion, and direct air capture.
# 2. Decompose the Answer for specific focus
DECOMPOSE _1.answer INTO "individual methods and their basic principles"
# Internal: _1.parts now contains parts for each method (e.g., _1.parts[0] = "Post-combustion capture...", _1.parts[1] = "Pre-combustion capture...")
# 3. Get more detail on a specific method
ASK "Elaborate on the challenges and potential of _1.parts[3] (direct air capture)."
# Output (Interaction _2): Details on direct air capture challenges and potential.
# 4. Ask for different perspectives on a contentious issue related to the topic
LET criticisms = LIST RESPONSES FOR "What are common criticisms of CCS as a climate solution?"
# Output: criticisms now holds a list of arguments against CCS (e.g., cost, energy intensity, leakage risk, moral hazard).
# 5. Iterate through criticisms and ask for LM's counter-arguments or assessment
ADD CONTEXT "You are an expert in environmental policy. Provide balanced counter-arguments or contextualize the criticisms."
FOR EACH criticism IN criticisms DO
ASK "How valid is this criticism of CCS: '{{criticism}}'?"
# For each criticism, the LM provides a balanced assessment/counter-argument.
# This generates multiple new interactions (_3, _4, etc.), each evaluating a criticism.
END
CLEAR CONTEXT
# 6. Final Summary Request (using the context of the entire session implicitly or explicitly)
ASK "Based on our discussion, what are the most critical factors for successful CCS implementation?"
# Output (Interaction _last): Summarizes key factors, potentially drawing from the previous interactions.
Underlying Assumptions and Execution Model
- Statefulness: The LM-Flow interpreter maintains the
Current Context, Interaction IDs, and Variables.
- LM Capability: Assumes the underlying language model is capable of:
- Understanding complex instructions and context.
- Decomposing text based on descriptions.
- Generating lists of varied responses.
- Performing judgments/assessments.
- Output: The system would display the LM's responses to
ASK queries. For DECOMPOSE and LIST RESPONSES, it would conceptually make the structured data (.parts or list variables) available for subsequent commands.
Future Considerations / Enhancements
- Error Handling: Mechanisms for handling invalid commands or LM failures.
- Conditional Logic:
IF/ELSE statements for more complex decision-making based on LM output.
- Function Definitions: Allow users to define reusable blocks of LM-Flow commands.
- External Data Loading:
LOAD DATA "path/to/file.txt" to inject external information into context or for queries.
- Output Formatting: Commands to specify desired output format (JSON, markdown, plain text).
- User Feedback Integration:
RATE _N.answer or EDIT _N.answer to provide feedback or direct modifications that the LM could learn from or use for refinement.
This LM-Flow language provides a powerful yet simple way to guide complex interactions with a language model, moving beyond single-turn prompts to multi-step, context-rich dialogues.