71 lines
2.3 KiB
Python
71 lines
2.3 KiB
Python
import asyncio
|
|
from types import SimpleNamespace
|
|
|
|
from gfa_core.mas.agents.base import AgentMessage, AgentState
|
|
from gfa_core.mas.agents.intent_v2 import IntentAgentV2
|
|
|
|
|
|
def test_fallback_does_not_turn_unrecognized_continuation_into_identify():
|
|
intent = IntentAgentV2(None)._fallback_recognition("执行接下来的分析")
|
|
|
|
assert intent["stages"] == []
|
|
assert intent["needs_clarification"] is True
|
|
assert intent["clarification_type"] == "analysis_stage"
|
|
|
|
|
|
def test_validation_does_not_turn_empty_model_stages_into_identify():
|
|
intent = IntentAgentV2(None)._validate_intent(
|
|
{
|
|
"gene_family": "SPL",
|
|
"species": "Ft",
|
|
"stages": [],
|
|
"params": {},
|
|
},
|
|
"执行接下来的步骤",
|
|
)
|
|
|
|
assert intent["stages"] == []
|
|
assert intent["needs_clarification"] is True
|
|
assert intent["clarification_type"] == "analysis_stage"
|
|
|
|
|
|
def test_fallback_still_recognizes_explicit_identify():
|
|
intent = IntentAgentV2(None)._fallback_recognition("执行 identify 分析")
|
|
|
|
assert intent["stages"] == ["identify"]
|
|
assert intent.get("needs_clarification") is not True
|
|
|
|
|
|
def test_empty_model_response_cannot_authorize_identify_and_keeps_goal_context():
|
|
class _EmptyLLM:
|
|
async def acall(self, *_args, **_kwargs):
|
|
return SimpleNamespace(content="")
|
|
|
|
state = AgentState(session_id="empty-intent", job_id="job-empty-intent")
|
|
message = AgentMessage(
|
|
sender="router",
|
|
receiver="intent_v2",
|
|
message_type="recognize_intent",
|
|
payload={
|
|
"query": "执行接下来的分析",
|
|
"job_id": "job-empty-intent",
|
|
"workspace": "/tmp/job-empty-intent",
|
|
"goal_context": {
|
|
"user_terms": {
|
|
"gene_family": "SPL",
|
|
"target_species": ["Ft"],
|
|
"reference_species": ["At"],
|
|
"comparative_species": [],
|
|
}
|
|
},
|
|
},
|
|
)
|
|
|
|
returned = asyncio.run(IntentAgentV2(_EmptyLLM()).execute(state, message))
|
|
intent = returned.results["results"]["intent"]
|
|
|
|
assert intent["stages"] == []
|
|
assert intent["needs_clarification"] is True
|
|
assert intent["target_species"] == ["Ft"]
|
|
assert intent["reference_species"] == ["At"]
|