fix(ai): mode agent utilise les outils natifs au lieu du bloc obsigate-action (BUG-053)
This commit is contained in:
@@ -729,6 +729,23 @@ class TestGeneralPrompt:
|
||||
prompt = build_general_system_prompt(["Alpha"])
|
||||
assert "Contexte applicatif actuel" not in prompt
|
||||
|
||||
def test_general_prompt_agent_uses_native_tools(self):
|
||||
"""BUG-053: the agent must call tools, not emit `obsigate-action` blocks."""
|
||||
from backend.bookslm import build_general_system_prompt
|
||||
|
||||
prompt = build_general_system_prompt(["Alpha"], agent=True)
|
||||
assert "create_file" in prompt
|
||||
# The text-protocol example block must not be taught in agent mode.
|
||||
assert '"action": "create_file"' not in prompt
|
||||
assert "inclus un bloc de ce type" not in prompt
|
||||
|
||||
def test_general_prompt_classic_keeps_text_protocol(self):
|
||||
"""The classic chat endpoint still uses the text action protocol."""
|
||||
from backend.bookslm import build_general_system_prompt
|
||||
|
||||
prompt = build_general_system_prompt(["Alpha"])
|
||||
assert '"action": "create_file"' in prompt
|
||||
|
||||
def test_documents_prompt_scope(self):
|
||||
from backend.bookslm import build_system_prompt
|
||||
|
||||
@@ -899,6 +916,30 @@ class TestBooksLMAgentEndpoint:
|
||||
)
|
||||
assert resp.status_code == 401
|
||||
|
||||
def test_agent_prompt_uses_native_tools_not_text_protocol(self, bookslm_client, monkeypatch):
|
||||
"""BUG-053: the agent system prompt must not teach the text protocol."""
|
||||
import backend.bookslm_routes as routes
|
||||
from backend.ai_chat import LLMResponse
|
||||
|
||||
captured = {}
|
||||
|
||||
async def fake_chat_completion(messages, **kwargs):
|
||||
captured["system"] = messages[0]["content"]
|
||||
return LLMResponse(content="ok")
|
||||
|
||||
monkeypatch.setattr(routes, "chat_completion", fake_chat_completion)
|
||||
monkeypatch.setattr(routes, "_resolve_provider_name", lambda requested: "deepseek")
|
||||
|
||||
token, _ = _login_bookslm(bookslm_client)
|
||||
resp = bookslm_client.post(
|
||||
"/api/ai/bookslm/agent",
|
||||
json={"directory": "", "message": "cree un fichier", "mode": "general"},
|
||||
headers={"Authorization": f"Bearer {token}"},
|
||||
)
|
||||
assert resp.status_code == 200
|
||||
assert "create_file" in captured["system"]
|
||||
assert '"action": "create_file"' not in captured["system"]
|
||||
|
||||
def test_agent_tool_call_flow(self, bookslm_client, monkeypatch):
|
||||
import backend.bookslm_routes as routes
|
||||
from backend.ai_chat import LLMResponse, ToolCall
|
||||
|
||||
Reference in New Issue
Block a user