deer-flow/backend/tests/test_interaction_policy.py
Eilen Shin aaca3eeaeb
refactor(agent): ground runtime decisions in structured evidence (#7986)
* refactor(agent): ground runtime decisions in structured evidence

Use producer status and structured errors for tool recovery, preserve memory context without lexical confirmation, and remove predetermined receipt and skill conclusions.

Require explicit MCP discovery and authenticated schedule trial actions. Preserve authorization, ownership, isolation, and bounded execution; update documentation and regression coverage.

* test(sandbox): expect read_file initialization error callback

* fix(agent): address evidence review follow-ups

* fix(agent): preserve retry budgets for OpenAI transport errors

* fix(agent): expose tool execution status in model requests

Project validated execution metadata and exact tool text into request-only JSON so status survives provider serialization. Preserve stored results and receipt hashes, cover SDK and graph boundaries, and migrate replay input hashes without changing recorded responses.

---------

Co-authored-by: Willem Jiang <willem.jiang@gmail.com>
2026-11-08 22:00:23 +08:00

52 lines
1.9 KiB
Python

import pytest
from deerflow.agents.interaction_policy import (
ASK_CLARIFICATION_TOOL_NAME,
RunInteractionMode,
RunInteractionPolicy,
resolve_run_interaction_policy,
)
def test_interactive_policy_keeps_clarification_available():
policy = resolve_run_interaction_policy({})
assert policy.mode is RunInteractionMode.INTERACTIVE
assert policy.allows_clarification
assert policy.disabled_tool_names == frozenset()
assert "ask_clarification" in policy.clarification_system
def test_scheduled_policy_disables_tool_and_uses_autonomous_guidance():
policy = resolve_run_interaction_policy({"context": {"non_interactive": True}})
assert policy.mode is RunInteractionMode.SCHEDULED
assert not policy.allows_clarification
assert policy.disabled_tool_names == frozenset({ASK_CLARIFICATION_TOOL_NAME})
assert "MUST call ask_clarification" not in policy.clarification_system
assert "minimal reversible assumptions" in policy.clarification_reminder
def test_github_policy_resolves_as_webhook_without_legacy_flag():
policy = resolve_run_interaction_policy({"context": {"channel_name": "github", "disable_clarification": True}})
assert policy.mode is RunInteractionMode.WEBHOOK
assert not policy.allows_clarification
assert "issue, pull request, repository, event context" in policy.clarification_system
def test_explicit_mode_takes_precedence_over_legacy_flags():
policy = resolve_run_interaction_policy(
{
"configurable": {"interaction_mode": "autonomous"},
"context": {"non_interactive": True, "channel_name": "github"},
}
)
assert policy == RunInteractionPolicy(RunInteractionMode.AUTONOMOUS)
def test_invalid_explicit_mode_fails_closed():
with pytest.raises(ValueError, match="Invalid interaction_mode 'Scheduled'"):
resolve_run_interaction_policy({"context": {"interaction_mode": "Scheduled"}})