yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
conversational_agent_service.h
Go to the documentation of this file.
1#ifndef YAZE_SRC_CLI_SERVICE_AGENT_CONVERSATIONAL_AGENT_SERVICE_H_
2#define YAZE_SRC_CLI_SERVICE_AGENT_CONVERSATIONAL_AGENT_SERVICE_H_
3
4#include <filesystem>
5#include <map>
6#include <optional>
7#include <string>
8#include <vector>
9
10#include "absl/status/status.h"
11#include "absl/status/statusor.h"
12#include "absl/time/time.h"
17// Advanced features (only available when Z3ED_AI=ON)
18#ifdef Z3ED_AI
23#endif
24
25#ifdef SendMessage
26#undef SendMessage
27#endif
28
29namespace yaze {
30
31class Rom;
32
33namespace cli {
34namespace agent {
35
37 enum class Sender { kUser, kAgent };
38 struct TableData {
39 std::vector<std::string> headers;
40 std::vector<std::vector<std::string>> rows;
41 };
43 std::string id;
44 int change_count = 0;
46 std::filesystem::path sandbox_rom_path;
47 std::filesystem::path proposal_json_path;
48 };
50 std::string message;
51 absl::Time timestamp;
52 std::optional<std::string> json_pretty;
53 std::optional<TableData> table_data;
54 bool is_internal = false; // True for tool results and other messages not
55 // meant for user display
56 std::vector<std::string> warnings;
58 std::string provider;
59 std::string model;
60 double latency_seconds = 0.0;
62 std::vector<std::string> tool_names;
63 std::map<std::string, std::string> parameters;
64 };
65 std::optional<ModelMetadata> model_metadata;
76 std::optional<SessionMetrics> metrics;
77 std::optional<ProposalSummary> proposal;
78};
79
81
83 int max_tool_iterations = 4; // Maximum number of tool calling iterations
84 int max_retry_attempts = 3; // Maximum retries on errors
85 bool verbose = false; // Enable verbose diagnostic output
86 bool show_reasoning = true; // Show LLM reasoning in output
88 50; // Maximum stored history messages per session
89 bool trim_history = true; // Whether to trim history beyond the limit
90 bool enable_vim_mode = false; // Enable vim-style line editing in simple-chat
92};
93
95 public:
97 explicit ConversationalAgentService(const AgentConfig& config);
98
99 // Send a message from the user and get the agent's response.
100 absl::StatusOr<ChatMessage> SendMessage(const std::string& message);
101
102 // Get the full chat history.
103 const std::vector<ChatMessage>& GetHistory() const;
104
105 // Provide the service with a ROM context for tool execution.
106 void SetRomContext(Rom* rom);
107
108 // Clear the current conversation history, preserving ROM/tool context.
109 void ResetConversation();
110
111 // Configuration
112 void SetConfig(const AgentConfig& config) { config_ = config; }
113 const AgentConfig& GetConfig() const { return config_; }
114 absl::Status ConfigureProvider(const AIServiceConfig& config);
117
119
120 void ReplaceHistory(std::vector<ChatMessage> history);
121
122 // External Driver Support (for WASM/JS Integration)
124 std::function<void(const std::vector<ChatMessage>& history)>;
126 // Called by external driver when a response is ready
127 void HandleExternalResponse(const AgentResponse& response);
128
129#ifdef Z3ED_AI
130 // Advanced Features Access (only when Z3ED_AI=ON)
131 LearnedKnowledgeService& learned_knowledge() { return learned_knowledge_; }
132 TodoManager& todo_manager() { return todo_manager_; }
133
134 // Inject learned context into next message
135 void EnableContextInjection(bool enable) { inject_learned_context_ = enable; }
136 void EnablePretraining(bool enable) { inject_pretraining_ = enable; }
137#endif
138
139 private:
143 int tool_calls = 0;
147 absl::Duration total_latency = absl::ZeroDuration();
148 };
149
150 void TrimHistoryIfNeeded();
153
154#ifdef Z3ED_AI
155 // Context enhancement (only when Z3ED_AI=ON)
156 std::string BuildEnhancedPrompt(const std::string& user_message);
157 std::string InjectLearnedContext(const std::string& message);
158 std::string InjectPretraining();
159
160 // Response enhancement
161 ChatMessage EnhanceResponse(const ChatMessage& response,
162 const std::string& user_message);
163#endif
164
165 std::vector<ChatMessage> history_;
166 std::unique_ptr<AIService> ai_service_;
170 Rom* rom_context_ = nullptr;
173
174 // External driver state
177
178#ifdef Z3ED_AI
179 // Advanced features (only when Z3ED_AI=ON)
180 LearnedKnowledgeService learned_knowledge_;
181 TodoManager todo_manager_;
182 bool inject_learned_context_ = true;
183 bool inject_pretraining_ = false; // One-time injection on first message
184 bool pretraining_injected_ = false;
185#endif
186};
187
188} // namespace agent
189} // namespace cli
190} // namespace yaze
191
192#endif // YAZE_SRC_CLI_SERVICE_AGENT_CONVERSATIONAL_AGENT_SERVICE_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
absl::StatusOr< ChatMessage > SendMessage(const std::string &message)
absl::Status ConfigureProvider(const AIServiceConfig &config)
void SetToolPreferences(const ToolDispatcher::ToolPreferences &prefs)
const std::vector< ChatMessage > & GetHistory() const
void HandleExternalResponse(const AgentResponse &response)
std::function< void(const std::vector< ChatMessage > &history)> ExternalDriverCallback
void ReplaceHistory(std::vector< ChatMessage > history)
Manages persistent learned information across agent sessions.
Manages TODO lists for z3ed agent task execution.
std::vector< std::vector< std::string > > rows
std::optional< ModelMetadata > model_metadata
std::optional< std::string > json_pretty
std::optional< ProposalSummary > proposal
std::optional< SessionMetrics > metrics