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

Function main

examples/tool_calling_multistep.cpp:124–273  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

122}
123
124int main() {
125 std::cout << "AI SDK C++ - Multi-Step Tool Calling Example\n";
126 std::cout << "=============================================\n\n";
127
128 // Create OpenAI client
129 auto client = ai::openai::create_client();
130
131 // Define tools
132 ai::ToolSet tools = {
133 {"lookup_user", ai::create_simple_tool(
134 "lookup_user", "Look up user information by user ID",
135 {{"user_id", "string"}}, lookup_user)},
136 {"get_weather", ai::create_simple_tool(
137 "get_weather", "Get current weather for a location",
138 {{"location", "string"}}, get_weather)},
139 {"send_email",
140 ai::create_simple_tool(
141 "send_email", "Send an email notification",
142 {{"to", "string"}, {"subject", "string"}, {"body", "string"}},
143 send_email)},
144 {"get_recommendations",
145 ai::create_simple_tool("get_recommendations",
146 "Get activity recommendations for a city, "
147 "optionally considering weather",
148 {{"city", "string"}, {"weather", "string"}},
149 get_recommendations)}};
150
151 // Step callback to monitor progress
152 auto step_callback = [](const ai::GenerateStep& step) {
153 std::cout << "\n--- Step Completed ---\n";
154 std::cout << "Text: " << step.text << "\n";
155 std::cout << "Tool calls: " << step.tool_calls.size() << "\n";
156 std::cout << "Tool results: " << step.tool_results.size() << "\n";
157 std::cout << "Finish reason: ";
158 switch (step.finish_reason) {
159 case ai::kFinishReasonStop:
160 std::cout << "stop";
161 break;
162 case ai::kFinishReasonLength:
163 std::cout << "length";
164 break;
165 case ai::kFinishReasonToolCalls:
166 std::cout << "tool_calls";
167 break;
168 case ai::kFinishReasonError:
169 std::cout << "error";
170 break;
171 default:
172 std::cout << "unknown";
173 break;
174 }
175 std::cout << "\n----------------------\n\n";
176 };
177
178 // Example 1: Multi-step workflow
179 std::cout << "1. Multi-Step Workflow Example:\n";
180 std::cout << "Task: Look up user 'alice', get weather for her city, get "
181 "recommendations, and send her an email\n\n";

Callers

nothing calls this directly

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