認知DSL YAMLインターフェースを用いたエージェント型開発

著者: Asher Bond

# Project Definition: "Hello, World!" in Every Programming Language

project:
 name: "Hello World in Every Language"
 description: "Generate, execute, and validate 'Hello, World!' programs in multiple programming languages."
 steps:
 - planning_HOF
 - code_generation_HOF
 - execution_HOF
 - validation_HOF
 - packaging_HOF

# Step 1: Planning Phase
planning_HOF:
 description: "Plan project structure and identify languages, environments, and dependencies."
 input: "user_prompt"
 process:
 - identify_languages:
 type: atomic_function
 input: "user_prompt"
 process: "select_common_programming_languages"
 output: "language_list"
 - setup_project_structure:
 type: atomic_function
 input: "language_list"
 process: "create_folder_structure"
 output: "project_structure"
 - define_environment_requirements:
 type: atomic_function
 input: "language_list"
 process: "determine_compilers_and_interpreters"
 output: "environment_requirements"
 - plan_task_sequence:
 type: atomic_function
 input: "language_list"
 process: "sequence_tasks_for_code_generation_and_validation"
 output: "task_plan"
 output: "project_plan"

# Step 2: Code Generation Phase
code_generation_HOF:
 description: "Generate 'Hello, World!' code for each language and create necessary scripts and README."
 input: "project_plan"
 process:
 - generate_code_files:
 type: atomic_function
 input: "language_list"
 process: "generate_hello_world_code_for_each_language"
 output: "code_files"
 - create_execution_scripts:
 type: atomic_function
 input: "project_structure"
 process: "generate_scripts_for_running_all_programs"
 output: "execution_scripts"
 - generate_readme:
 type: atomic_function
 input: "project_structure"
 process: "create_readme_with_instructions"
 output: "readme_file"
 output: "generated_project_files"

# Step 3: Execution Phase
execution_HOF:
 description: "Execute each 'Hello, World!' program and capture output and errors."
 input: "generated_project_files"
 process:
 - execute_code_files:
 type: atomic_function
 input: "code_files"
 process: "run_code_snippets_in_each_language_environment"
 output: "execution_results"
 - capture_outputs_and_errors:
 type: atomic_function
 input: "execution_results"
 process: "log_outputs_and_errors"
 output: "execution_logs"
 output: "initial_execution_results"

# Step 4: Validation and Continuous Improvement Phase
validation_HOF:
 description: "Validate outputs of each program, detect errors, and refine code until all outputs are correct."
 input: "initial_execution_results"
 process:
 - validate_outputs:
 type: atomic_function
 input: "execution_logs"
 process: "check_output_for_hello_world"
 output: "validation_report"
 - error_handling_and_refinement:
 type: atomic_function
 input: "validation_report"
 process: "identify_and_fix_errors"
 output: "refined_code_files"
 - reexecute_and_revalidate:
 type: atomic_function
 input: "refined_code_files"
 process: "run_refined_code_and_validate_again"
 output: "final_validation_results"
 - continuous_loop:
 type: loop
 condition: "until all programs output 'Hello, World!' correctly"
 actions:
 - validate_outputs
 - error_handling_and_refinement
 - reexecute_and_revalidate
 output: "validated_code_files"

# Step 5: Packaging Phase
packaging_HOF:
 description: "Package the validated project files into a ZIP file for download."
 input: "validated_code_files"
 process:
 - create_zip_archive:
 type: atomic_function
 input: "validated_code_files"
 process: "compress_files_into_zip"
 output: "zip_file"
 - finalize_readme:
 type: atomic_function
 input: "zip_file"
 process: "update_readme_with_final_instructions"
 output: "final_readme"
 output: "project_zip_file"

# Output to User
final_output:
 description: "Provide the user with a link to download the validated and packaged 'Hello, World!' project."
 input: "project_zip_file"
 action:
 - provide_download_link:
 type: user_action
 input: "project_zip_file"
 output: "download_link"
 output: "project_ready_for_download"

YAML表現の解説

  1. プロジェクト定義: project セクションは、複数のプログラミング言語で「Hello, World!」コードを生成、実行、検証するという全体の目標を定義します。

  2. 高階関数(HOF): プロセスの各フェーズ(計画、コード生成、実行、検証、パッケージング)は、それぞれ高階関数(HOF)として表現されます。各HOFは、特定のタスクを実行するアトミック関数を内包しています。

  3. アトミック関数: 各HOFの中で、個々のステップを担うアトミック関数が指定されます。例えば、identify_languages はプログラミング言語を選定し、generate_code_files は各言語のコードファイルを作成します。

  4. 継続的改善ループ: validation_HOF は、すべてのプログラムの検証が成功するまでタスクを再試行する継続的ループ(continuous_loop)を含みます。このループは、検証条件が満たされるまで validate_outputserror_handling_and_refinementreexecute_and_revalidate の各関数を繰り返し実行します。

  5. パッケージングと納品: 検証が成功すると、packaging_HOF はプロジェクトをZIPファイルにまとめ、ダウンロードリンクを提供します。

このYAML表現は、チャットボットのプロセスを認知DSL形式でモデル化し、各ステップがどのように定義され、実行され、望ましい成果に向けて反復的に洗練されていくかを明確にします。

Hello World In Every LanguageにおけるHOF認知型コンパイルの論理的な流れ

flowchart TB
    START(["Hello World IPO definition"]) 

    subgraph S1["Planning HOF"]
        direction TB
        P1(["Generate Language List"])
        PV1{"Languages Valid?"}
        P2(["Generate Project Structure"])
        PV2{"Structure Valid?"}
        P3(["Generate Environment Requirements"])
        PV3{"Requirements Valid?"}
        P4(["Generate Task Sequence"])
        PV4{"Task Plan Valid?"}
        POut(["project_plan"])
        
        P1 --> PV1
        PV1 -->|"No (Regenerate)"| P1
        PV1 -->|Yes| P2
        P2 --> PV2
        PV2 -->|"No (Regenerate)"| P2
        PV2 -->|Yes| P3
        P3 --> PV3
        PV3 -->|"No (Regenerate)"| P3
        PV3 -->|Yes| P4
        P4 --> PV4
        PV4 -->|"No (Regenerate)"| P4
        PV4 -->|Yes| POut
    end

    subgraph S2["Code Generation HOF"]
        direction TB
        C1(["Generate Code Files"])
        CV1{"Code Valid?"}
        C2(["Generate Execution Scripts"])
        CV2{"Scripts Valid?"}
        C3(["Generate README"])
        CV3{"README Valid?"}
        CGOut(["generated_project_files"])
        
        C1 --> CV1
        CV1 -->|"No (Regenerate)"| C1
        CV1 -->|Yes| C2
        C2 --> CV2
        CV2 -->|"No (Regenerate)"| C2
        CV2 -->|Yes| C3
        C3 --> CV3
        CV3 -->|"No (Regenerate)"| C3
        CV3 -->|Yes| CGOut
    end

    subgraph S3["Execution HOF"]
        direction TB
        E1(["Execute Programs"])
        EV1{"Execution Valid?"}
        E2(["Generate Output Logs"])
        EV2{"Logs Valid?"}
        EOut(["initial_execution_results"])
        
        E1 --> EV1
        EV1 -->|"No (Regenerate)"| E1
        EV1 -->|Yes| E2
        E2 --> EV2
        EV2 -->|"No (Regenerate)"| E2
        EV2 -->|Yes| EOut
    end

    subgraph S4["Validation HOF"]
        direction TB
        V1(["Generate Validation Tests"])
        VV1{"Tests Valid?"}
        V2(["Generate Error Fixes"])
        VV2{"Fixes Valid?"}
        V3(["Generate Revalidation"])
        V4{"All Programs Valid?"}
        VOut(["validated_code_files"])
        
        V1 --> VV1
        VV1 -->|"No (Regenerate)"| V1
        VV1 -->|Yes| V2
        V2 --> VV2
        VV2 -->|"No (Regenerate)"| V2
        VV2 -->|Yes| V3
        V3 --> V4
        V4 -->|"No (Regenerate)"| V1
        V4 -->|Yes| VOut
    end

    subgraph S5["Packaging HOF"]
        direction TB
        PK1(["Generate ZIP Archive"])
        PKV1{"Archive Valid?"}
        PK2(["Generate Final README"])
        PKV2{"README Valid?"}
        PK3(["Generate Download Link"])
        PKV3{"Link Valid?"}
        PKOut(["project_ready_for_download"])
        
        PK1 --> PKV1
        PKV1 -->|"No (Regenerate)"| PK1
        PKV1 -->|Yes| PK2
        PK2 --> PKV2
        PKV2 -->|"No (Regenerate)"| PK2
        PKV2 -->|Yes| PK3
        PK3 --> PKV3
        PKV3 -->|"No (Regenerate)"| PK3
        PKV3 -->|Yes| PKOut
    end

    START --> S1
    S1 --> S2
    S2 --> S3
    S3 --> S4
    S4 --> S5

    classDef default fill:#262d35,stroke:#6b7686,stroke-width:2px,color:#e6ebf3
    classDef decision fill:#241a30,stroke:#8a2be2,stroke-width:2px,color:#e6ebf3
    classDef step1 fill:#2a1a4a,stroke:#9400d3,stroke-width:2px,color:#fff
    classDef step2 fill:#8a6fd0,stroke:#8a2be2,stroke-width:2px,color:#fff
    classDef step3 fill:#6a3a90,stroke:#9932cc,stroke-width:2px,color:#fff
    classDef step4 fill:#3a2a4a,stroke:#84b8e2,stroke-width:2px,color:#fff
    classDef step5 fill:#4a2a4a,stroke:#da70d6,stroke-width:2px,color:#fff

    class PV1,PV2,PV3,PV4,CV1,CV2,CV3,EV1,EV2,VV1,VV2,V4,PKV1,PKV2,PKV3 decision
    class P1,P2,P3,P4,POut step1
    class C1,C2,C3,CGOut step2
    class E1,E2,EOut step3
    class V1,V2,V3,VOut step4
    class PK1,PK2,PK3,PKOut step5
    class START step1

    style S1 fill:#33265c,stroke:#9400d3,stroke-width:4px,color:#fff
    style S2 fill:#8a6fd0,stroke:#8a2be2,stroke-width:4px,color:#fff
    style S3 fill:#33265c,stroke:#9932cc,stroke-width:4px,color:#fff
    style S4 fill:#3a2a4a,stroke:#84b8e2,stroke-width:4px,color:#fff
    style S5 fill:#4a2a4a,stroke:#da70d6,stroke-width:4px,color:#fff

関連記事: