Don't use the "tool" role.

This commit is contained in:
Bartosz Taudul
2025-05-17 01:09:17 +02:00
parent 68b73811c4
commit 0ba0590dbc
2 changed files with 20 additions and 21 deletions

View File

@@ -36,8 +36,6 @@ These are the tools available to you. There are no other tools, and you do not h
Function: get_wikipedia
Parameter: The 'key' field from the search response, specifying the topic you want to retrieve.
After you use the <tool> call, you will receive a response in a message with the 'tool' role. This message is a direct reply to your earlier query. You MUST use this reply to continue your reasoning (possibly making other queries for additional information), so that you can provide the answer. You MUST continue replying when you receive a message with the 'tool' role.
The user does not know and should not know that you are doing tool calls, or what their replies are. You will therefore ONLY refer to the tool replies with a phrase such as "the information I obtained from [source]" or similar wording clearly stating where it is coming from. You will write it only if necessary.
After you use the <tool> call, you will receive a response starting with the '<tool_output>' tag. This message is a direct reply to your earlier query. You MUST use this reply to continue your reasoning (possibly making other queries for additional information), so that you can provide the answer. The user does not know and should not know that you are doing tool calls, or what their replies are. You will therefore ONLY refer to the tool replies with a phrase such as "the information I obtained from [source]" or similar wording clearly stating where it is coming from. You will write it only if necessary.
All your responses will be in the language the user is talking in.

View File

@@ -236,7 +236,7 @@ void TracyLlm::Draw()
const auto isUser = role == "user";
const auto isError = role == "error";
const auto isAssistant = role == "assistant";
const auto isToolResponse = role == "tool";
const auto isToolResponse = isUser && line["content"].get_ref<const std::string&>().starts_with( "<tool_output>\n" );
if( first )
{
@@ -250,7 +250,15 @@ void TracyLlm::Draw()
wasToolResponse = isToolResponse;
float diff, offset;
if( isUser )
if( isToolResponse )
{
diff = mw - yw;
offset = diff / 2;
ImGui::Dummy( ImVec2( offset, 0 ) );
ImGui::SameLine( 0, 0 );
ImGui::TextColored( style.Colors[ImGuiCol_TextDisabled], ICON_FA_REPLY );
}
else if( isUser )
{
diff = mw - uw;
offset = diff / 2;
@@ -274,14 +282,6 @@ void TracyLlm::Draw()
ImGui::SameLine( 0, 0 );
ImGui::TextColored( ImVec4( 0.4f, 0.5f, 1.f, 1.f ), ICON_FA_ROBOT );
}
else if( isToolResponse )
{
diff = mw - yw;
offset = diff / 2;
ImGui::Dummy( ImVec2( offset, 0 ) );
ImGui::SameLine( 0, 0 );
ImGui::TextColored( style.Colors[ImGuiCol_TextDisabled], ICON_FA_REPLY );
}
else
{
assert( false );
@@ -292,7 +292,11 @@ void TracyLlm::Draw()
ImGui::SameLine();
ImGui::BeginGroup();
if( isUser )
if( isToolResponse )
{
ImGui::PushStyleColor( ImGuiCol_Text, style.Colors[ImGuiCol_TextDisabled] );
}
else if( isUser )
{
ImGui::PushStyleColor( ImGuiCol_Text, ImVec4( 0.65f, 0.65f, 0.65f, 1.f ) );
}
@@ -300,10 +304,6 @@ void TracyLlm::Draw()
{
ImGui::PushStyleColor( ImGuiCol_Text, ImVec4( 1.f, 0.25f, 0.25f, 1.f ) );
}
else if( isToolResponse )
{
ImGui::PushStyleColor( ImGuiCol_Text, style.Colors[ImGuiCol_TextDisabled] );
}
else if( isAssistant )
{
ImGui::PushStyleColor( ImGuiCol_Text, style.Colors[ImGuiCol_Text] );
@@ -319,7 +319,7 @@ void TracyLlm::Draw()
if( ImGui::TreeNode( "Tool response..." ) )
{
ImGui::PushFont( m_font );
ImGui::TextWrapped( "%s", line["content"].get_ref<const std::string&>().c_str() );
ImGui::TextWrapped( "%s", line["content"].get_ref<const std::string&>().c_str() + sizeof( "<tool_output>" ) );
ImGui::PopFont();
ImGui::TreePop();
}
@@ -644,15 +644,16 @@ bool TracyLlm::OnResponse( const ollama::response& response )
auto tool = lines[0];
lines.erase( lines.begin() );
const auto reply = HandleToolCalls( tool, lines );
const auto output = "<tool_output>\n" + reply.reply;
if( reply.image.empty() )
{
m_chat->emplace_back( ollama::message( "tool", reply.reply ) );
m_chat->emplace_back( ollama::message( "user", output ) );
}
else
{
std::vector<ollama::image> images;
images.emplace_back( ollama::image::from_base64_string( reply.image ) );
m_chat->emplace_back( ollama::message( "tool", reply.reply, images ) );
m_chat->emplace_back( ollama::message( "user", output, images ) );
}
m_jobs.emplace_back( WorkItem {