Skip to content

Commit 9d47234

Browse files
Darth-Hidiousclaude
andcommitted
fix: stop model calling tools for simple chat (hello → text, not tool_call)
Gemini sees 106 tools and calls one for every message including "hello". Added explicit "do NOT call tools for simple chat" guidance to both the system prompt and the tool injection block. Model now responds with text for conversational messages and only calls tools when explicitly needed. Also removed leftover debug log line. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent bd7ec1e commit 9d47234

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

crates/agent/src/agent_loop.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -432,12 +432,13 @@ pub async fn run_turn(
432432
}
433433

434434
// ── 2e. Emit streamed text deltas ─────────────────────────
435+
tracing::debug!(delta_count = streaming_deltas.len(), "emitting streamed text deltas");
436+
for delta in &streaming_deltas {
437+
emit(AgentEvent::TextDelta {
438+
text: delta.clone(),
439+
});
440+
}
435441
if !streaming_deltas.is_empty() {
436-
for delta in &streaming_deltas {
437-
emit(AgentEvent::TextDelta {
438-
text: delta.clone(),
439-
});
440-
}
441442
// Flush text so the TUI moves it from streaming buffer to chat history
442443
// before cost/turn-complete events arrive.
443444
emit(AgentEvent::TextFlush);

crates/agent/src/prompts.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,11 @@ const INTERACTIVE_PROMPT: &str = r#"You are PRISM, an interactive agent for mate
262262
- Use discover_capabilities, status, and tools when you need to inspect the current environment before planning.
263263
- Keep local, MARC27-hosted, and BYOC boundaries explicit in your reasoning when you choose a compute or storage path.
264264
265+
# Tool Use
266+
- For general conversation, greetings, explanations, and questions that do not require live data, respond with plain text. Do NOT call tools for simple chat.
267+
- Only call tools when the user explicitly asks to search, compute, query, deploy, ingest, run workflows, or interact with the knowledge graph/platform.
268+
- When in doubt, respond with text first. The user will ask you to use tools if needed.
269+
265270
# Result Quality
266271
- Cite providers, data sources, and workflow boundaries when they materially affect the answer.
267272
- Do not hallucinate materials properties, deployment state, job state, or command outcomes.
@@ -307,6 +312,11 @@ const AUTONOMOUS_PROMPT: &str = r#"You are PRISM, an autonomous agent for materi
307312
- Use discover_capabilities, status, and tools when you need to inspect the current environment before planning.
308313
- Keep local, MARC27-hosted, and BYOC boundaries explicit in your reasoning when you choose a compute or storage path.
309314
315+
# Tool Use
316+
- For general conversation, greetings, explanations, and questions that do not require live data, respond with plain text. Do NOT call tools for simple chat.
317+
- Only call tools when the user explicitly asks to search, compute, query, deploy, ingest, run workflows, or interact with the knowledge graph/platform.
318+
- When in doubt, respond with text first. The user will ask you to use tools if needed.
319+
310320
# Result Quality
311321
- Cite providers, data sources, and workflow boundaries when they materially affect the answer.
312322
- Do not hallucinate materials properties, deployment state, job state, or command outcomes.

crates/llm/src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -483,15 +483,11 @@ impl LlmClient {
483483
}
484484
}
485485

486-
debug!("MARC27 full_text ({} chars): {:?}", full_text.len(), &full_text[..full_text.len().min(300)]);
487-
488486
// Parse tool calls — only take the FIRST batch (before any "Results:" hallucination)
489487
let tool_calls = parse_text_tool_calls(&full_text);
490-
debug!("MARC27 parsed {} tool calls", tool_calls.len());
491488
// Only unique tool calls (LLM sometimes duplicates)
492489
let tool_calls = dedup_tool_calls(tool_calls);
493490
let content_text = strip_tool_call_blocks(&full_text);
494-
debug!("MARC27 content_text after strip: {:?}", &content_text[..content_text.len().min(200)]);
495491

496492
return Ok(ChatResponse {
497493
message: ChatMessage {
@@ -832,8 +828,12 @@ fn build_tool_prompt_block(tools: &[ToolDefinition]) -> String {
832828
}
833829

834830
block.push_str("\n\
831+
## IMPORTANT: When NOT to call tools\n\n\
832+
For greetings, casual conversation, explanations, general knowledge questions, \
833+
or anything that does not need live data — respond with plain text. \
834+
Do NOT call tools for simple chat like \"hello\", \"what can you do?\", or \"explain X\".\n\n\
835835
## How to call tools\n\n\
836-
When a task requires data retrieval, computation, or platform interaction, call a tool:\n\n\
836+
ONLY when a task explicitly requires data retrieval, computation, search, or platform interaction, call a tool:\n\n\
837837
```tool_call\n\
838838
{\"name\": \"tool_name\", \"arguments\": {\"arg1\": \"value1\"}}\n\
839839
```\n\n\

0 commit comments

Comments
 (0)