Commit 059db080 authored by Your Name's avatar Your Name

Add critical instruction to system prompt and tool tag fallback extraction

- System prompt now includes: 'CRITICAL: You must always close your reasoning with ]]> before opening any tool tags'
- Extraction logic now uses tool tags as fallback stop markers if close tag is missing
- Handles: <tool_call>, <tool>, <|tool_call|>, <|tool|>, <function=
parent 301371bf
......@@ -102,6 +102,10 @@ class AgenticTemplateManager:
"\n\nCRITICAL: You are an agent with access to tools. "
f"Use the {thought_tag} tag to reason step-by-step "
"before providing a tool call. If you have enough info, provide the final answer."
" CRITICAL: You must always close your reasoning with "
f"{thought_tag} "
"before opening any tool tags like <tool> or <tool_call>. "
"Failure to close reasoning will result in malformed output."
)
return f"{base_prompt}{agent_addon}"
......
......@@ -2313,11 +2313,31 @@ async def chat_completions(request: ChatCompletionRequest, http_request: Request
reasoning_text = ""
final_text = first_pass_result
# Define tool tags that indicate end of reasoning
tool_tags = ["<tool_call>", "<tool>", "<|tool_call|", "<|tool|", "<function="]
if close_tag and close_tag in first_pass_result:
# Split at close tag
parts = first_pass_result.split(close_tag, 1)
reasoning_text = parts[0]
final_text = parts[1] if len(parts) > 1 else ""
else:
# Try to find tool tags as fallback stop markers
earliest_tool_idx = len(first_pass_result)
earliest_tool_tag = None
for tag in tool_tags:
idx = first_pass_result.find(tag)
if idx != -1 and idx < earliest_tool_idx:
earliest_tool_idx = idx
earliest_tool_tag = tag
if earliest_tool_tag:
# Split at tool tag
if global_debug:
print(f"RAW: No close tag found, using tool tag '{earliest_tool_tag}' as fallback")
parts = first_pass_result.split(earliest_tool_tag, 1)
reasoning_text = parts[0]
final_text = earliest_tool_tag + (parts[1] if len(parts) > 1 else "")
if global_debug:
print(f"RAW: Extracted reasoning: {reasoning_text[:100]}...")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment