feat: wire order tools into the chat system prompt

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01V57jSQPqwkGG8BuAXg59X5
This commit is contained in:
Jonny 2026-09-13 19:12:03 +02:00
parent c0185bbbf7
commit 940ad510e0
3 changed files with 32 additions and 3 deletions

View File

@ -923,7 +923,10 @@ async def run_chat_completion(claude_messages: list, conversation_id: int):
latest_user_message = claude_messages[-1]["content"] latest_user_message = claude_messages[-1]["content"]
memory_context = await build_memory_context(latest_user_message, conversation_id) memory_context = await build_memory_context(latest_user_message, conversation_id)
system_prompt = f"{CLAUDE_SYSTEM_PROMPT}\n\n{CALENDAR_ASSISTANT_INSTRUCTIONS}\n\n{MEMORY_ASSISTANT_INSTRUCTIONS}" system_prompt = (
f"{CLAUDE_SYSTEM_PROMPT}\n\n{CALENDAR_ASSISTANT_INSTRUCTIONS}\n\n"
f"{MEMORY_ASSISTANT_INSTRUCTIONS}\n\n{ORDER_ASSISTANT_INSTRUCTIONS}"
)
if memory_context: if memory_context:
system_prompt = f"{system_prompt}\n\n{memory_context}" system_prompt = f"{system_prompt}\n\n{memory_context}"
@ -937,7 +940,7 @@ async def run_chat_completion(claude_messages: list, conversation_id: int):
model=CLAUDE_MODEL, model=CLAUDE_MODEL,
max_tokens=1024, max_tokens=1024,
system=system_prompt, system=system_prompt,
tools=CALENDAR_TOOLS + MEMORY_TOOLS, tools=CALENDAR_TOOLS + MEMORY_TOOLS + ORDER_TOOLS,
messages=messages, messages=messages,
) )
total_input += completion.usage.input_tokens total_input += completion.usage.input_tokens

View File

@ -211,7 +211,7 @@ async def test_run_chat_completion_includes_memory_context_in_system_prompt():
_, kwargs = main.claude_client.messages.create.call_args _, kwargs = main.claude_client.messages.create.call_args
assert "Hund heisst Bruno" in kwargs["system"] assert "Hund heisst Bruno" in kwargs["system"]
assert kwargs["tools"] == main.CALENDAR_TOOLS + main.MEMORY_TOOLS assert kwargs["tools"] == main.CALENDAR_TOOLS + main.MEMORY_TOOLS + main.ORDER_TOOLS
@pytest.mark.asyncio @pytest.mark.asyncio

View File

@ -280,3 +280,29 @@ async def test_execute_tool_dispatches_order_tools():
with patch.object(main, "update_order_status", new=AsyncMock(return_value={"id": 1, "status": "Erledigt"})): with patch.object(main, "update_order_status", new=AsyncMock(return_value={"id": 1, "status": "Erledigt"})):
result = await main.execute_tool("update_order_status", {"order_id": 1, "status": "Erledigt"}) result = await main.execute_tool("update_order_status", {"order_id": 1, "status": "Erledigt"})
assert json.loads(result) == {"id": 1, "status": "Erledigt"} assert json.loads(result) == {"id": 1, "status": "Erledigt"}
@pytest.mark.asyncio
async def test_run_chat_completion_includes_order_tools_and_instructions():
completion = MagicMock()
completion.stop_reason = "end_turn"
text_block = MagicMock()
text_block.type = "text"
text_block.text = "Bestellung angelegt."
completion.content = [text_block]
usage = MagicMock()
usage.input_tokens = 10
usage.output_tokens = 5
completion.usage = usage
main.claude_client = MagicMock()
main.claude_client.messages.create.return_value = completion
with patch.object(main, "build_memory_context", new=AsyncMock(return_value="")):
await main.run_chat_completion(
[{"role": "user", "content": "Neue Bestellung fuer Feuerwehr Onza"}], conversation_id=1
)
_, kwargs = main.claude_client.messages.create.call_args
assert kwargs["tools"] == main.CALENDAR_TOOLS + main.MEMORY_TOOLS + main.ORDER_TOOLS
assert "create_order" in kwargs["system"] or "Bestellungen" in kwargs["system"]