fix: delegate analysis planning from main agent
This commit is contained in:
@@ -0,0 +1,101 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
from typing import Any
|
||||
|
||||
import pytest
|
||||
|
||||
from gfa_core.mas.agents.router_runtime import (
|
||||
RouteDecision,
|
||||
RouterRuntime,
|
||||
)
|
||||
from gfa_core.mas.workflow_models import GoalLedger
|
||||
|
||||
|
||||
class _PassThroughTools:
|
||||
@staticmethod
|
||||
def resolve_analysis_handoff_request(
|
||||
query: str,
|
||||
*,
|
||||
workflow_id: str | None = None,
|
||||
guidance: bool = False,
|
||||
) -> str:
|
||||
return query
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("query", "workflow_id", "clarification_question"),
|
||||
(
|
||||
(
|
||||
"执行rnaseq",
|
||||
"rnaseq_whole_genome",
|
||||
"请选择全基因组还是基因家族成员RNA-seq",
|
||||
),
|
||||
("执行全基因组rnaseq", "rnaseq_whole_genome", None),
|
||||
("对已确认家族成员执行rnaseq", "rnaseq_family_member", None),
|
||||
("执行motif分析", "gene_family", None),
|
||||
),
|
||||
)
|
||||
def test_new_analysis_proposal_preserves_original_request_without_main_agent_planning(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
query: str,
|
||||
workflow_id: str,
|
||||
clarification_question: str | None,
|
||||
) -> None:
|
||||
runtime = RouterRuntime(object(), _PassThroughTools(), max_iterations=5) # type: ignore[arg-type]
|
||||
|
||||
async def decide_route(**_: Any) -> tuple[RouteDecision, int, list[dict[str, Any]]]:
|
||||
return (
|
||||
RouteDecision(
|
||||
goal="new_analysis",
|
||||
needs=["analysis_intent"],
|
||||
subject=query,
|
||||
clarification_question=clarification_question,
|
||||
workflow_id=workflow_id, # type: ignore[arg-type]
|
||||
analysis_request_kind="execution",
|
||||
),
|
||||
1,
|
||||
[],
|
||||
)
|
||||
|
||||
monkeypatch.setattr(runtime, "_decide_route", decide_route)
|
||||
|
||||
outcome = asyncio.run(
|
||||
runtime.run(
|
||||
query=query,
|
||||
history=[],
|
||||
session_id="analysis-handoff-session",
|
||||
job_id="job-analysis-handoff",
|
||||
goal_ledger=GoalLedger(
|
||||
conversation_id="analysis-handoff-session",
|
||||
revision=0,
|
||||
user_terms={"active_job_id": "job-analysis-handoff"},
|
||||
),
|
||||
)
|
||||
)
|
||||
|
||||
assert outcome.action == "clarify"
|
||||
assert outcome.proposal is not None
|
||||
assert outcome.proposal["request"] == query
|
||||
assert "workflow_id" not in outcome.proposal
|
||||
assert "全基因组还是" not in outcome.message
|
||||
|
||||
|
||||
def test_new_analysis_decision_discards_main_agent_workflow_and_clarification() -> None:
|
||||
decision = RouteDecision(
|
||||
goal="new_analysis",
|
||||
needs=["analysis_intent"],
|
||||
subject="执行rnaseq",
|
||||
clarification_question="请选择RNA-seq模式",
|
||||
workflow_id="rnaseq_whole_genome",
|
||||
analysis_request_kind="execution",
|
||||
)
|
||||
|
||||
normalized = RouterRuntime._analysis_handoff_decision(decision)
|
||||
|
||||
assert normalized.goal == "new_analysis"
|
||||
assert normalized.needs == ["analysis_intent"]
|
||||
assert normalized.subject == decision.subject
|
||||
assert normalized.workflow_id is None
|
||||
assert normalized.clarification_question is None
|
||||
assert normalized.analysis_request_kind == "execution"
|
||||
Reference in New Issue
Block a user