#include "google/optimize/simulated_user.h" #include "google/optimize/caps.h" namespace molo::google::optimize { using clients::body::Json; SimulatedUser::SimulatedUser(std::shared_ptr model, std::string model_name) : model_(std::move(model), std::move(model_name)) {} std::optional SimulatedUser::next(const Scenario& scenario, const std::vector& history) const { Conversation c; c.turns = history; std::string system = "You play a human user talking to an AI agent. Follow your hidden plan, " "react naturally to what the agent said, and keep each message short. " "When the plan is complete or cannot progress, finish. Reply with one " "JSON object: {\"done\":true|false,\"message\":\"\"}.\n" "Hidden plan: " + scenario.plan; Json reply = model_.ask(system, "Conversation so far:\n" + c.transcript()); const Json* done = reply.find("done"); if (done && done->is_bool() && done->as_bool()) return std::nullopt; const Json* msg = reply.find("message"); if (!msg || !msg->is_string() || msg->as_string().empty()) return std::nullopt; std::string text = msg->as_string(); if (text.size() > OptimizeCaps::kMaxTextChars) text.resize(OptimizeCaps::kMaxTextChars); return text; } } // namespace molo::google::optimize