File size: 4,330 Bytes
310260a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 | """
Integration Tests for Tool Selection
Tests agent's ability to select correct tools based on user intent.
"""
import pytest
from tests.utils.agent_helpers import invoke_agent_with_message, assert_tool_called, test_agent_intent_recognition
@pytest.mark.integration
@pytest.mark.asyncio
async def test_agent_selects_correct_tool_based_on_user_intent(test_user, test_session):
"""
Test: Agent selects correct tool based on user intent
Verifies that agent correctly interprets user intent and selects appropriate tools.
"""
# Test create intent
response1 = await invoke_agent_with_message(
user_id=test_user.id,
message="Remind me to call mom"
)
assert_tool_called(response1, "create_task")
# Test list intent
response2 = await invoke_agent_with_message(
user_id=test_user.id,
message="What do I need to do?"
)
assert_tool_called(response2, "list_tasks")
@pytest.mark.integration
@pytest.mark.asyncio
async def test_agent_recognizes_create_task_intent_variations(test_user):
"""
Test: Agent recognizes create_task intent variations
Verifies that agent recognizes different phrasings for creating tasks.
"""
# Test various create task phrasings
create_phrases = [
"Add a task to buy groceries",
"Remind me to call the dentist",
"I need to submit the report",
"Create a task for reviewing code"
]
for phrase in create_phrases:
result = await test_agent_intent_recognition(
user_id=test_user.id,
message=phrase,
expected_tool="create_task"
)
assert result, f"Agent failed to recognize create intent for: {phrase}"
@pytest.mark.integration
@pytest.mark.asyncio
async def test_agent_recognizes_list_tasks_intent_variations(test_user):
"""
Test: Agent recognizes list_tasks intent variations
Verifies that agent recognizes different phrasings for listing tasks.
"""
# Test various list task phrasings
list_phrases = [
"Show my tasks",
"What do I need to do?",
"List all my tasks",
"What's on my todo list?"
]
for phrase in list_phrases:
result = await test_agent_intent_recognition(
user_id=test_user.id,
message=phrase,
expected_tool="list_tasks"
)
assert result, f"Agent failed to recognize list intent for: {phrase}"
@pytest.mark.integration
@pytest.mark.asyncio
async def test_agent_recognizes_mark_complete_intent(test_user, test_session):
"""
Test: Agent recognizes mark_complete intent
Verifies that agent recognizes intent to mark tasks complete.
"""
# Create a task first
from tests.utils.task_helpers import create_test_task
task = create_test_task(test_session, test_user.id, title="Test task")
# Test mark complete intent
response = await invoke_agent_with_message(
user_id=test_user.id,
message=f"Mark task {task.id} as complete"
)
assert_tool_called(response, "mark_complete")
@pytest.mark.integration
@pytest.mark.asyncio
async def test_agent_recognizes_update_task_intent(test_user, test_session):
"""
Test: Agent recognizes update_task intent
Verifies that agent recognizes intent to update tasks.
"""
# Create a task first
from tests.utils.task_helpers import create_test_task
task = create_test_task(test_session, test_user.id, title="Old title")
# Test update intent
response = await invoke_agent_with_message(
user_id=test_user.id,
message=f"Change task {task.id} title to 'New title'"
)
assert_tool_called(response, "update_task")
@pytest.mark.integration
@pytest.mark.asyncio
async def test_agent_recognizes_delete_task_intent(test_user, test_session):
"""
Test: Agent recognizes delete_task intent
Verifies that agent recognizes intent to delete tasks.
"""
# Create a task first
from tests.utils.task_helpers import create_test_task
task = create_test_task(test_session, test_user.id, title="Task to delete")
# Test delete intent
response = await invoke_agent_with_message(
user_id=test_user.id,
message=f"Delete task {task.id}"
)
assert_tool_called(response, "delete_task")
|