yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
prompt_builder.h
Go to the documentation of this file.
1#ifndef YAZE_CLI_SERVICE_PROMPT_BUILDER_H_
2#define YAZE_CLI_SERVICE_PROMPT_BUILDER_H_
3
4// PromptBuilder requires JSON and YAML support for catalogue loading
5// If you see linker errors, enable Z3ED_AI or YAZE_WITH_JSON in CMake
6#if !defined(YAZE_WITH_JSON)
7#ifdef _MSC_VER
8 #pragma message("PromptBuilder requires JSON support. Build with -DZ3ED_AI=ON or -DYAZE_WITH_JSON=ON")
9#else
10 #warning "PromptBuilder requires JSON support. Build with -DZ3ED_AI=ON or -DYAZE_WITH_JSON=ON"
11#endif
12#endif
13
14#include <map>
15#include <string>
16#include <vector>
17
18#include "absl/status/status.h"
19#include "absl/status/statusor.h"
20#include "nlohmann/json_fwd.hpp"
23#include "app/rom.h"
24
25namespace yaze {
26namespace cli {
27
28namespace agent {
29struct ChatMessage;
30}
31
32// Few-shot example for prompt engineering
34 std::string user_prompt;
35 std::string text_response;
36 std::vector<std::string> expected_commands;
37 std::string explanation; // Why these commands work
38 std::vector<ToolCall> tool_calls;
39};
40
42 std::string name;
43 std::string description;
44 bool required = false;
45 std::string example;
46};
47
49 std::string name;
50 std::string description;
51 std::vector<ToolArgument> arguments;
52 std::string usage_notes;
53};
54
55// ROM context information to inject into prompts
56struct RomContext {
57 std::string rom_path;
58 bool rom_loaded = false;
59 std::string current_editor; // "overworld", "dungeon", "sprite", etc.
60 std::map<std::string, std::string> editor_state; // Context-specific state
61};
62
63// Builds sophisticated prompts for LLM services
65 public:
67
68 void SetRom(Rom* rom) { rom_ = rom; }
69
70 // Load z3ed command documentation from resources
71 absl::Status LoadResourceCatalogue(const std::string& yaml_path);
72
73 // Build system instruction with full command reference
74 std::string BuildSystemInstruction();
75
76 // Build system instruction with few-shot examples
78
79 // Build user prompt with ROM context
80 std::string BuildContextualPrompt(
81 const std::string& user_prompt,
82 const RomContext& context);
83
84 // Build a full prompt from a conversation history
85 std::string BuildPromptFromHistory(
86 const std::vector<agent::ChatMessage>& history);
87
88 // Add custom few-shot examples
89 void AddFewShotExample(const FewShotExample& example);
90
91 // Get few-shot examples for specific category
92 std::vector<FewShotExample> GetExamplesForCategory(
93 const std::string& category);
94 std::string LookupTileId(const std::string& alias) const;
95 const std::map<std::string, std::string>& tile_reference() const {
96 return tile_reference_;
97 }
98
99 // Generate OpenAI-compatible function call schemas (JSON format)
100 std::string BuildFunctionCallSchemas() const;
101
102 // Set verbosity level (0=minimal, 1=standard, 2=verbose)
103 void SetVerbosity(int level) { verbosity_ = level; }
104
105 private:
106 std::string BuildCommandReference() const;
107 std::string BuildFewShotExamplesSection() const;
108 std::string BuildToolReference() const;
109 std::string BuildContextSection(const RomContext& context);
110 std::string BuildConstraintsSection() const;
111 std::string BuildTileReferenceSection() const;
112 absl::StatusOr<std::string> ResolveCataloguePath(const std::string& yaml_path) const;
113 void ClearCatalogData();
114 absl::Status ParseCommands(const nlohmann::json& commands);
115 absl::Status ParseTools(const nlohmann::json& tools);
116 absl::Status ParseExamples(const nlohmann::json& examples);
117 void ParseTileReference(const nlohmann::json& tile_reference);
118
119 Rom* rom_ = nullptr;
120 std::unique_ptr<ResourceContextBuilder> resource_context_builder_;
121 std::map<std::string, std::string> command_docs_; // Command name -> docs
122 std::vector<FewShotExample> examples_;
123 std::vector<ToolSpecification> tool_specs_;
124 std::map<std::string, std::string> tile_reference_;
125 int verbosity_ = 1;
126 bool catalogue_loaded_ = false;
127};
128
129} // namespace cli
130} // namespace yaze
131
132#endif // YAZE_CLI_SERVICE_PROMPT_BUILDER_H_
The Rom class is used to load, save, and modify Rom data.
Definition rom.h:71
std::string BuildContextualPrompt(const std::string &user_prompt, const RomContext &context)
std::vector< FewShotExample > examples_
std::map< std::string, std::string > command_docs_
absl::Status ParseTools(const nlohmann::json &tools)
std::map< std::string, std::string > tile_reference_
std::unique_ptr< ResourceContextBuilder > resource_context_builder_
const std::map< std::string, std::string > & tile_reference() const
std::string BuildConstraintsSection() const
std::string BuildTileReferenceSection() const
void AddFewShotExample(const FewShotExample &example)
std::string BuildFunctionCallSchemas() const
std::string BuildSystemInstructionWithExamples()
std::string BuildPromptFromHistory(const std::vector< agent::ChatMessage > &history)
std::string BuildToolReference() const
std::string BuildContextSection(const RomContext &context)
void SetVerbosity(int level)
void ParseTileReference(const nlohmann::json &tile_reference)
std::string BuildSystemInstruction()
std::string LookupTileId(const std::string &alias) const
absl::Status ParseExamples(const nlohmann::json &examples)
std::string BuildFewShotExamplesSection() const
std::vector< ToolSpecification > tool_specs_
std::string BuildCommandReference() const
absl::StatusOr< std::string > ResolveCataloguePath(const std::string &yaml_path) const
absl::Status LoadResourceCatalogue(const std::string &yaml_path)
absl::Status ParseCommands(const nlohmann::json &commands)
std::vector< FewShotExample > GetExamplesForCategory(const std::string &category)
Main namespace for the application.
std::vector< ToolCall > tool_calls
std::vector< std::string > expected_commands
std::map< std::string, std::string > editor_state
std::vector< ToolArgument > arguments