23
23
24
24
import json
25
25
import logging
26
+ from typing import Dict , List , Optional , Text , Union
27
+ from urllib .parse import urljoin
26
28
27
29
from aixplain .enums .supplier import Supplier
28
30
from aixplain .modules .agent import Agent
29
- from aixplain .modules .team_agent import TeamAgent
31
+ from aixplain .modules .team_agent import TeamAgent , InspectorTarget
30
32
from aixplain .utils import config
31
33
from aixplain .factories .team_agent_factory .utils import build_team_agent
32
34
from aixplain .utils .file_utils import _request_with_retry
33
- from typing import Dict , List , Optional , Text , Union
34
- from urllib .parse import urljoin
35
35
36
36
37
37
class TeamAgentFactory :
@@ -47,9 +47,29 @@ def create(
47
47
version : Optional [Text ] = None ,
48
48
use_mentalist : bool = True ,
49
49
use_inspector : bool = True ,
50
+ num_inspectors : int = 1 ,
51
+ inspector_targets : List [Union [InspectorTarget , Text ]] = [InspectorTarget .STEPS ],
50
52
use_mentalist_and_inspector : bool = False , # TODO: remove this
51
53
) -> TeamAgent :
52
- """Create a new team agent in the platform."""
54
+ """Create a new team agent in the platform.
55
+
56
+ Args:
57
+ name: The name of the team agent.
58
+ agents: A list of agents to be added to the team.
59
+ llm_id: The ID of the LLM to be used for the team agent.
60
+ description: The description of the team agent.
61
+ api_key: The API key to be used for the team agent.
62
+ supplier: The supplier of the team agent.
63
+ version: The version of the team agent.
64
+ use_mentalist: Whether to use the mentalist agent.
65
+ use_inspector: Whether to use the inspector agent.
66
+ num_inspectors: The number of inspectors to be used for each inspection.
67
+ inspector_targets: Which stages to be inspected during an execution of the team agent. (steps, output)
68
+ use_mentalist_and_inspector: Whether to use the mentalist and inspector agents. (legacy)
69
+
70
+ Returns:
71
+ A new team agent instance.
72
+ """
53
73
assert len (agents ) > 0 , "TeamAgent Onboarding Error: At least one agent must be provided."
54
74
agent_list = []
55
75
for agent in agents :
@@ -68,8 +88,22 @@ def create(
68
88
assert isinstance (agent , Agent ), "TeamAgent Onboarding Error: Agents must be instances of Agent class"
69
89
agent_list .append (agent_obj )
70
90
71
- if use_inspector and not use_mentalist :
72
- raise Exception ("TeamAgent Onboarding Error: To use the Inspector agent, you must enable Mentalist." )
91
+ # NOTE: backend expects max_inspectors (for "generated" inspectors)
92
+ max_inspectors = num_inspectors
93
+
94
+ if use_inspector :
95
+ try :
96
+ # convert to enum if string and check its validity
97
+ inspector_targets = [InspectorTarget (target ) for target in inspector_targets ]
98
+ except ValueError :
99
+ raise ValueError ("TeamAgent Onboarding Error: Invalid inspector target. Valid targets are: steps, output" )
100
+
101
+ if not use_mentalist :
102
+ raise Exception ("TeamAgent Onboarding Error: To use the Inspector agent, you must enable Mentalist." )
103
+ if max_inspectors < 1 :
104
+ raise Exception (
105
+ "TeamAgent Onboarding Error: The number of inspectors must be greater than 0 when using the Inspector agent."
106
+ )
73
107
74
108
if use_mentalist_and_inspector :
75
109
mentalist_llm_id = llm_id
@@ -100,6 +134,8 @@ def create(
100
134
"supervisorId" : llm_id ,
101
135
"plannerId" : mentalist_llm_id ,
102
136
"inspectorId" : inspector_llm_id ,
137
+ "maxInspectors" : max_inspectors ,
138
+ "inspectorTargets" : inspector_targets if use_inspector else [],
103
139
"supplier" : supplier ,
104
140
"version" : version ,
105
141
"status" : "draft" ,
0 commit comments