From 940ad510e0dac3d9eec505545f33519242506ba9 Mon Sep 17 00:00:00 2001 From: Jonny Date: Sun, 13 Sep 2026 19:12:03 +0200 Subject: [PATCH] feat: wire order tools into the chat system prompt Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_01V57jSQPqwkGG8BuAXg59X5 --- Claude outputs/main.py | 7 +++++-- Claude outputs/tests/test_memory.py | 2 +- Claude outputs/tests/test_orders.py | 26 ++++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/Claude outputs/main.py b/Claude outputs/main.py index 0f947da..c7cd39d 100644 --- a/Claude outputs/main.py +++ b/Claude outputs/main.py @@ -923,7 +923,10 @@ async def run_chat_completion(claude_messages: list, conversation_id: int): latest_user_message = claude_messages[-1]["content"] 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: 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, max_tokens=1024, system=system_prompt, - tools=CALENDAR_TOOLS + MEMORY_TOOLS, + tools=CALENDAR_TOOLS + MEMORY_TOOLS + ORDER_TOOLS, messages=messages, ) total_input += completion.usage.input_tokens diff --git a/Claude outputs/tests/test_memory.py b/Claude outputs/tests/test_memory.py index 8e911bc..073991e 100644 --- a/Claude outputs/tests/test_memory.py +++ b/Claude outputs/tests/test_memory.py @@ -211,7 +211,7 @@ async def test_run_chat_completion_includes_memory_context_in_system_prompt(): _, kwargs = main.claude_client.messages.create.call_args 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 diff --git a/Claude outputs/tests/test_orders.py b/Claude outputs/tests/test_orders.py index d332899..7833d2a 100644 --- a/Claude outputs/tests/test_orders.py +++ b/Claude outputs/tests/test_orders.py @@ -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"})): result = await main.execute_tool("update_order_status", {"order_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"]