agentex-sdk 0.1.0a6__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (289) hide show
  1. agentex/__init__.py +103 -0
  2. agentex/_base_client.py +1992 -0
  3. agentex/_client.py +506 -0
  4. agentex/_compat.py +219 -0
  5. agentex/_constants.py +14 -0
  6. agentex/_exceptions.py +108 -0
  7. agentex/_files.py +123 -0
  8. agentex/_models.py +829 -0
  9. agentex/_qs.py +150 -0
  10. agentex/_resource.py +43 -0
  11. agentex/_response.py +830 -0
  12. agentex/_streaming.py +333 -0
  13. agentex/_types.py +219 -0
  14. agentex/_utils/__init__.py +57 -0
  15. agentex/_utils/_logs.py +25 -0
  16. agentex/_utils/_proxy.py +65 -0
  17. agentex/_utils/_reflection.py +42 -0
  18. agentex/_utils/_resources_proxy.py +24 -0
  19. agentex/_utils/_streams.py +12 -0
  20. agentex/_utils/_sync.py +86 -0
  21. agentex/_utils/_transform.py +447 -0
  22. agentex/_utils/_typing.py +151 -0
  23. agentex/_utils/_utils.py +422 -0
  24. agentex/_version.py +4 -0
  25. agentex/lib/.keep +4 -0
  26. agentex/lib/__init__.py +0 -0
  27. agentex/lib/adk/__init__.py +41 -0
  28. agentex/lib/adk/_modules/__init__.py +0 -0
  29. agentex/lib/adk/_modules/acp.py +247 -0
  30. agentex/lib/adk/_modules/agent_task_tracker.py +176 -0
  31. agentex/lib/adk/_modules/agents.py +77 -0
  32. agentex/lib/adk/_modules/events.py +141 -0
  33. agentex/lib/adk/_modules/messages.py +285 -0
  34. agentex/lib/adk/_modules/state.py +291 -0
  35. agentex/lib/adk/_modules/streaming.py +75 -0
  36. agentex/lib/adk/_modules/tasks.py +124 -0
  37. agentex/lib/adk/_modules/tracing.py +194 -0
  38. agentex/lib/adk/providers/__init__.py +9 -0
  39. agentex/lib/adk/providers/_modules/__init__.py +0 -0
  40. agentex/lib/adk/providers/_modules/litellm.py +232 -0
  41. agentex/lib/adk/providers/_modules/openai.py +416 -0
  42. agentex/lib/adk/providers/_modules/sgp.py +85 -0
  43. agentex/lib/adk/utils/__init__.py +5 -0
  44. agentex/lib/adk/utils/_modules/__init__.py +0 -0
  45. agentex/lib/adk/utils/_modules/templating.py +94 -0
  46. agentex/lib/cli/__init__.py +0 -0
  47. agentex/lib/cli/commands/__init__.py +0 -0
  48. agentex/lib/cli/commands/agents.py +328 -0
  49. agentex/lib/cli/commands/init.py +227 -0
  50. agentex/lib/cli/commands/main.py +33 -0
  51. agentex/lib/cli/commands/secrets.py +169 -0
  52. agentex/lib/cli/commands/tasks.py +118 -0
  53. agentex/lib/cli/commands/uv.py +133 -0
  54. agentex/lib/cli/handlers/__init__.py +0 -0
  55. agentex/lib/cli/handlers/agent_handlers.py +160 -0
  56. agentex/lib/cli/handlers/cleanup_handlers.py +186 -0
  57. agentex/lib/cli/handlers/deploy_handlers.py +351 -0
  58. agentex/lib/cli/handlers/run_handlers.py +452 -0
  59. agentex/lib/cli/handlers/secret_handlers.py +670 -0
  60. agentex/lib/cli/templates/default/.dockerignore.j2 +43 -0
  61. agentex/lib/cli/templates/default/Dockerfile-uv.j2 +42 -0
  62. agentex/lib/cli/templates/default/Dockerfile.j2 +42 -0
  63. agentex/lib/cli/templates/default/README.md.j2 +193 -0
  64. agentex/lib/cli/templates/default/deploy/example.yaml.j2 +55 -0
  65. agentex/lib/cli/templates/default/manifest.yaml.j2 +116 -0
  66. agentex/lib/cli/templates/default/project/acp.py.j2 +29 -0
  67. agentex/lib/cli/templates/default/pyproject.toml.j2 +33 -0
  68. agentex/lib/cli/templates/default/requirements.txt.j2 +5 -0
  69. agentex/lib/cli/templates/deploy/Screenshot 2025-03-19 at 10.36.57/342/200/257AM.png +0 -0
  70. agentex/lib/cli/templates/deploy/example.yaml.j2 +55 -0
  71. agentex/lib/cli/templates/sync/.dockerignore.j2 +43 -0
  72. agentex/lib/cli/templates/sync/Dockerfile-uv.j2 +42 -0
  73. agentex/lib/cli/templates/sync/Dockerfile.j2 +42 -0
  74. agentex/lib/cli/templates/sync/README.md.j2 +293 -0
  75. agentex/lib/cli/templates/sync/deploy/example.yaml.j2 +55 -0
  76. agentex/lib/cli/templates/sync/manifest.yaml.j2 +116 -0
  77. agentex/lib/cli/templates/sync/project/acp.py.j2 +26 -0
  78. agentex/lib/cli/templates/sync/pyproject.toml.j2 +33 -0
  79. agentex/lib/cli/templates/sync/requirements.txt.j2 +5 -0
  80. agentex/lib/cli/templates/temporal/.dockerignore.j2 +43 -0
  81. agentex/lib/cli/templates/temporal/Dockerfile-uv.j2 +48 -0
  82. agentex/lib/cli/templates/temporal/Dockerfile.j2 +48 -0
  83. agentex/lib/cli/templates/temporal/README.md.j2 +316 -0
  84. agentex/lib/cli/templates/temporal/deploy/example.yaml.j2 +55 -0
  85. agentex/lib/cli/templates/temporal/manifest.yaml.j2 +137 -0
  86. agentex/lib/cli/templates/temporal/project/acp.py.j2 +30 -0
  87. agentex/lib/cli/templates/temporal/project/run_worker.py.j2 +33 -0
  88. agentex/lib/cli/templates/temporal/project/workflow.py.j2 +66 -0
  89. agentex/lib/cli/templates/temporal/pyproject.toml.j2 +34 -0
  90. agentex/lib/cli/templates/temporal/requirements.txt.j2 +5 -0
  91. agentex/lib/cli/utils/cli_utils.py +14 -0
  92. agentex/lib/cli/utils/credential_utils.py +103 -0
  93. agentex/lib/cli/utils/exceptions.py +6 -0
  94. agentex/lib/cli/utils/kubectl_utils.py +135 -0
  95. agentex/lib/cli/utils/kubernetes_secrets_utils.py +185 -0
  96. agentex/lib/core/__init__.py +0 -0
  97. agentex/lib/core/adapters/__init__.py +0 -0
  98. agentex/lib/core/adapters/llm/__init__.py +1 -0
  99. agentex/lib/core/adapters/llm/adapter_litellm.py +46 -0
  100. agentex/lib/core/adapters/llm/adapter_sgp.py +55 -0
  101. agentex/lib/core/adapters/llm/port.py +24 -0
  102. agentex/lib/core/adapters/streams/adapter_redis.py +128 -0
  103. agentex/lib/core/adapters/streams/port.py +50 -0
  104. agentex/lib/core/clients/__init__.py +1 -0
  105. agentex/lib/core/clients/temporal/__init__.py +0 -0
  106. agentex/lib/core/clients/temporal/temporal_client.py +181 -0
  107. agentex/lib/core/clients/temporal/types.py +47 -0
  108. agentex/lib/core/clients/temporal/utils.py +56 -0
  109. agentex/lib/core/services/__init__.py +0 -0
  110. agentex/lib/core/services/adk/__init__.py +0 -0
  111. agentex/lib/core/services/adk/acp/__init__.py +0 -0
  112. agentex/lib/core/services/adk/acp/acp.py +210 -0
  113. agentex/lib/core/services/adk/agent_task_tracker.py +85 -0
  114. agentex/lib/core/services/adk/agents.py +43 -0
  115. agentex/lib/core/services/adk/events.py +61 -0
  116. agentex/lib/core/services/adk/messages.py +164 -0
  117. agentex/lib/core/services/adk/providers/__init__.py +0 -0
  118. agentex/lib/core/services/adk/providers/litellm.py +256 -0
  119. agentex/lib/core/services/adk/providers/openai.py +723 -0
  120. agentex/lib/core/services/adk/providers/sgp.py +99 -0
  121. agentex/lib/core/services/adk/state.py +120 -0
  122. agentex/lib/core/services/adk/streaming.py +262 -0
  123. agentex/lib/core/services/adk/tasks.py +69 -0
  124. agentex/lib/core/services/adk/tracing.py +36 -0
  125. agentex/lib/core/services/adk/utils/__init__.py +0 -0
  126. agentex/lib/core/services/adk/utils/templating.py +58 -0
  127. agentex/lib/core/temporal/__init__.py +0 -0
  128. agentex/lib/core/temporal/activities/__init__.py +207 -0
  129. agentex/lib/core/temporal/activities/activity_helpers.py +37 -0
  130. agentex/lib/core/temporal/activities/adk/__init__.py +0 -0
  131. agentex/lib/core/temporal/activities/adk/acp/__init__.py +0 -0
  132. agentex/lib/core/temporal/activities/adk/acp/acp_activities.py +86 -0
  133. agentex/lib/core/temporal/activities/adk/agent_task_tracker_activities.py +76 -0
  134. agentex/lib/core/temporal/activities/adk/agents_activities.py +35 -0
  135. agentex/lib/core/temporal/activities/adk/events_activities.py +50 -0
  136. agentex/lib/core/temporal/activities/adk/messages_activities.py +94 -0
  137. agentex/lib/core/temporal/activities/adk/providers/__init__.py +0 -0
  138. agentex/lib/core/temporal/activities/adk/providers/litellm_activities.py +71 -0
  139. agentex/lib/core/temporal/activities/adk/providers/openai_activities.py +210 -0
  140. agentex/lib/core/temporal/activities/adk/providers/sgp_activities.py +42 -0
  141. agentex/lib/core/temporal/activities/adk/state_activities.py +85 -0
  142. agentex/lib/core/temporal/activities/adk/streaming_activities.py +33 -0
  143. agentex/lib/core/temporal/activities/adk/tasks_activities.py +48 -0
  144. agentex/lib/core/temporal/activities/adk/tracing_activities.py +55 -0
  145. agentex/lib/core/temporal/activities/adk/utils/__init__.py +0 -0
  146. agentex/lib/core/temporal/activities/adk/utils/templating_activities.py +41 -0
  147. agentex/lib/core/temporal/services/__init__.py +0 -0
  148. agentex/lib/core/temporal/services/temporal_task_service.py +69 -0
  149. agentex/lib/core/temporal/types/__init__.py +0 -0
  150. agentex/lib/core/temporal/types/workflow.py +5 -0
  151. agentex/lib/core/temporal/workers/__init__.py +0 -0
  152. agentex/lib/core/temporal/workers/worker.py +162 -0
  153. agentex/lib/core/temporal/workflows/workflow.py +26 -0
  154. agentex/lib/core/tracing/__init__.py +5 -0
  155. agentex/lib/core/tracing/processors/agentex_tracing_processor.py +117 -0
  156. agentex/lib/core/tracing/processors/sgp_tracing_processor.py +119 -0
  157. agentex/lib/core/tracing/processors/tracing_processor_interface.py +40 -0
  158. agentex/lib/core/tracing/trace.py +311 -0
  159. agentex/lib/core/tracing/tracer.py +70 -0
  160. agentex/lib/core/tracing/tracing_processor_manager.py +62 -0
  161. agentex/lib/environment_variables.py +87 -0
  162. agentex/lib/py.typed +0 -0
  163. agentex/lib/sdk/__init__.py +0 -0
  164. agentex/lib/sdk/config/__init__.py +0 -0
  165. agentex/lib/sdk/config/agent_config.py +61 -0
  166. agentex/lib/sdk/config/agent_manifest.py +219 -0
  167. agentex/lib/sdk/config/build_config.py +35 -0
  168. agentex/lib/sdk/config/deployment_config.py +117 -0
  169. agentex/lib/sdk/config/local_development_config.py +56 -0
  170. agentex/lib/sdk/config/project_config.py +103 -0
  171. agentex/lib/sdk/fastacp/__init__.py +3 -0
  172. agentex/lib/sdk/fastacp/base/base_acp_server.py +406 -0
  173. agentex/lib/sdk/fastacp/fastacp.py +74 -0
  174. agentex/lib/sdk/fastacp/impl/agentic_base_acp.py +72 -0
  175. agentex/lib/sdk/fastacp/impl/sync_acp.py +109 -0
  176. agentex/lib/sdk/fastacp/impl/temporal_acp.py +97 -0
  177. agentex/lib/sdk/fastacp/tests/README.md +297 -0
  178. agentex/lib/sdk/fastacp/tests/conftest.py +307 -0
  179. agentex/lib/sdk/fastacp/tests/pytest.ini +10 -0
  180. agentex/lib/sdk/fastacp/tests/run_tests.py +227 -0
  181. agentex/lib/sdk/fastacp/tests/test_base_acp_server.py +450 -0
  182. agentex/lib/sdk/fastacp/tests/test_fastacp_factory.py +344 -0
  183. agentex/lib/sdk/fastacp/tests/test_integration.py +477 -0
  184. agentex/lib/sdk/state_machine/__init__.py +6 -0
  185. agentex/lib/sdk/state_machine/noop_workflow.py +21 -0
  186. agentex/lib/sdk/state_machine/state.py +10 -0
  187. agentex/lib/sdk/state_machine/state_machine.py +189 -0
  188. agentex/lib/sdk/state_machine/state_workflow.py +16 -0
  189. agentex/lib/sdk/utils/__init__.py +0 -0
  190. agentex/lib/sdk/utils/messages.py +223 -0
  191. agentex/lib/types/__init__.py +0 -0
  192. agentex/lib/types/acp.py +94 -0
  193. agentex/lib/types/agent_configs.py +79 -0
  194. agentex/lib/types/agent_results.py +29 -0
  195. agentex/lib/types/credentials.py +34 -0
  196. agentex/lib/types/fastacp.py +61 -0
  197. agentex/lib/types/files.py +13 -0
  198. agentex/lib/types/json_rpc.py +49 -0
  199. agentex/lib/types/llm_messages.py +354 -0
  200. agentex/lib/types/task_message_updates.py +171 -0
  201. agentex/lib/types/tracing.py +34 -0
  202. agentex/lib/utils/__init__.py +0 -0
  203. agentex/lib/utils/completions.py +131 -0
  204. agentex/lib/utils/console.py +14 -0
  205. agentex/lib/utils/io.py +29 -0
  206. agentex/lib/utils/iterables.py +14 -0
  207. agentex/lib/utils/json_schema.py +23 -0
  208. agentex/lib/utils/logging.py +31 -0
  209. agentex/lib/utils/mcp.py +17 -0
  210. agentex/lib/utils/model_utils.py +46 -0
  211. agentex/lib/utils/parsing.py +15 -0
  212. agentex/lib/utils/regex.py +6 -0
  213. agentex/lib/utils/temporal.py +13 -0
  214. agentex/py.typed +0 -0
  215. agentex/resources/__init__.py +103 -0
  216. agentex/resources/agents.py +707 -0
  217. agentex/resources/events.py +294 -0
  218. agentex/resources/messages/__init__.py +33 -0
  219. agentex/resources/messages/batch.py +271 -0
  220. agentex/resources/messages/messages.py +492 -0
  221. agentex/resources/spans.py +557 -0
  222. agentex/resources/states.py +544 -0
  223. agentex/resources/tasks.py +615 -0
  224. agentex/resources/tracker.py +384 -0
  225. agentex/types/__init__.py +56 -0
  226. agentex/types/acp_type.py +7 -0
  227. agentex/types/agent.py +29 -0
  228. agentex/types/agent_list_params.py +13 -0
  229. agentex/types/agent_list_response.py +10 -0
  230. agentex/types/agent_rpc_by_name_params.py +21 -0
  231. agentex/types/agent_rpc_params.py +51 -0
  232. agentex/types/agent_rpc_params1.py +21 -0
  233. agentex/types/agent_rpc_response.py +20 -0
  234. agentex/types/agent_rpc_result.py +90 -0
  235. agentex/types/agent_task_tracker.py +34 -0
  236. agentex/types/data_content.py +30 -0
  237. agentex/types/data_content_param.py +31 -0
  238. agentex/types/data_delta.py +14 -0
  239. agentex/types/event.py +29 -0
  240. agentex/types/event_list_params.py +22 -0
  241. agentex/types/event_list_response.py +10 -0
  242. agentex/types/message_author.py +7 -0
  243. agentex/types/message_create_params.py +18 -0
  244. agentex/types/message_list_params.py +14 -0
  245. agentex/types/message_list_response.py +10 -0
  246. agentex/types/message_style.py +7 -0
  247. agentex/types/message_update_params.py +18 -0
  248. agentex/types/messages/__init__.py +8 -0
  249. agentex/types/messages/batch_create_params.py +16 -0
  250. agentex/types/messages/batch_create_response.py +10 -0
  251. agentex/types/messages/batch_update_params.py +16 -0
  252. agentex/types/messages/batch_update_response.py +10 -0
  253. agentex/types/shared/__init__.py +3 -0
  254. agentex/types/shared/task_message_update.py +83 -0
  255. agentex/types/span.py +36 -0
  256. agentex/types/span_create_params.py +40 -0
  257. agentex/types/span_list_params.py +12 -0
  258. agentex/types/span_list_response.py +10 -0
  259. agentex/types/span_update_params.py +37 -0
  260. agentex/types/state.py +25 -0
  261. agentex/types/state_create_params.py +16 -0
  262. agentex/types/state_list_params.py +16 -0
  263. agentex/types/state_list_response.py +10 -0
  264. agentex/types/state_update_params.py +16 -0
  265. agentex/types/task.py +23 -0
  266. agentex/types/task_delete_by_name_response.py +8 -0
  267. agentex/types/task_delete_response.py +8 -0
  268. agentex/types/task_list_response.py +10 -0
  269. agentex/types/task_message.py +33 -0
  270. agentex/types/task_message_content.py +16 -0
  271. agentex/types/task_message_content_param.py +17 -0
  272. agentex/types/task_message_delta.py +16 -0
  273. agentex/types/text_content.py +53 -0
  274. agentex/types/text_content_param.py +54 -0
  275. agentex/types/text_delta.py +14 -0
  276. agentex/types/tool_request_content.py +36 -0
  277. agentex/types/tool_request_content_param.py +37 -0
  278. agentex/types/tool_request_delta.py +18 -0
  279. agentex/types/tool_response_content.py +36 -0
  280. agentex/types/tool_response_content_param.py +36 -0
  281. agentex/types/tool_response_delta.py +18 -0
  282. agentex/types/tracker_list_params.py +16 -0
  283. agentex/types/tracker_list_response.py +10 -0
  284. agentex/types/tracker_update_params.py +19 -0
  285. agentex_sdk-0.1.0a6.dist-info/METADATA +426 -0
  286. agentex_sdk-0.1.0a6.dist-info/RECORD +289 -0
  287. agentex_sdk-0.1.0a6.dist-info/WHEEL +4 -0
  288. agentex_sdk-0.1.0a6.dist-info/entry_points.txt +2 -0
  289. agentex_sdk-0.1.0a6.dist-info/licenses/LICENSE +201 -0
@@ -0,0 +1,426 @@
1
+ Metadata-Version: 2.3
2
+ Name: agentex-sdk
3
+ Version: 0.1.0a6
4
+ Summary: The official Python library for the agentex API
5
+ Project-URL: Homepage, https://github.com/scaleapi/agentex-python
6
+ Project-URL: Repository, https://github.com/scaleapi/agentex-python
7
+ Author: Agentex
8
+ License: Apache-2.0
9
+ Classifier: Intended Audience :: Developers
10
+ Classifier: License :: OSI Approved :: Apache Software License
11
+ Classifier: Operating System :: MacOS
12
+ Classifier: Operating System :: Microsoft :: Windows
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Operating System :: POSIX
15
+ Classifier: Operating System :: POSIX :: Linux
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Programming Language :: Python :: 3.14
19
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
20
+ Classifier: Typing :: Typed
21
+ Requires-Python: <4,>=3.12
22
+ Requires-Dist: aiohttp<4,>=3.10.10
23
+ Requires-Dist: anyio<5,>=3.5.0
24
+ Requires-Dist: distro<2,>=1.7.0
25
+ Requires-Dist: fastapi<0.116,>=0.115.0
26
+ Requires-Dist: httpx<0.28,>=0.27.2
27
+ Requires-Dist: ipykernel>=6.29.5
28
+ Requires-Dist: jinja2<4,>=3.1.3
29
+ Requires-Dist: jsonref<2,>=1.1.0
30
+ Requires-Dist: jsonschema<5,>=4.23.0
31
+ Requires-Dist: kubernetes<29.0.0,>=25.0.0
32
+ Requires-Dist: litellm<2,>=1.66.0
33
+ Requires-Dist: mcp[cli]>=1.4.1
34
+ Requires-Dist: openai-agents>=0.0.7
35
+ Requires-Dist: pydantic<3,>=2.0.0
36
+ Requires-Dist: pytest-asyncio>=1.0.0
37
+ Requires-Dist: pytest>=8.4.0
38
+ Requires-Dist: python-on-whales<0.74,>=0.73.0
39
+ Requires-Dist: pyyaml<7,>=6.0.2
40
+ Requires-Dist: questionary<3,>=2.0.1
41
+ Requires-Dist: redis<6,>=5.2.0
42
+ Requires-Dist: rich<14,>=13.9.2
43
+ Requires-Dist: scale-gp-beta==0.1.0a20
44
+ Requires-Dist: scale-gp>=0.1.0a59
45
+ Requires-Dist: sniffio
46
+ Requires-Dist: temporalio<2,>=1.10.0
47
+ Requires-Dist: typer<0.17,>=0.16
48
+ Requires-Dist: typing-extensions<5,>=4.10
49
+ Requires-Dist: tzdata>=2025.2
50
+ Requires-Dist: tzlocal>=5.3.1
51
+ Requires-Dist: uvicorn>=0.31.1
52
+ Requires-Dist: watchfiles<1.0,>=0.24.0
53
+ Provides-Extra: aiohttp
54
+ Requires-Dist: aiohttp; extra == 'aiohttp'
55
+ Requires-Dist: httpx-aiohttp>=0.1.8; extra == 'aiohttp'
56
+ Provides-Extra: dev
57
+ Requires-Dist: ruff>=0.3.4; extra == 'dev'
58
+ Description-Content-Type: text/markdown
59
+
60
+ # Agentex Python API library
61
+
62
+ <!-- prettier-ignore -->
63
+ [![PyPI version](https://img.shields.io/pypi/v/agentex-sdk.svg?label=pypi%20(stable))](https://pypi.org/project/agentex-sdk/)
64
+
65
+ The Agentex Python library provides convenient access to the Agentex REST API from any Python 3.8+
66
+ application. The library includes type definitions for all request params and response fields,
67
+ and offers both synchronous and asynchronous clients powered by [httpx](https://github.com/encode/httpx).
68
+
69
+ It is generated with [Stainless](https://www.stainless.com/).
70
+
71
+ ## Documentation
72
+
73
+ The full API of this library can be found in [api.md](https://github.com/scaleapi/agentex-python/tree/main/api.md).
74
+
75
+ ## Installation
76
+
77
+ ```sh
78
+ # install from the production repo
79
+ pip install git+ssh://git@github.com/scaleapi/agentex-python.git
80
+ ```
81
+
82
+ > [!NOTE]
83
+ > Once this package is [published to PyPI](https://www.stainless.com/docs/guides/publish), this will become: `pip install --pre agentex-sdk`
84
+
85
+ ## Usage
86
+
87
+ The full API of this library can be found in [api.md](https://github.com/scaleapi/agentex-python/tree/main/api.md).
88
+
89
+ ```python
90
+ import os
91
+ from agentex import Agentex
92
+
93
+ client = Agentex(
94
+ api_key=os.environ.get("AGENTEX_SDK_API_KEY"), # This is the default and can be omitted
95
+ # defaults to "production".
96
+ environment="development",
97
+ )
98
+
99
+ tasks = client.tasks.list()
100
+ ```
101
+
102
+ While you can provide an `api_key` keyword argument,
103
+ we recommend using [python-dotenv](https://pypi.org/project/python-dotenv/)
104
+ to add `AGENTEX_SDK_API_KEY="My API Key"` to your `.env` file
105
+ so that your API Key is not stored in source control.
106
+
107
+ ## Async usage
108
+
109
+ Simply import `AsyncAgentex` instead of `Agentex` and use `await` with each API call:
110
+
111
+ ```python
112
+ import os
113
+ import asyncio
114
+ from agentex import AsyncAgentex
115
+
116
+ client = AsyncAgentex(
117
+ api_key=os.environ.get("AGENTEX_SDK_API_KEY"), # This is the default and can be omitted
118
+ # defaults to "production".
119
+ environment="development",
120
+ )
121
+
122
+
123
+ async def main() -> None:
124
+ tasks = await client.tasks.list()
125
+
126
+
127
+ asyncio.run(main())
128
+ ```
129
+
130
+ Functionality between the synchronous and asynchronous clients is otherwise identical.
131
+
132
+ ### With aiohttp
133
+
134
+ By default, the async client uses `httpx` for HTTP requests. However, for improved concurrency performance you may also use `aiohttp` as the HTTP backend.
135
+
136
+ You can enable this by installing `aiohttp`:
137
+
138
+ ```sh
139
+ # install from the production repo
140
+ pip install 'agentex-sdk[aiohttp] @ git+ssh://git@github.com/scaleapi/agentex-python.git'
141
+ ```
142
+
143
+ Then you can enable it by instantiating the client with `http_client=DefaultAioHttpClient()`:
144
+
145
+ ```python
146
+ import asyncio
147
+ from agentex import DefaultAioHttpClient
148
+ from agentex import AsyncAgentex
149
+
150
+
151
+ async def main() -> None:
152
+ async with AsyncAgentex(
153
+ api_key="My API Key",
154
+ http_client=DefaultAioHttpClient(),
155
+ ) as client:
156
+ tasks = await client.tasks.list()
157
+
158
+
159
+ asyncio.run(main())
160
+ ```
161
+
162
+ ## Using types
163
+
164
+ Nested request parameters are [TypedDicts](https://docs.python.org/3/library/typing.html#typing.TypedDict). Responses are [Pydantic models](https://docs.pydantic.dev) which also provide helper methods for things like:
165
+
166
+ - Serializing back into JSON, `model.to_json()`
167
+ - Converting to a dictionary, `model.to_dict()`
168
+
169
+ Typed requests and responses provide autocomplete and documentation within your editor. If you would like to see type errors in VS Code to help catch bugs earlier, set `python.analysis.typeCheckingMode` to `basic`.
170
+
171
+ ## Handling errors
172
+
173
+ When the library is unable to connect to the API (for example, due to network connection problems or a timeout), a subclass of `agentex.APIConnectionError` is raised.
174
+
175
+ When the API returns a non-success status code (that is, 4xx or 5xx
176
+ response), a subclass of `agentex.APIStatusError` is raised, containing `status_code` and `response` properties.
177
+
178
+ All errors inherit from `agentex.APIError`.
179
+
180
+ ```python
181
+ import agentex
182
+ from agentex import Agentex
183
+
184
+ client = Agentex()
185
+
186
+ try:
187
+ client.tasks.list()
188
+ except agentex.APIConnectionError as e:
189
+ print("The server could not be reached")
190
+ print(e.__cause__) # an underlying Exception, likely raised within httpx.
191
+ except agentex.RateLimitError as e:
192
+ print("A 429 status code was received; we should back off a bit.")
193
+ except agentex.APIStatusError as e:
194
+ print("Another non-200-range status code was received")
195
+ print(e.status_code)
196
+ print(e.response)
197
+ ```
198
+
199
+ Error codes are as follows:
200
+
201
+ | Status Code | Error Type |
202
+ | ----------- | -------------------------- |
203
+ | 400 | `BadRequestError` |
204
+ | 401 | `AuthenticationError` |
205
+ | 403 | `PermissionDeniedError` |
206
+ | 404 | `NotFoundError` |
207
+ | 422 | `UnprocessableEntityError` |
208
+ | 429 | `RateLimitError` |
209
+ | >=500 | `InternalServerError` |
210
+ | N/A | `APIConnectionError` |
211
+
212
+ ### Retries
213
+
214
+ Certain errors are automatically retried 2 times by default, with a short exponential backoff.
215
+ Connection errors (for example, due to a network connectivity problem), 408 Request Timeout, 409 Conflict,
216
+ 429 Rate Limit, and >=500 Internal errors are all retried by default.
217
+
218
+ You can use the `max_retries` option to configure or disable retry settings:
219
+
220
+ ```python
221
+ from agentex import Agentex
222
+
223
+ # Configure the default for all requests:
224
+ client = Agentex(
225
+ # default is 2
226
+ max_retries=0,
227
+ )
228
+
229
+ # Or, configure per-request:
230
+ client.with_options(max_retries=5).tasks.list()
231
+ ```
232
+
233
+ ### Timeouts
234
+
235
+ By default requests time out after 1 minute. You can configure this with a `timeout` option,
236
+ which accepts a float or an [`httpx.Timeout`](https://www.python-httpx.org/advanced/timeouts/#fine-tuning-the-configuration) object:
237
+
238
+ ```python
239
+ from agentex import Agentex
240
+
241
+ # Configure the default for all requests:
242
+ client = Agentex(
243
+ # 20 seconds (default is 1 minute)
244
+ timeout=20.0,
245
+ )
246
+
247
+ # More granular control:
248
+ client = Agentex(
249
+ timeout=httpx.Timeout(60.0, read=5.0, write=10.0, connect=2.0),
250
+ )
251
+
252
+ # Override per-request:
253
+ client.with_options(timeout=5.0).tasks.list()
254
+ ```
255
+
256
+ On timeout, an `APITimeoutError` is thrown.
257
+
258
+ Note that requests that time out are [retried twice by default](https://github.com/scaleapi/agentex-python/tree/main/#retries).
259
+
260
+ ## Advanced
261
+
262
+ ### Logging
263
+
264
+ We use the standard library [`logging`](https://docs.python.org/3/library/logging.html) module.
265
+
266
+ You can enable logging by setting the environment variable `AGENTEX_LOG` to `info`.
267
+
268
+ ```shell
269
+ $ export AGENTEX_LOG=info
270
+ ```
271
+
272
+ Or to `debug` for more verbose logging.
273
+
274
+ ### How to tell whether `None` means `null` or missing
275
+
276
+ In an API response, a field may be explicitly `null`, or missing entirely; in either case, its value is `None` in this library. You can differentiate the two cases with `.model_fields_set`:
277
+
278
+ ```py
279
+ if response.my_field is None:
280
+ if 'my_field' not in response.model_fields_set:
281
+ print('Got json like {}, without a "my_field" key present at all.')
282
+ else:
283
+ print('Got json like {"my_field": null}.')
284
+ ```
285
+
286
+ ### Accessing raw response data (e.g. headers)
287
+
288
+ The "raw" Response object can be accessed by prefixing `.with_raw_response.` to any HTTP method call, e.g.,
289
+
290
+ ```py
291
+ from agentex import Agentex
292
+
293
+ client = Agentex()
294
+ response = client.tasks.with_raw_response.list()
295
+ print(response.headers.get('X-My-Header'))
296
+
297
+ task = response.parse() # get the object that `tasks.list()` would have returned
298
+ print(task)
299
+ ```
300
+
301
+ These methods return an [`APIResponse`](https://github.com/scaleapi/agentex-python/tree/main/src/agentex/_response.py) object.
302
+
303
+ The async client returns an [`AsyncAPIResponse`](https://github.com/scaleapi/agentex-python/tree/main/src/agentex/_response.py) with the same structure, the only difference being `await`able methods for reading the response content.
304
+
305
+ #### `.with_streaming_response`
306
+
307
+ The above interface eagerly reads the full response body when you make the request, which may not always be what you want.
308
+
309
+ To stream the response body, use `.with_streaming_response` instead, which requires a context manager and only reads the response body once you call `.read()`, `.text()`, `.json()`, `.iter_bytes()`, `.iter_text()`, `.iter_lines()` or `.parse()`. In the async client, these are async methods.
310
+
311
+ ```python
312
+ with client.tasks.with_streaming_response.list() as response:
313
+ print(response.headers.get("X-My-Header"))
314
+
315
+ for line in response.iter_lines():
316
+ print(line)
317
+ ```
318
+
319
+ The context manager is required so that the response will reliably be closed.
320
+
321
+ ### Making custom/undocumented requests
322
+
323
+ This library is typed for convenient access to the documented API.
324
+
325
+ If you need to access undocumented endpoints, params, or response properties, the library can still be used.
326
+
327
+ #### Undocumented endpoints
328
+
329
+ To make requests to undocumented endpoints, you can make requests using `client.get`, `client.post`, and other
330
+ http verbs. Options on the client will be respected (such as retries) when making this request.
331
+
332
+ ```py
333
+ import httpx
334
+
335
+ response = client.post(
336
+ "/foo",
337
+ cast_to=httpx.Response,
338
+ body={"my_param": True},
339
+ )
340
+
341
+ print(response.headers.get("x-foo"))
342
+ ```
343
+
344
+ #### Undocumented request params
345
+
346
+ If you want to explicitly send an extra param, you can do so with the `extra_query`, `extra_body`, and `extra_headers` request
347
+ options.
348
+
349
+ #### Undocumented response properties
350
+
351
+ To access undocumented response properties, you can access the extra fields like `response.unknown_prop`. You
352
+ can also get all the extra fields on the Pydantic model as a dict with
353
+ [`response.model_extra`](https://docs.pydantic.dev/latest/api/base_model/#pydantic.BaseModel.model_extra).
354
+
355
+ ### Configuring the HTTP client
356
+
357
+ You can directly override the [httpx client](https://www.python-httpx.org/api/#client) to customize it for your use case, including:
358
+
359
+ - Support for [proxies](https://www.python-httpx.org/advanced/proxies/)
360
+ - Custom [transports](https://www.python-httpx.org/advanced/transports/)
361
+ - Additional [advanced](https://www.python-httpx.org/advanced/clients/) functionality
362
+
363
+ ```python
364
+ import httpx
365
+ from agentex import Agentex, DefaultHttpxClient
366
+
367
+ client = Agentex(
368
+ # Or use the `AGENTEX_BASE_URL` env var
369
+ base_url="http://my.test.server.example.com:8083",
370
+ http_client=DefaultHttpxClient(
371
+ proxy="http://my.test.proxy.example.com",
372
+ transport=httpx.HTTPTransport(local_address="0.0.0.0"),
373
+ ),
374
+ )
375
+ ```
376
+
377
+ You can also customize the client on a per-request basis by using `with_options()`:
378
+
379
+ ```python
380
+ client.with_options(http_client=DefaultHttpxClient(...))
381
+ ```
382
+
383
+ ### Managing HTTP resources
384
+
385
+ By default the library closes underlying HTTP connections whenever the client is [garbage collected](https://docs.python.org/3/reference/datamodel.html#object.__del__). You can manually close the client using the `.close()` method if desired, or with a context manager that closes when exiting.
386
+
387
+ ```py
388
+ from agentex import Agentex
389
+
390
+ with Agentex() as client:
391
+ # make requests here
392
+ ...
393
+
394
+ # HTTP client is now closed
395
+ ```
396
+
397
+ ## Versioning
398
+
399
+ This package generally follows [SemVer](https://semver.org/spec/v2.0.0.html) conventions, though certain backwards-incompatible changes may be released as minor versions:
400
+
401
+ 1. Changes that only affect static types, without breaking runtime behavior.
402
+ 2. Changes to library internals which are technically public but not intended or documented for external use. _(Please open a GitHub issue to let us know if you are relying on such internals.)_
403
+ 3. Changes that we do not expect to impact the vast majority of users in practice.
404
+
405
+ We take backwards-compatibility seriously and work hard to ensure you can rely on a smooth upgrade experience.
406
+
407
+ We are keen for your feedback; please open an [issue](https://www.github.com/scaleapi/agentex-python/issues) with questions, bugs, or suggestions.
408
+
409
+ ### Determining the installed version
410
+
411
+ If you've upgraded to the latest version but aren't seeing any new features you were expecting then your python environment is likely still using an older version.
412
+
413
+ You can determine the version that is being used at runtime with:
414
+
415
+ ```py
416
+ import agentex
417
+ print(agentex.__version__)
418
+ ```
419
+
420
+ ## Requirements
421
+
422
+ Python 3.8 or higher.
423
+
424
+ ## Contributing
425
+
426
+ See [the contributing documentation](https://github.com/scaleapi/agentex-python/tree/main/./CONTRIBUTING.md).