优化提示词及没有工具调用闭合标签

This commit is contained in:
Vertex-AI-Step-Builder
2025-12-31 14:20:20 +00:00
parent 6bcdbc2560
commit cecfc74a96
2 changed files with 76 additions and 6 deletions

View File

@@ -117,17 +117,33 @@ def inject_tools_into_prompt(messages: List[ChatMessage], tools: List[Tool]) ->
tool_prompt = f"""
You are a helpful assistant with access to a set of tools.
You can call them by emitting a JSON object inside tool call tags.
IMPORTANT: Use the following format for tool calls:
Format: {TOOL_CALL_START_TAG}{{"name": "tool_name", "arguments": {{...}}}}{TOOL_CALL_END_TAG}
## TOOL CALL FORMAT (CRITICAL)
Example: {full_example}
When you need to use a tool, you MUST follow this EXACT format:
Here are the available tools:
{TOOL_CALL_START_TAG}{{"name": "tool_name", "arguments": {{...}}}}{TOOL_CALL_END_TAG}
### IMPORTANT RULES:
1. ALWAYS include BOTH the opening tag ({TOOL_CALL_START_TAG}) AND closing tag ({TOOL_CALL_END_TAG})
2. The JSON must be valid and properly formatted
3. Keep arguments concise to avoid truncation
4. Do not include any text between the tags except the JSON
### Examples:
Simple call:
{full_example}
Multiple arguments:
{TOOL_CALL_START_TAG}{{"name": "search", "arguments": {{"query": "example", "limit": 5}}}}{TOOL_CALL_END_TAG}
## AVAILABLE TOOLS:
{tool_defs}
Only use the tools if strictly necessary.
## REMEMBER:
- If you decide to call a tool, output ONLY the tool call tags (you may add brief text before or after)
- ALWAYS close your tags properly with {TOOL_CALL_END_TAG}
- Keep your arguments concise and essential
"""
# Prepend the system prompt with tool definitions
return [ChatMessage(role="system", content=tool_prompt)] + messages