|
| 1 | +# ----------------------------------------------------------------------------- |
| 2 | +# Copyright (c) 2025, Oracle and/or its affiliates. |
| 3 | +# |
| 4 | +# Licensed under the Universal Permissive License v 1.0 as shown at |
| 5 | +# http://oss.oracle.com/licenses/upl. |
| 6 | +# ----------------------------------------------------------------------------- |
| 7 | + |
| 8 | +""" |
| 9 | +3300 - Module for testing select_ai agent teams |
| 10 | +""" |
| 11 | + |
| 12 | +import uuid |
| 13 | + |
| 14 | +import pytest |
| 15 | +import select_ai |
| 16 | +from select_ai.agent import ( |
| 17 | + Agent, |
| 18 | + AgentAttributes, |
| 19 | + Task, |
| 20 | + TaskAttributes, |
| 21 | + Team, |
| 22 | + TeamAttributes, |
| 23 | +) |
| 24 | + |
| 25 | +PYSAI_3300_AGENT_NAME = f"PYSAI_3300_AGENT_{uuid.uuid4().hex.upper()}" |
| 26 | +PYSAI_3300_AGENT_DESCRIPTION = "PYSAI_3300_AGENT_DESCRIPTION" |
| 27 | +PYSAI_3300_PROFILE_NAME = f"PYSAI_3300_PROFILE_{uuid.uuid4().hex.upper()}" |
| 28 | +PYSAI_3300_TASK_NAME = f"PYSAI_3300_{uuid.uuid4().hex.upper()}" |
| 29 | +PYSAI_3300_TASK_DESCRIPTION = "PYSAI_3100_SQL_TASK_DESCRIPTION" |
| 30 | +PYSAI_3300_TEAM_NAME = f"PYSAI_3300_TEAM_{uuid.uuid4().hex.upper()}" |
| 31 | +PYSAI_3300_TEAM_DESCRIPTION = "PYSAI_3300_TEAM_DESCRIPTION" |
| 32 | + |
| 33 | + |
| 34 | +@pytest.fixture(scope="module") |
| 35 | +def python_gen_ai_profile(profile_attributes): |
| 36 | + profile = select_ai.Profile( |
| 37 | + profile_name=PYSAI_3300_PROFILE_NAME, |
| 38 | + description="OCI GENAI Profile", |
| 39 | + attributes=profile_attributes, |
| 40 | + ) |
| 41 | + yield profile |
| 42 | + profile.delete(force=True) |
| 43 | + |
| 44 | + |
| 45 | +@pytest.fixture(scope="module") |
| 46 | +def task_attributes(): |
| 47 | + return TaskAttributes( |
| 48 | + instruction="Help the user with their request about movies. " |
| 49 | + "User question: {query}. ", |
| 50 | + enable_human_tool=False, |
| 51 | + ) |
| 52 | + |
| 53 | + |
| 54 | +@pytest.fixture(scope="module") |
| 55 | +def task(task_attributes): |
| 56 | + task = Task( |
| 57 | + task_name=PYSAI_3300_TASK_NAME, |
| 58 | + description=PYSAI_3300_TASK_DESCRIPTION, |
| 59 | + attributes=task_attributes, |
| 60 | + ) |
| 61 | + task.create() |
| 62 | + yield task |
| 63 | + task.delete(force=True) |
| 64 | + |
| 65 | + |
| 66 | +@pytest.fixture(scope="module") |
| 67 | +def agent(python_gen_ai_profile): |
| 68 | + agent = Agent( |
| 69 | + agent_name=PYSAI_3300_AGENT_NAME, |
| 70 | + description=PYSAI_3300_AGENT_DESCRIPTION, |
| 71 | + attributes=AgentAttributes( |
| 72 | + profile_name=PYSAI_3300_PROFILE_NAME, |
| 73 | + role="You are an AI Movie Analyst. " |
| 74 | + "Your can help answer a variety of questions related to movies. ", |
| 75 | + enable_human_tool=False, |
| 76 | + ), |
| 77 | + ) |
| 78 | + agent.create(enabled=True, replace=True) |
| 79 | + yield agent |
| 80 | + agent.delete(force=True) |
| 81 | + |
| 82 | + |
| 83 | +@pytest.fixture(scope="module") |
| 84 | +def team_attributes(agent, task): |
| 85 | + return TeamAttributes( |
| 86 | + agents=[{"name": agent.agent_name, "task": task.task_name}], |
| 87 | + process="sequential", |
| 88 | + ) |
| 89 | + |
| 90 | + |
| 91 | +@pytest.fixture(scope="module") |
| 92 | +def team(team_attributes): |
| 93 | + team = Team( |
| 94 | + team_name=PYSAI_3300_TEAM_NAME, |
| 95 | + description=PYSAI_3300_TEAM_DESCRIPTION, |
| 96 | + attributes=team_attributes, |
| 97 | + ) |
| 98 | + team.create() |
| 99 | + yield team |
| 100 | + team.delete(force=True) |
| 101 | + |
| 102 | + |
| 103 | +def test_3300(team, team_attributes): |
| 104 | + assert team.team_name == PYSAI_3300_TEAM_NAME |
| 105 | + assert team.description == PYSAI_3300_TEAM_DESCRIPTION |
| 106 | + assert team.attributes == team_attributes |
| 107 | + |
| 108 | + |
| 109 | +@pytest.mark.parametrize("team_name_pattern", [None, "^PYSAI_3300_TEAM_"]) |
| 110 | +def test_3301(team_name_pattern): |
| 111 | + if team_name_pattern: |
| 112 | + teams = list(select_ai.agent.Team.list(team_name_pattern)) |
| 113 | + else: |
| 114 | + teams = list(select_ai.agent.Team.list()) |
| 115 | + team_names = set(team.team_name for team in teams) |
| 116 | + team_descriptions = set(team.description for team in teams) |
| 117 | + assert PYSAI_3300_TEAM_NAME in team_names |
| 118 | + assert PYSAI_3300_TEAM_DESCRIPTION in team_descriptions |
| 119 | + |
| 120 | + |
| 121 | +def test_3302(team_attributes): |
| 122 | + team = select_ai.agent.Team.fetch(team_name=PYSAI_3300_TEAM_NAME) |
| 123 | + assert team.team_name == PYSAI_3300_TEAM_NAME |
| 124 | + assert team.description == PYSAI_3300_TEAM_DESCRIPTION |
| 125 | + assert team.attributes == team_attributes |
0 commit comments