@@ -33,7 +33,7 @@ void detailedStepCallback(const AutonomousAgent::Step& step) {
3333}
3434
3535// Custom callback for human-in-the-loop
36- bool detailedHumanApproval (const String & message, const JsonObject& context, String & modifications) {
36+ bool detailedHumanApproval (const std::string & message, const JsonObject& context, std::string & modifications) {
3737 if (!context.empty ()) {
3838 Logger::info (" \n Context Information:" );
3939 Logger::info (" {}" , context.dump (2 ));
@@ -48,7 +48,7 @@ bool detailedHumanApproval(const String& message, const JsonObject& context, Str
4848
4949 if (response == ' m' || response == ' M' ) {
5050 Logger::info (" Enter your modifications or instructions: " );
51- String user_modifications;
51+ std::string user_modifications;
5252 std::getline (std::cin, user_modifications);
5353
5454 // Set modifications output parameter
@@ -79,33 +79,20 @@ int main() {
7979 auto & config = ConfigLoader::getInstance ();
8080
8181 // Proceed based on provider choice and API key in the environment
82- if (provider_choice == 1 ) {
83- bool hasOpenAI = config.has (" OPENAI_API_KEY" );
84- if (hasOpenAI) {
85- llm = createLLM (" openai" , config.get (" OPENAI_API_KEY" ), " gpt-4o-2024-05-13" );
82+ try {
83+ if (provider_choice == 1 ) {
84+ llm = createLLM (" openai" , config.get (" OPENAI_API_KEY" ), " gpt-4o" );
85+ } else if (provider_choice == 2 ) {
86+ llm = createLLM (" anthropic" , config.get (" ANTHROPIC_API_KEY" ), " claude-sonnet-4-5" );
87+ } else if (provider_choice == 3 ) {
88+ llm = createLLM (" google" , config.get (" GEMINI_API_KEY" ), " gemini-2.5-flash" );
8689 } else {
87- Logger::error (" OPENAI_API_KEY not found in environment ." );
90+ Logger::error (" Invalid provider choice ." );
8891 return EXIT_FAILURE;
8992 }
90- } else if (provider_choice == 2 ) {
91- // Note: This assumes the user has the Anthropic API key in the environment
92- bool hasAnthropic = config.has (" ANTHROPIC_API_KEY" );
93- if (hasAnthropic) {
94- llm = createLLM (" anthropic" , config.get (" ANTHROPIC_API_KEY" ), " claude-3-5-sonnet-20240620" );
95- } else {
96- Logger::error (" ANTHROPIC_API_KEY not found in environment." );
97- return EXIT_FAILURE;
98- }
99- } else if (provider_choice == 3 ) {
100- bool hasGoogle = config.has (" GEMINI_API_KEY" );
101- if (hasGoogle) {
102- llm = createLLM (" google" , config.get (" GEMINI_API_KEY" ), " gemini-2.0-flash" );
103- } else {
104- Logger::error (" GEMINI_API_KEY not found in environment." );
105- return EXIT_FAILURE;
106- }
107- } else {
108- Logger::error (" Invalid provider choice." );
93+ } catch (const std::exception& e) {
94+ Logger::error (" Error creating LLM: {}" , e.what ());
95+ Logger::error (" Please ensure the appropriate API key is set in the environment." );
10996 return EXIT_FAILURE;
11097 }
11198
@@ -121,17 +108,15 @@ int main() {
121108
122109 // Set system prompt for the context
123110 context->setSystemPrompt (
124- " You are a helpful, autonomous assistant with access to tools."
125- " You can use these tools to accomplish tasks for the user."
111+ " You are a helpful, autonomous assistant with access to tools. "
112+ " You can use these tools to accomplish tasks for the user. "
126113 " Think step by step and be thorough in your approach."
127114 );
128115
129- // Register tools
130- context->registerTool (tools::createWebSearchTool ());
131- context->registerTool (tools::createWikipediaTool ());
132- // Uncomment when tools are implemented
133- // context->registerTool(tools::createWeatherTool());
134- // context->registerTool(tools::createCalculatorTool());
116+ // Register tools from tool registry
117+ auto registry = tools::ToolRegistry::global ();
118+ tools::registerStandardTools (registry, llm);
119+ context->registerToolRegistry (registry);
135120
136121 // Create a custom tool
137122 auto summarize_tool = createTool (
@@ -142,7 +127,7 @@ int main() {
142127 {" max_length" , " Maximum length of summary in words" , " integer" , false }
143128 },
144129 [context](const JsonObject& params) -> ToolResult {
145- String text = params[" text" ];
130+ std::string text = params[" text" ];
146131 int max_length = params.contains (" max_length" ) ? params[" max_length" ].get <int >() : 100 ;
147132
148133 // Create a specific context for summarization
@@ -152,11 +137,11 @@ int main() {
152137 " that capture the main points of the provided text."
153138 );
154139
155- String prompt = " Summarize the following text in no more than " +
140+ std::string prompt = " Summarize the following text in no more than " +
156141 std::to_string (max_length) + " words:\n\n " + text;
157142
158143 LLMResponse llm_response = summary_context->getLLM ()->chat (prompt);
159- String summary = llm_response.content ;
144+ std::string summary = llm_response.content ;
160145
161146 return ToolResult{
162147 true ,
@@ -182,12 +167,15 @@ int main() {
182167 // Set planning strategy based on user choice
183168 AutonomousAgent::PlanningStrategy strategy;
184169 switch (strategy_choice) {
170+ case 1 :
171+ strategy = AutonomousAgent::PlanningStrategy::REACT;
172+ break ;
185173 case 2 :
186174 strategy = AutonomousAgent::PlanningStrategy::PLAN_AND_EXECUTE;
187175 break ;
188- case 1 :
189176 default :
190- strategy = AutonomousAgent::PlanningStrategy::REACT;
177+ Logger::error (" Invalid strategy choice." );
178+ return EXIT_FAILURE;
191179 }
192180 agent.setPlanningStrategy (strategy);
193181
@@ -228,7 +216,7 @@ int main() {
228216 Logger::info (" ==================================================" );
229217 Logger::info (" Enter a question or task for the agent (or 'exit' to quit):" );
230218
231- String user_input;
219+ std::string user_input;
232220 while (true ) {
233221 Logger::info (" \n > " );
234222 std::getline (std::cin, user_input);
@@ -256,7 +244,7 @@ int main() {
256244 Logger::info (" \n ==================================================" );
257245 Logger::info (" FINAL RESULT " );
258246 Logger::info (" ==================================================" );
259- Logger::info (" {}" , result[" answer" ].get <String >());
247+ Logger::info (" {}" , result[" answer" ].get <std::string >());
260248
261249 // Display completion statistics
262250 Logger::info (" \n --------------------------------------------------" );
@@ -274,4 +262,4 @@ int main() {
274262 }
275263
276264 return EXIT_SUCCESS;
277- }
265+ }
0 commit comments