88async 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():
3737async 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():
8080async 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():
121121async 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
160160async 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