Skip to content

Commit 7ecac60

Browse files
author
Chris Warren-Smith
committed
LLAMA: fix nitro tool handling
1 parent 4737d15 commit 7ecac60

1 file changed

Lines changed: 10 additions & 10 deletions

File tree

llama/nitro.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1446,8 +1446,8 @@ bool AgentState::run_turn(const std::string &user_message,
14461446
tui.set_thinking(false);
14471447
std::string buffer;
14481448

1449-
auto invoke_tool = [&](const std::string &buffer, const std::string_view template_str) -> void {
1450-
std::string result = process_tool(buffer, cfg, tui);
1449+
auto invoke_tool = [&](const std::string &tool, const std::string_view template_str) -> void {
1450+
std::string result = process_tool(tool, cfg, tui);
14511451
std::string content = std::vformat(template_str, std::make_format_args(result));
14521452
if (!llama->add_message(*iter, "tool_result", content)) {
14531453
tui.append_line(std::string("[err] tool result inject: ") + llama->last_error());
@@ -1486,7 +1486,6 @@ bool AgentState::run_turn(const std::string &user_message,
14861486
while (iter->_has_next) {
14871487
std::string tok = llama->next(*iter);
14881488
buffer += tok;
1489-
14901489
if (think_mode == t_init) {
14911490
start_think("<think>");
14921491
start_think("<|think|>");
@@ -1502,16 +1501,16 @@ bool AgentState::run_turn(const std::string &user_message,
15021501
}
15031502
if (think_mode == t_thunk) {
15041503
auto tool_start = buffer.find("TOOL:");
1505-
if (tool_start != std::string::npos) {
1504+
if (tool_start == 0) {
15061505
// fetch all remaining tokens
15071506
invoke_tool(buffer + llama->all(*iter), "TOOL_RESULT: {}");
15081507
buffer.clear();
15091508
think_mode = t_init;
15101509
continue;
15111510
}
15121511
auto pos = buffer.find('\n');
1513-
if (pos != std::string::npos && pos > 0) {
1514-
tui.append_token(buffer.substr(0, pos) + "\n");
1512+
if (pos != std::string::npos) {
1513+
tui.append_token(buffer.substr(0, pos + 1));
15151514
buffer = buffer.substr(pos + 1);
15161515
}
15171516
}
@@ -1945,6 +1944,7 @@ static std::string build_system_prompt(const std::vector<std::string> &knowledge
19451944
" TOOL:CURL <url> HTTP GET; returns response body (max 32 KB)\n\n"
19461945
"Rules:\n"
19471946
"- Never access files outside the sandbox.\n"
1947+
"- Only use one TOOL at a time. Never combine, always use each tool step by step\n"
19481948
"- Use TOOL:PERMISSION before destructive or irreversible operations.\n"
19491949
"- Use TOOL:CURL to fetch documentation, APIs, or web content you need.\n"
19501950
"- Reason step-by-step inside <|think|> </|think|> (hidden from user).\n"
@@ -2200,13 +2200,16 @@ int main(int argc, char **argv) {
22002200
cfg.embed_path = resolve_path(take_next(a.c_str()));
22012201
} else if (a == "-g" || a == "--gpu-layers") {
22022202
cfg.n_gpu_layers = std::stoi(take_next(a.c_str()));
2203+
} else if (a == "-l" || a == "--log") {
2204+
log_open();
22032205
} else if (a == "-h" || a == "--help") {
22042206
std::puts("Usage: nitro [options] [project_dir]\n"
22052207
"\n"
22062208
"Options:\n"
22072209
" -m, --model <path> GGUF model to load on startup\n"
22082210
" -e, --embed <path> embedding model for RAG\n"
22092211
" -g, --gpu-layers <n> GPU layers to offload (default: 32)\n"
2212+
" -l, --log enabled logging\n"
22102213
" -h, --help show this help\n"
22112214
"\n"
22122215
"project_dir defaults to the current working directory.\n"
@@ -2271,8 +2274,6 @@ int main(int argc, char **argv) {
22712274
tui.redraw_all();
22722275
}
22732276

2274-
// log_open();
2275-
22762277
// ── Main loop ─────────────────────────────────────────────────────
22772278
for (;;) {
22782279
{
@@ -2302,8 +2303,7 @@ int main(int argc, char **argv) {
23022303
}
23032304
}
23042305

2305-
// log_close();
2306-
2306+
log_close();
23072307
tui.destroy();
23082308
// Persist input history for the next session.
23092309
tui.history.save(history_path());

0 commit comments

Comments
 (0)