Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion libs/app/src/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,11 @@ void Application::init_pipeline() {
auto primary = exe_dir / "pipelines";
if (!exe_dir.empty() && std::filesystem::exists(primary))
return primary;
return exe_dir / ".." / "config" / "pipelines";
// From build/cli/ or $PREFIX/bin/: try ../config/pipelines first,
// then ../../config/pipelines (project-root layout during dev).
auto fallback1 = exe_dir / ".." / "config" / "pipelines";
if (std::filesystem::exists(fallback1)) return fallback1;
return exe_dir / ".." / ".." / "config" / "pipelines";
}(),
.worlds_base_dir = options_.home_dir / "worldbuilding",
.condition_evaluator = condition_evaluator,
Expand Down
13 changes: 9 additions & 4 deletions libs/llm/src/anthropic_provider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ nlohmann::json AnthropicProvider::build_request_body(const ChatRequest& request)
nlohmann::json item;
item["role"] = m.role;

// assistant 消息可能包含 tool_use content blocks
if (m.role == "assistant" && !m.tool_calls.empty()) {
// assistant 消息可能包含 thinking / tool_use content blocks
if (m.role == "assistant" &&
(!m.tool_calls.empty() || !m.provider_content_blocks_json.empty())) {
nlohmann::json content_arr = nlohmann::json::array();
if (!m.provider_content_blocks_json.empty()) {
auto preserved_blocks = nlohmann::json::parse(
Expand Down Expand Up @@ -134,6 +135,7 @@ std::future<AgentResponse> AnthropicProvider::chat(

// SSE 累积状态
std::string response_text;
std::string error_body; // raw response captured for error diagnostics
int input_tokens = 0, output_tokens = 0;
int cache_read_tokens = 0, cache_write_tokens = 0;
bool has_usage = false;
Expand Down Expand Up @@ -237,6 +239,7 @@ std::future<AgentResponse> AnthropicProvider::chat(
};

auto write_callback = [&](const std::string& data) {
error_body += data;
line_buffer += data;
size_t newline = 0;
while ((newline = line_buffer.find('\n')) != std::string::npos) {
Expand Down Expand Up @@ -267,6 +270,7 @@ std::future<AgentResponse> AnthropicProvider::chat(

for (int attempt = 0; attempt <= retry.max_retries; attempt++) {
response_text.clear();
error_body.clear();
input_tokens = 0;
output_tokens = 0;
has_usage = false;
Expand Down Expand Up @@ -341,8 +345,9 @@ std::future<AgentResponse> AnthropicProvider::chat(

// Not retryable: other 4xx
if (http_code >= 400 && http_code < 500 && http_code != 429) {
spdlog::error("Anthropic API error body: {}", error_body);
throw AgentError(ErrorType::LLM_ERROR,
"LLM API error (HTTP " + std::to_string(http_code) + ")");
"LLM API error (HTTP " + std::to_string(http_code) + "): " + error_body);
}

// Exhausted retries
Expand All @@ -351,7 +356,7 @@ std::future<AgentResponse> AnthropicProvider::chat(
throw AgentError(ErrorType::LLM_ERROR, curl_easy_strerror(res));
}
throw AgentError(ErrorType::LLM_ERROR,
"LLM API error after retries (HTTP " + std::to_string(http_code) + ")");
"LLM API error after retries (HTTP " + std::to_string(http_code) + "): " + error_body);
}

// Backoff and retry
Expand Down
2 changes: 1 addition & 1 deletion libs/storage/include/merak/session_store.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class SessionStore {
private:
std::shared_ptr<pqxx::connection> conn_;
std::filesystem::path root_;
mutable std::mutex mutex_;
mutable std::recursive_mutex mutex_;
mutable std::mutex plan_mutex_;
std::string plan_text_;
void exec(const std::string& sql);
Expand Down
Loading
Loading