Skip to content

Commit e8a90e6

Browse files
committed
wip
1 parent c173448 commit e8a90e6

7 files changed

Lines changed: 164 additions & 189 deletions

File tree

ai21/clients/studio/resources/agents/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
__all__ = [
55
"Agents",
6-
"AsyncAgents",
6+
"AsyncAgents",
77
"AgentRun",
88
"AsyncAgentRun",
9-
]
9+
]

ai21/clients/studio/resources/agents/agents.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def create(self, *, request: CreateAgentRequest) -> Agent:
2424
# Map agent_type to assistant_type for API compatibility
2525
if "agent_type" in body:
2626
body["assistant_type"] = body.pop("agent_type")
27-
27+
2828
result = self._post(path=f"/{self._module_name}", body=body, response_cls=Agent)
2929
assert result is not None # response_cls is provided, so result should never be None
3030
return result
@@ -65,7 +65,7 @@ async def create(self, *, request: CreateAgentRequest) -> Agent:
6565
body = request.model_dump(exclude_none=True)
6666
if "agent_type" in body:
6767
body["assistant_type"] = body.pop("agent_type")
68-
68+
6969
result = await self._post(path=f"/{self._module_name}", body=body, response_cls=Agent)
7070
assert result is not None # response_cls is provided, so result should never be None
7171
return result
@@ -93,4 +93,4 @@ async def delete(self, agent_id: str) -> DeleteAgentResponse:
9393
"""Delete an agent"""
9494
result = await self._delete(path=f"/{self._module_name}/{agent_id}", response_cls=DeleteAgentResponse)
9595
assert result is not None # response_cls is provided, so result should never be None
96-
return result
96+
return result

ai21/models/agents/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@
2424
"RunAgentRequest",
2525
"RunResponse",
2626
"Visibility",
27-
]
27+
]

ai21/models/agents/agent.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,4 @@ class RunResponse(AI21BaseModel):
105105
status: str # "completed", "failed", "in_progress", "requires_action"
106106
result: Optional[Any] = None
107107
data_sources: Optional[Dict[str, Any]] = None
108-
requirements_result: Optional[Dict[str, Any]] = None
108+
requirements_result: Optional[Dict[str, Any]] = None

tests/integration_tests/clients/studio/test_agents.py

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,25 @@
88
async def test_agents_create_and_delete():
99
"""Test creating and deleting an agent"""
1010
client = AsyncAI21Client()
11-
11+
1212
# Create an agent
1313
create_request = CreateAgentRequest(
1414
name="Test Agent for Integration",
1515
description="This is a test agent created by integration tests",
1616
budget=BudgetLevel.LOW,
1717
agent_type=AgentType.DEFAULT,
1818
)
19-
19+
2020
agent = await client.beta.agents.create(request=create_request)
21-
21+
2222
# Verify agent was created
2323
assert agent.id is not None
2424
assert agent.name == "Test Agent for Integration"
2525
assert agent.description == "This is a test agent created by integration tests"
2626
assert agent.budget == BudgetLevel.LOW
2727
assert agent.agent_type == AgentType.DEFAULT
2828
assert agent.object == "agent"
29-
29+
3030
# Clean up - delete the agent
3131
delete_response = await client.beta.agents.delete(agent.id)
3232
assert delete_response.deleted is True
@@ -37,39 +37,39 @@ async def test_agents_create_and_delete():
3737
async def test_agents_crud_operations():
3838
"""Test full CRUD operations for agents"""
3939
client = AsyncAI21Client()
40-
40+
4141
# Create
4242
create_request = CreateAgentRequest(
4343
name="CRUD Test Agent",
4444
description="Testing CRUD operations",
4545
budget=BudgetLevel.MEDIUM,
4646
)
47-
47+
4848
agent = await client.beta.agents.create(request=create_request)
4949
agent_id = agent.id
50-
50+
5151
try:
5252
# Read - Get specific agent
5353
retrieved_agent = await client.beta.agents.get(agent_id)
5454
assert retrieved_agent.id == agent_id
5555
assert retrieved_agent.name == "CRUD Test Agent"
56-
56+
5757
# Read - List agents (should include our agent)
5858
agents_list = await client.beta.agents.list()
5959
agent_ids = [a.id for a in agents_list.results]
6060
assert agent_id in agent_ids
61-
61+
6262
# Update
6363
modify_request = ModifyAgentRequest(
6464
name="Modified CRUD Test Agent",
6565
description="Updated description for testing",
6666
)
67-
67+
6868
updated_agent = await client.beta.agents.modify(agent_id, request=modify_request)
6969
assert updated_agent.id == agent_id
7070
assert updated_agent.name == "Modified CRUD Test Agent"
7171
assert updated_agent.description == "Updated description for testing"
72-
72+
7373
finally:
7474
# Delete
7575
delete_response = await client.beta.agents.delete(agent_id)
@@ -80,38 +80,38 @@ async def test_agents_crud_operations():
8080
async def test_agent_run_basic():
8181
"""Test running an agent with basic input"""
8282
client = AsyncAI21Client()
83-
83+
8484
# Create a test agent
8585
create_request = CreateAgentRequest(
8686
name="Test Run Agent",
8787
description="Agent for testing runs",
8888
budget=BudgetLevel.LOW,
8989
)
90-
90+
9191
agent = await client.beta.agents.create(request=create_request)
9292
agent_id = agent.id
93-
93+
9494
try:
9595
# Test agent run
9696
input_messages = [{"role": "user", "content": "What is 2+2?"}]
97-
97+
9898
run_response = await client.beta.agents.runs.create_and_poll(
99-
agent_id,
99+
agent_id,
100100
input=input_messages,
101101
poll_timeout_sec=120, # 2 minutes timeout
102102
)
103-
103+
104104
assert run_response.id is not None
105105
assert run_response.status in ["completed", "failed"]
106-
106+
107107
if run_response.status == "completed":
108108
assert run_response.result is not None
109-
109+
110110
# Test retrieving the run
111111
retrieved_run = await client.beta.agents.runs.retrieve(str(run_response.id))
112112
assert retrieved_run.id == run_response.id
113113
assert retrieved_run.status == run_response.status
114-
114+
115115
finally:
116116
# Clean up
117117
await client.beta.agents.delete(agent_id)
@@ -121,21 +121,21 @@ async def test_agent_run_basic():
121121
async def test_agent_run_with_options():
122122
"""Test running an agent with various options"""
123123
client = AsyncAI21Client()
124-
124+
125125
# Create a test agent
126126
create_request = CreateAgentRequest(
127127
name="Test Options Agent",
128128
description="Agent for testing run options",
129129
budget=BudgetLevel.MEDIUM,
130130
)
131-
131+
132132
agent = await client.beta.agents.create(request=create_request)
133133
agent_id = agent.id
134-
134+
135135
try:
136136
# Test agent run with options
137137
input_messages = [{"role": "user", "content": "Tell me about AI"}]
138-
138+
139139
run_response = await client.beta.agents.runs.create_and_poll(
140140
agent_id,
141141
input=input_messages,
@@ -144,33 +144,33 @@ async def test_agent_run_with_options():
144144
response_language="english",
145145
poll_timeout_sec=120,
146146
)
147-
147+
148148
assert run_response.id is not None
149149
assert run_response.status in ["completed", "failed"]
150-
150+
151151
if run_response.status == "completed":
152152
assert run_response.result is not None
153-
153+
154154
finally:
155155
# Clean up
156156
await client.beta.agents.delete(agent_id)
157157

158158

159-
@pytest.mark.asyncio
159+
@pytest.mark.asyncio
160160
async def test_agents_list_empty_or_populated():
161161
"""Test listing agents when there may be none or some"""
162162
client = AsyncAI21Client()
163-
163+
164164
# List all agents
165165
agents_list = await client.beta.agents.list()
166-
166+
167167
# Should return a valid response
168-
assert hasattr(agents_list, 'results')
168+
assert hasattr(agents_list, "results")
169169
assert isinstance(agents_list.results, list)
170-
170+
171171
# Each result should be a proper Agent object
172172
for agent in agents_list.results:
173-
assert hasattr(agent, 'id')
174-
assert hasattr(agent, 'name')
175-
assert hasattr(agent, 'created_at')
176-
assert hasattr(agent, 'updated_at')
173+
assert hasattr(agent, "id")
174+
assert hasattr(agent, "name")
175+
assert hasattr(agent, "created_at")
176+
assert hasattr(agent, "updated_at")

0 commit comments

Comments
 (0)