MCPcopy Create free account
hub / github.com/ClickHouse/ai-sdk-cpp / test_multi_step

Function test_multi_step

examples/test_tool_integration.cpp:121–183  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

119}
120
121void test_multi_step() {
122 std::cout << "\n=== Testing Multi-Step Tool Calling ===\n";
123
124 auto client = ai::openai::create_client();
125
126 // Create tools for multi-step
127 ai::ToolSet tools = {
128 {"get_number",
129 ai::create_simple_tool(
130 "get_number", "Get a number for calculation",
131 {{"description", "string"}},
132 [](const ai::JsonValue& args,
133 const ai::ToolExecutionContext& context) -> ai::JsonValue {
134 std::string desc = args["description"].get<std::string>();
135 std::cout << "🔢 Getting number for: " << desc << std::endl;
136 return ai::JsonValue{{"number", 42}};
137 })},
138 {"calculate",
139 ai::create_simple_tool(
140 "calculate", "Perform a calculation",
141 {{"operation", "string"}, {"a", "number"}, {"b", "number"}},
142 [](const ai::JsonValue& args,
143 const ai::ToolExecutionContext& context) -> ai::JsonValue {
144 std::string op = args["operation"].get<std::string>();
145 double a = args["a"].get<double>();
146 double b = args["b"].get<double>();
147
148 std::cout << "🧮 Calculating: " << a << " " << op << " " << b
149 << std::endl;
150
151 double result = 0;
152 if (op == "add")
153 result = a + b;
154 else if (op == "multiply")
155 result = a * b;
156
157 return ai::JsonValue{{"result", result}};
158 })}};
159
160 ai::GenerateOptions options;
161 options.model = ai::openai::models::kGpt54;
162 options.prompt = "Get a number and then multiply it by 2. Show me the steps.";
163 options.tools = tools;
164 options.max_steps = 5; // Enable multi-step
165 options.max_tokens = 200;
166
167 std::cout << "Making multi-step request...\n";
168
169 auto result = client.generate_text(options);
170
171 if (result) {
172 std::cout << "✅ Multi-step request successful!\n";
173 std::cout << "Final response: " << result.text << "\n";
174 std::cout << "Total steps: " << result.steps.size() << "\n";
175 std::cout << "Total tool calls: " << result.get_all_tool_calls().size()
176 << "\n";
177 std::cout << "Total tool results: " << result.get_all_tool_results().size()
178 << "\n";

Callers 1

mainFunction · 0.85

Calls 6

create_simple_toolFunction · 0.85
get_all_tool_callsMethod · 0.80
get_all_tool_resultsMethod · 0.80
create_clientFunction · 0.50
generate_textMethod · 0.45
error_messageMethod · 0.45

Tested by

no test coverage detected