Skip to content

Commit 17ad731

Browse files
committed
wip
1 parent cc9b604 commit 17ad731

3 files changed

Lines changed: 30 additions & 20 deletions

File tree

ai21/clients/common/agents/agents.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,10 @@ def _create_body(
3030
tool_resources: Dict[str, Any] | NotGiven,
3131
requirements: List[Requirement] | NotGiven,
3232
budget: BudgetLevel | NotGiven,
33-
agent_type: AgentType | NotGiven,
3433
response_language: ResponseLanguage | NotGiven,
3534
**kwargs,
3635
) -> dict:
37-
body = remove_not_given(
36+
return remove_not_given(
3837
{
3938
"name": name,
4039
"description": description,
@@ -43,15 +42,10 @@ def _create_body(
4342
"tool_resources": tool_resources,
4443
"requirements": requirements,
4544
"budget": budget,
46-
"agent_type": agent_type,
4745
"response_language": response_language,
4846
**kwargs,
4947
}
5048
)
51-
# Map agent_type to assistant_type for API compatibility
52-
if "agent_type" in body:
53-
body["assistant_type"] = body.pop("agent_type")
54-
return body
5549

5650
def _modify_body(
5751
self,
@@ -115,9 +109,6 @@ def modify(
115109
*,
116110
name: str | NotGiven = NOT_GIVEN,
117111
description: str | NotGiven = NOT_GIVEN,
118-
optimization: str | NotGiven = NOT_GIVEN,
119-
avatar: str | NotGiven = NOT_GIVEN,
120-
is_archived: bool | NotGiven = NOT_GIVEN,
121112
models: List[str] | NotGiven = NOT_GIVEN,
122113
tools: List[Dict[str, Any]] | NotGiven = NOT_GIVEN,
123114
tool_resources: Dict[str, Any] | NotGiven = NOT_GIVEN,

ai21/clients/common/agents/run.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,29 @@
11
from abc import ABC
22

33
from ai21.models.agents import Agent
4+
from ai21.models.maestro.run import Requirement
45
from ai21.utils.typing import remove_not_given
56

67

78
class BaseAgentRun(ABC):
9+
def _convert_requirements(self, requirements):
10+
"""Convert agent requirements to maestro requirements, filtering out invalid ones."""
11+
if not requirements:
12+
return None
13+
14+
converted_requirements = []
15+
for req in requirements:
16+
if req.title and req.description and req.type:
17+
converted_requirements.append(
18+
Requirement(
19+
name=req.title,
20+
description=req.description,
21+
is_mandatory=req.type == "mandatory",
22+
)
23+
)
24+
25+
return converted_requirements if converted_requirements else None
26+
827
def convert_agent_to_maestro_run_payload(
928
self,
1029
agent: Agent,
@@ -15,7 +34,7 @@ def convert_agent_to_maestro_run_payload(
1534
models=agent.models,
1635
tools=agent.tools,
1736
tool_resources=agent.tool_resources,
18-
requirements=agent.requirements,
37+
requirements=self._convert_requirements(agent.requirements),
1938
budget=agent.budget,
2039
response_language=agent.response_language,
2140
**kwargs,

ai21/models/agents/agent.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,19 @@ class Requirement(AI21BaseModel):
4949
class Agent(AI21BaseModel):
5050
id: str
5151
name: str
52-
description: Union[str, None] = None
52+
description: str | None = None
5353
organization_id: str
5454
user_id: str
55-
models: Union[List[str], None] = None
56-
tools: Union[List[ToolDefinition], None] = None
57-
tool_resources: Union[ToolResources, None] = None
58-
requirements: Union[List[Requirement], None] = None
59-
budget: Union[Budget, None] = None
60-
visibility: Union[Visibility, None] = None
61-
assistant_type: Union[AgentType, None] = None
55+
models: list[str] | None = None
56+
tools: list[ToolDefinition] | None = None
57+
tool_resources: ToolResources | None = None
58+
requirements: list[Requirement] | None = None
59+
budget: Budget | None = None
60+
visibility: Visibility | None = None
61+
assistant_type: AgentType | None = None
6262
created_at: datetime
6363
updated_at: datetime
64-
response_language: Union[ResponseLanguage, None] = None
64+
response_language: ResponseLanguage | None = None
6565

6666

6767
class ListAgentsResponse(AI21BaseModel):

0 commit comments

Comments
 (0)