**ALang v0.1 Proposal Summary**
1. **Executive Summary / TL;DR:**
The Autologos system, in its v3.x.x prose-directive form, has encountered limitations in reliability and maintainability due to the inherent challenges of an LLM consistently interpreting and executing a large body of natural language instructions. ALang (Autologos Language) v0.1 is proposed as a fundamental refactor to address these issues. ALang is a compact, formal, S-expression-based language designed to define Autologos's core logic and workflows. In this paradigm, the LLM acts as an intelligent dispatcher (interpreting user intent and current state to invoke appropriate ALang procedures) and as a core generator (for tasks like content creation and complex analysis, via carefully controlled ALang primitives). The Orchestrator serves as the trusted execution engine for ALang primitives, managing state, tool interactions, and user I/O. This approach aims to significantly enhance Autologos's reliability, reduce its operational "code" size (critical density), improve maintainability, and provide a robust platform for integrating current backlog items and future evolution. This document outlines the v0.1 proposal for ALang, covering its design goals, specification, core logic structure, and the redefined roles of the LLM and Orchestrator.
2. **ALang Design Goals & Principles (Reiteration):**
* Adherence to original Autologos v3.x.x functional goals.
* Reliability and Consistency.
* Critical Density / "Fewer Lines" (Compactness).
* Simplicity and Clarity (avoiding over-complication).
* Maintainability and Evolvability.
* Clear LLM-Orchestrator Contract.
3. **ALang v0.1 Specification Overview:**
* **3.1. Syntax:**
* S-Expression based: `(OPERATOR operand1 operand2 ...)`
* Literals:
* Strings: `"..."` (standard escapes for `\"`, `\\`, `\n`, etc.)
* Numbers: Integers (`123`), Floats (`1.23`)
* Booleans: `TRUE`, `FALSE`
* Symbols/Keywords: Unquoted alphanumeric strings, often prefixed (e.g., `ALANG_STATUS_SUCCESS`, `PHASE_IDEATION`). Case-insensitive for keywords/enums, case-sensitive for string literals and defined procedure names.
* NIL: A special symbol `NIL` representing null/empty/undefined.
* Comments: `;` to end of line.
* **3.2. Core Data Types:**
* Primitive Types: `String`, `Number` (Integer/Float), `Boolean`, `Symbol`, `NIL`.
* Structured System Types (orchestrator-managed):
* `StatusObject`: `{status_code: ALANG_STATUS_SUCCESS, message: "Optional message", data_handle: handle_if_any}`. Primitives might return this.
* `ErrorObject`: `{error_level: "CRITICAL_TOOL_ERROR", message: "...", internal_code: "..."}`. Stored in `sys.error_...`.
* `Handle`: Opaque identifier managed by orchestrator, points to data (file, memory object, tool result).
* `ALangProcedureDefinition`: The structure representing a defined ALang procedure (name, params, body).
* `LoopContextObject`: (for `session.loop_stack`) `{type: "FOR_EACH", list_handle: ..., current_index: ..., iteration_var_name: ...}`.
* **3.3. State Variable Dictionary (Summary):**
* `sys.*` (System-wide): `sys.alang_core_logic_version`, `sys.current_mode`, `sys.error_level`, `sys.evolution_backlog_handle`, `sys.knowledge_base_handle`.
* `proj.*` (Project-specific): `proj.id`, `proj.title`, `proj.master_plan_handle`, `proj.current_phase_id`, `proj.status_definition_of_done`, `proj.tau_project_log`, `proj.artifacts`, `proj.user_defined_principles`.
* `session.*` (Session-specific): `session.user_id_handle`, `session.thread_id_handle`, `session.last_user_input_raw`, `session.parsed_command_details`, `session.pending_user_action`, `session.active_tool_id`, `session.tool_last_status`, `session.tool_last_output_handle`, `session.output_preferences`, `session.loop_stack`, `session.internal_thoughts_buffer`, `session.output_buffer`.
* **3.4. Core Primitives (Categorized Summary & Examples):**
* State Management: `SET_STATE (variable_path_string value)`, `GET_STATE (variable_path_string)`, `INIT_PROJECT_STATE (project_id project_title master_plan_handle_optional)`, `CLEAR_SESSION_STATE ()`.
* User I/O: `REQUEST_USER_INPUT (prompt_message_key_or_text expected_input_type_hint)`, `OUTPUT_TO_USER_BUFFER (message_type content_handle_or_text formatting_hints)`, `FLUSH_USER_OUTPUT_BUFFER ()`, `GET_LAST_USER_INPUT_PROCESSED ()`.
* Control Flow: `IF (condition_expression (actions...)) (OPTIONAL_ELSE (actions...))`, `LOOP_WHILE (condition_expression (actions...))`, `LOOP_FOR_COUNT (loop_var_symbol start_number end_number increment_number_optional (actions...))`, `LOOP_FOR_EACH (item_var_symbol list_handle_or_list_literal (actions...))`, `CALL_PROCEDURE (procedure_name_symbol (arg1 arg2 ...))`, `RETURN_STATUS (status_code)`.
* Tool Interaction: `IS_TOOL_ENABLED (tool_id)`, `INVOKE_TOOL_ASYNC_WITH_CALLBACKS (tool_id input_data params_map success_proc_name failure_proc_name (OPTIONAL_CONTEXT_MAP pass_through_context))`, `GET_ASYNC_JOB_STATUS (job_id)`, `GET_ASYNC_JOB_RESULT_HANDLE (job_id)`.
* Data Handling: `READ_CONTENT (handle, options)`, `GET_HANDLE_METADATA (handle, key)`, `RELEASE_HANDLE (handle)`.
* Logging & Error: `LOG_EVENT (event_type description_text (key_value_details_map_optional))`, `SET_ERROR_STATE (error_level error_message_key_or_text)`.
* Specialized/Generative: `VALIDATE_DATA (data_handle, schema_handle)`, `APPLY_QA_PROCEDURE_TO_ARTIFACT (artifact_handle, qa_procedure_name)`, `UPDATE_EVOLUTION_BACKLOG_ITEM (...)`, `SAFE_GENERATE_CONTENT (target_artifact_handle prompt_template_handle context_data_handle constraint_set_handle)`.
* *Note:* Primitives are powerful to keep ALang procedures lean. The orchestrator handles the implementation details.
* **3.5. Error Handling Convention:**
* Primitives return `ALANG_STATUS_CODE` (Symbol) to indicate success or failure.
* On failure, primitives may also set `sys.error_level` and `sys.error_message` to provide more details.
* ALang procedures check the return status and take appropriate action (e.g., retry, log error, halt execution).
* No complex `TRY/CATCH` in ALang v0.1; errors typically halt the current ALang script segment, reported by the orchestrator.
* **3.6. Asynchronous Operations Model:**
* Asynchronous operations (e.g., tool invocation) are handled via a callback mechanism.
* The `INVOKE_TOOL_ASYNC_WITH_CALLBACKS` primitive takes the names of two ALang procedures: one to be called on success and one to be called on failure.
* The orchestrator manages the asynchronous operation and invokes the appropriate callback procedure when the operation completes.
* A `pass_through_context` map allows the calling procedure to pass state information to the callback procedures.
4. **`Autologos_Core_Logic.alang` v0.1 Structure Overview:**
* The `Autologos_Core_Logic.alang` file defines the core behavior of the Autologos system using the ALang language.
* The file is structured into the following sections:
* Section 0: System Config & Metadata (ALang Spec Version, Core Logic Version, etc.)
* Section 1: Utility Procedures & Primitives Declarations
* Section 2: Event Handler Procedures (Top-Level Entry Points) - `OnSystemInit`, `OnUserInput`, `OnToolSuccess`, `OnToolFailure`
* Section 3: Command Dispatcher & Specific Command Handlers (`DispatchUserCommand`, `HandleStartCommand`, etc.)
* Section 4: Phase Logic Dispatcher & Specific Phase Execution Procedures (`DispatchPhaseExecution`, `ExecutePhaseIdeaFormulation`, etc.)
* Section 5: QA Procedures
* Section 6: Backlog Feature Procedures (PKA, Pattern Analysis, etc.)
* Section 7: Core Generative Logic (`SAFE_GENERATE_CONTENT` and its helpers/sub-procedures)
* Example (Snippet from `OnUserInput`):
```scheme
(DEFINE_PROCEDURE OnUserInput (raw_text)
(LOG_EVENT "USER_INPUT_RECEIVED" raw_text)
(SET_STATE session.last_user_input_raw raw_text)
(LET ((parsedCmdResult (CALL_PROCEDURE ParseUserCommand raw_text)))
(IF (EQ (GET_RESULT_STATUS parsedCmdResult) ALANG_STATUS_SUCCESS)
(LET ((cmdDetails (GET_RESULT_DATA parsedCmdResult)))
(SET_STATE session.parsed_command_details cmdDetails)
(CALL_PROCEDURE DispatchUserCommand cmdDetails)
)
(CALL_PROCEDURE OutputErrorToUser (GET_STATE sys.error_message))
)
)
(FLUSH_USER_OUTPUT_BUFFER)
)
```
5. **LLM & Orchestrator Roles in ALang Execution (Clarified Contract):**
* **LLM:**
* Natural Language Understanding (parsing user input via `ParseUserCommand`).
* High-level decision making (choosing which ALang procedures to call based on state and intent).
* Core content generation (within `SAFE_GENERATE_CONTENT`'s invocation of `INVOKE_CORE_LLM_GENERATION`).
* Complex analytical tasks (within specific primitives like `FindSimilarBacklogItem`).
* **Orchestrator:**
* ALang parser and execution engine (manages call stack, variable scopes).
* Implementation of all ALang primitives.
* State management.
* Tool integration and async event management (callbacks).
* Interface with user (actual text in/out).
* File system access.
* Timestamp generation (via trusted system clock).
* Unique ID generation.
* Data validation.
* Enforcing constraints.
* **Key Principles:** Trust but Verify, Explicit Control Flow, Limited LLM Scope, Orchestrator as the Source of Truth, Clear Error Handling.
6. **Integration of Key Evolution Backlog Items (Summary of Approach):**
* **EB001 (Pattern-Centric Processing):** ALang procedures for pattern identification, abstraction, and reasoning, integrated into `SAFE_GENERATE_CONTENT` and other relevant workflows.
* **EB002 (Persistent Knowledge Artifacts):** ALang primitives for PKA management (creation, consent, storage, query, retrieval), enabling the system to learn and reuse knowledge across projects.
* **EB003 (Meta-Cognitive QA):** ALang procedures representing "simulated critics" and primitives for assessing output uncertainty, integrated into the `SAFE_GENERATE_CONTENT` pipeline to improve the quality and reliability of generated content.
* **EB004 (Pre-DOI References):** A `VALIDATE_REFERENCE` ALang procedure that implements a policy for handling academic references without DOIs.
7. **Addressing Critical Risks (Recap):**
* **Hallucination and Factual Inaccuracy:** Mitigated by structured prompts, context injection, validation steps, and the orchestrator's role in providing trusted data sources.
* **Instruction Non-Adherence:** Mitigated by the formal ALang structure, which limits the LLM's "degrees of freedom" and enforces adherence to core principles.
* **Prompt Injection and Security Vulnerabilities:** Mitigated by careful input validation and sanitization, and by limiting the LLM's access to sensitive data or system resources.
* **Bootstrapping Problem (Reliable Self-Generation of ALang):** Addressed by the CDGIP (adapted for ALang), which provides a multi-layered approach to verifying the integrity of the generated `.alang` file, including user verification and potential checksum validation.
8. **Next Steps & Future Evolution:**
* Prototype orchestrator implementation.
* LLM prompt engineering and fine-tuning (if needed).
* Systematic translation of all v3.6.3 logic into ALang.
* Comprehensive testing and validation.
* Iterative refinement of ALang specification & implementation.
* Future ALang versions: Stronger typing, local variable scopes, more advanced control flow, richer primitive set, formal verification.
This ALang v0.1 proposal provides a solid foundation for building a more robust, reliable, and evolvable Autologos system. By following these next steps and by continuously applying the principles of simplicity, critical density, and goal adherence, we can create a system that truly harnesses the power of LLMs while mitigating their inherent risks.
AI_PRESENT_THOUGHTS:
I have now completed the draft of the ALang v0.1 Proposal Summary. This represents a comprehensive overview of the design decisions, the key components of ALang, and how it addresses the core challenges of building a reliable and trustworthy Autologos system.
This is the "final product" of this design phase, as requested.
I am now ready to present this full summary. Please indicate if you would like me to proceed with outputting the complete `ALang v0.1 Proposal Summary`. Given its length, it will likely require multiple parts.