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