Skip to content

Commit 1050d05

Browse files
SkylarKeltyclaude
andcommitted
fix: use plain messages for result selection and query refinement
The tool-call message pattern was causing some models to emit tool-call markup as text content instead of answering the prompt. This happened because the conversation history (assistant→tool_call→tool→response) primed the model to continue the tool-calling pattern. Only the essay synthesis call needs tool-call isolation (it receives raw untrusted web page content). Result selection and query refinement only receive search metadata (titles, snippets, URLs) generated by Artemis. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent e7daa54 commit 1050d05

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

artemis/researcher.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -240,23 +240,25 @@ async def generate_refined_queries(
240240
# Summarize current findings (untrusted web content)
241241
findings = format_results_for_synthesis(current_results[:10])
242242

243-
system = "You are a research query refinement specialist. Based on initial findings returned by the web_search tool, generate better follow-up queries."
243+
system = "You are a research query refinement specialist. Based on initial findings, generate better follow-up queries."
244244
user = f"""Topic: {topic}
245245
Section: {section}
246246
247247
Already Explored Queries: {', '.join(existing_queries)}
248248
249+
Current findings:
250+
{findings}
251+
249252
Generate {num_queries} NEW queries that explore aspects NOT yet covered by existing queries.
250253
Focus on gaps, unanswered questions, or deeper exploration of promising leads.
251254
Respond with ONLY a JSON array of strings.
252255
253256
Example: ["deeper aspect query", "contradiction check query"]"""
254257

255-
messages = build_tool_messages(
256-
system=system,
257-
user=user,
258-
tool_content=findings,
259-
)
258+
messages = [
259+
{"role": "system", "content": system},
260+
{"role": "user", "content": user},
261+
]
260262

261263
completion = await chat_completion(
262264
messages=messages,
@@ -745,14 +747,16 @@ async def select_relevant_results(
745747
Section: {section}
746748
Description: {description}
747749
750+
Search results:
751+
{results_text}
752+
748753
Return ONLY a JSON array of the result indices (0-based) for the most relevant results.
749754
Example: [0, 2, 5]"""
750755

751-
messages = build_tool_messages(
752-
system=system,
753-
user=user,
754-
tool_content=results_text,
755-
)
756+
messages = [
757+
{"role": "system", "content": system},
758+
{"role": "user", "content": user},
759+
]
756760

757761
try:
758762
completion = await chat_completion(
@@ -782,6 +786,8 @@ async def select_relevant_results(
782786
return (selected[:max_results] if selected else results[:max_results]), usage
783787
except (UpstreamServiceError, json.JSONDecodeError, ValueError, KeyError) as exc:
784788
logger.warning("LLM result selection failed, using first N: %s", exc)
789+
logger.debug(messages)
790+
logger.debug(completion["content"] if 'completion' in locals() else "No completion")
785791
return results[:max_results], TokenUsage()
786792

787793

0 commit comments

Comments
 (0)