Integrate AI Agent Services and Chat Interface
- Added support for AI agent services, including `ConversationalAgentService`, to facilitate user interactions through a chat interface. - Implemented `ChatTUI` for a terminal-based chat experience, allowing users to send messages and receive responses from the AI agent. - Updated `EditorManager` to include options for displaying the agent chat widget and performance dashboard. - Enhanced CMake configurations to include new source files for AI services and chat interface components. This commit significantly expands the functionality of the z3ed system, paving the way for a more interactive and user-friendly experience in ROM hacking.
This commit is contained in:
52
src/cli/service/agent/conversational_agent_service.cc
Normal file
52
src/cli/service/agent/conversational_agent_service.cc
Normal file
@@ -0,0 +1,52 @@
|
||||
#include "cli/service/agent/conversational_agent_service.h"
|
||||
|
||||
#include "absl/strings/str_cat.h"
|
||||
#include "absl/strings/str_join.h"
|
||||
#include "absl/time/clock.h"
|
||||
#include "cli/service/ai/service_factory.h"
|
||||
|
||||
namespace yaze {
|
||||
namespace cli {
|
||||
namespace agent {
|
||||
|
||||
ConversationalAgentService::ConversationalAgentService() {
|
||||
ai_service_ = CreateAIService();
|
||||
}
|
||||
|
||||
absl::StatusOr<ChatMessage> ConversationalAgentService::SendMessage(
|
||||
const std::string& message) {
|
||||
// 1. Add user message to history.
|
||||
history_.push_back({ChatMessage::Sender::kUser, message, absl::Now()});
|
||||
|
||||
// 2. Get response from the AI service using the full history.
|
||||
auto response_or = ai_service_->GenerateResponse(history_);
|
||||
if (!response_or.ok()) {
|
||||
return absl::InternalError(absl::StrCat("Failed to get AI response: ",
|
||||
response_or.status().message()));
|
||||
}
|
||||
|
||||
const auto& agent_response = response_or.value();
|
||||
|
||||
// For now, combine text and commands for display.
|
||||
// In the future, the TUI/GUI will handle these differently.
|
||||
std::string response_text = agent_response.text_response;
|
||||
if (!agent_response.commands.empty()) {
|
||||
response_text += "\n\nCommands:\n" + absl::StrJoin(agent_response.commands, "\n");
|
||||
}
|
||||
|
||||
ChatMessage chat_response = {ChatMessage::Sender::kAgent, response_text,
|
||||
absl::Now()};
|
||||
|
||||
// 3. Add agent response to history.
|
||||
history_.push_back(chat_response);
|
||||
|
||||
return chat_response;
|
||||
}
|
||||
|
||||
const std::vector<ChatMessage>& ConversationalAgentService::GetHistory() const {
|
||||
return history_;
|
||||
}
|
||||
|
||||
} // namespace agent
|
||||
} // namespace cli
|
||||
} // namespace yaze
|
||||
Reference in New Issue
Block a user