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,131 @@
1
+ from copy import deepcopy
2
+ from functools import reduce, singledispatch
3
+ from typing import Any
4
+
5
+ from agentex.lib.types.llm_messages import (
6
+ Choice,
7
+ Completion,
8
+ Delta,
9
+ ToolCall,
10
+ ToolCallRequest,
11
+ )
12
+
13
+
14
+ @singledispatch
15
+ def _concat_chunks(a: None, b: Any):
16
+ return b
17
+
18
+
19
+ @_concat_chunks.register
20
+ def _(a: Completion, b: Completion) -> Completion:
21
+ a.choices = [_concat_chunks(*c) for c in zip(a.choices, b.choices, strict=False)]
22
+ return a
23
+
24
+
25
+ @_concat_chunks.register
26
+ def _(a: Choice, b: Choice) -> Choice:
27
+ if hasattr(a, "index") and hasattr(b, "index"):
28
+ assert a.index == b.index
29
+
30
+ if hasattr(a, "delta") and hasattr(b, "delta"):
31
+ a.delta = _concat_chunks(a.delta, b.delta)
32
+
33
+ a.finish_reason = a.finish_reason or b.finish_reason
34
+ return a
35
+
36
+
37
+ @_concat_chunks.register
38
+ def _(a: Delta, b: Delta) -> Delta:
39
+ a.content = a.content + b.content if a.content and b.content else a.content or b.content
40
+
41
+ if hasattr(a, "tool_calls") and hasattr(b, "tool_calls") and a.tool_calls and b.tool_calls:
42
+ # Group tool calls by index
43
+ grouped_tool_calls = {}
44
+ for tool_call in a.tool_calls + b.tool_calls:
45
+ if tool_call.index not in grouped_tool_calls:
46
+ grouped_tool_calls[tool_call.index] = tool_call
47
+ else:
48
+ grouped_tool_calls[tool_call.index] = _concat_chunks(
49
+ grouped_tool_calls[tool_call.index], tool_call
50
+ )
51
+
52
+ a.tool_calls = list(grouped_tool_calls.values())
53
+ elif hasattr(b, "tool_calls") and b.tool_calls:
54
+ a.tool_calls = b.tool_calls
55
+
56
+ return a
57
+
58
+
59
+ @_concat_chunks.register
60
+ def _(a: ToolCallRequest, b: ToolCallRequest) -> ToolCallRequest:
61
+ # Preserve id from either a or b, with preference for a
62
+ id_val = a.id if a.id is not None else b.id
63
+
64
+ # Use index from either a or b, with preference for a's index
65
+ index_val = a.index if hasattr(a, "index") and a.index is not None else b.index
66
+
67
+ # Concatenate the function part
68
+ function_val = (
69
+ _concat_chunks(a.function, b.function)
70
+ if a.function and b.function
71
+ else a.function or b.function
72
+ )
73
+
74
+ # Set all properties
75
+ a.id = id_val
76
+ a.index = index_val
77
+ a.function = function_val
78
+
79
+ return a
80
+
81
+
82
+ @_concat_chunks.register
83
+ def _(a: ToolCall, b: ToolCall) -> ToolCall:
84
+ # Preserve name from either a or b, with preference for a
85
+ name_val = a.name or b.name
86
+
87
+ # Concatenate arguments string
88
+ args_val = ""
89
+ if a.arguments is not None and b.arguments is not None:
90
+ args_val = a.arguments + b.arguments
91
+ else:
92
+ args_val = a.arguments or b.arguments
93
+
94
+ # Set all properties
95
+ a.name = name_val
96
+ a.arguments = args_val
97
+
98
+ return a
99
+
100
+
101
+ def concat_completion_chunks(chunks: list[Completion]) -> Completion:
102
+ """
103
+ Accumulates all chunks returned from a streaming completion call into a `Completion` message.
104
+ This is useful when you stream responses from an LLM and want to keep track of the context (i.e. previous messages + current message).
105
+
106
+ Args:
107
+ chunks: list of completion chunks returned from streamed completion
108
+ Returns:
109
+ Completion: same as type returned from non-streaming completion
110
+
111
+
112
+
113
+ To implement `concat_completion_chunks` we first implement a binary `_concat_chunks` function for each
114
+ type. Using `singledispatch` to dispatch the call to the appropriate function based on the type of the first argument.
115
+ Each nested type is then concatenated. We can then use reduce to accumulate the entire stream into a single a
116
+ single `CompletionChunk`. Finally we convert the type to the appropriate non-streaming type `Completion` and return it.
117
+ """
118
+ if not chunks:
119
+ return None
120
+
121
+ chunks_copy = chunks.copy()
122
+ chunks_copy[0] = deepcopy(chunks_copy[0]) # _concat_chunks mutates first argument
123
+ accumulated_chunks = reduce(_concat_chunks, chunks_copy)
124
+
125
+ data = accumulated_chunks.model_dump()
126
+ data["object"] = "chat.completion"
127
+ choices = data["choices"]
128
+ for choice in choices:
129
+ choice["message"] = choice.pop("delta")
130
+
131
+ return Completion.model_validate(data)
@@ -0,0 +1,14 @@
1
+ from rich import box
2
+ from rich.console import Console
3
+ from rich.table import Table
4
+
5
+ console = Console()
6
+
7
+
8
+ def print_section(name: str, contents: list[str], subtitle: str | None = None):
9
+ console.print()
10
+ table = Table(box=box.SQUARE, caption=subtitle, show_header=False, expand=True)
11
+ table.title = name
12
+ table.add_column(name, style="dim", width=12)
13
+ table.add_row(*contents)
14
+ console.print(table)
@@ -0,0 +1,29 @@
1
+ from typing import Any
2
+
3
+ import yaml
4
+ from yaml.scanner import ScannerError
5
+
6
+
7
+ class InvalidYAMLError(ValueError):
8
+ """
9
+ Raised when trying to red a YAML file, but the file is not formatted correctly.
10
+ """
11
+
12
+
13
+ def load_yaml_file(file_path: str) -> dict[str, Any]:
14
+ """
15
+ Loads a YAML file from the specified path.
16
+
17
+ :param file_path: The path of the YAML file to load.
18
+ :type file_path: str
19
+ :return: The contents of the YAML file.
20
+ :rtype: dict
21
+ """
22
+ try:
23
+ with open(file_path) as file:
24
+ yaml_dict = yaml.safe_load(file)
25
+ return yaml_dict
26
+ except ScannerError as error:
27
+ raise InvalidYAMLError(
28
+ f"The following file is not in valid YAML format: {file_path}"
29
+ ) from error
@@ -0,0 +1,14 @@
1
+ from collections.abc import AsyncGenerator
2
+ from typing import Any
3
+
4
+
5
+ async def async_enumerate(
6
+ aiterable: AsyncGenerator, start: int = 0
7
+ ) -> AsyncGenerator[tuple[int, Any], None]:
8
+ """
9
+ Enumerate an async generator.
10
+ """
11
+ i = start
12
+ async for item in aiterable:
13
+ yield i, item
14
+ i += 1
@@ -0,0 +1,23 @@
1
+ from typing import Any
2
+
3
+ import jsonref
4
+ from jsonschema import validate as schema_validation
5
+
6
+
7
+ def resolve_refs(schema: dict) -> dict:
8
+ """
9
+ Resolve JSON references in a schema.
10
+ """
11
+ resolved = jsonref.replace_refs(schema, proxies=False, lazy_load=False)
12
+ serializable = {
13
+ "type": resolved.get("type"),
14
+ "properties": resolved.get("properties"),
15
+ "required": list(resolved.get("required", [])),
16
+ "additionalProperties": resolved.get("additionalProperties", False),
17
+ }
18
+ return serializable
19
+
20
+
21
+ def validate_payload(json_schema: dict[str, Any], payload: dict[str, Any]) -> None:
22
+ """Validate the payload against the JSON schema."""
23
+ schema_validation(instance=payload, schema=json_schema)
@@ -0,0 +1,31 @@
1
+ import logging
2
+
3
+ from rich.console import Console
4
+ from rich.logging import RichHandler
5
+
6
+
7
+ def make_logger(name: str):
8
+ """
9
+ Creates a logger object with a RichHandler to print colored text.
10
+ :param name: The name of the module to create the logger for.
11
+ :return: A logger object.
12
+ """
13
+ # Create a console object to print colored text
14
+ console = Console()
15
+
16
+ # Create a logger object with the name of the current module
17
+ logger = logging.getLogger(name)
18
+
19
+ # Set the global log level to INFO
20
+ logger.setLevel(logging.INFO)
21
+
22
+ # Add the RichHandler to the logger to print colored text
23
+ handler = RichHandler(
24
+ console=console,
25
+ show_level=False,
26
+ show_path=False,
27
+ show_time=False,
28
+ )
29
+ logger.addHandler(handler)
30
+
31
+ return logger
@@ -0,0 +1,17 @@
1
+ from typing import Any
2
+ from mcp import StdioServerParameters
3
+
4
+
5
+ def redact_mcp_server_params(
6
+ mcp_server_params: list[StdioServerParameters],
7
+ ) -> list[dict[str, Any]]:
8
+ """Redact MCP server params for logging."""
9
+ return [
10
+ {
11
+ **{k: v for k, v in server_param.model_dump().items() if k != "env"},
12
+ "env": dict.fromkeys(server_param.env, "********")
13
+ if server_param.env
14
+ else None,
15
+ }
16
+ for server_param in mcp_server_params
17
+ ]
@@ -0,0 +1,46 @@
1
+ from collections.abc import Iterable, Mapping
2
+ from typing import Any, TypeVar
3
+
4
+ from pydantic import BaseModel as PydanticBaseModel
5
+ from pydantic import ConfigDict
6
+
7
+ from agentex.lib.utils.io import load_yaml_file
8
+
9
+ T = TypeVar("T", bound="BaseModel")
10
+
11
+
12
+ class BaseModel(PydanticBaseModel):
13
+ model_config = ConfigDict(from_attributes=True, populate_by_name=True)
14
+
15
+ @classmethod
16
+ def from_yaml(cls: type[T], file_path: str) -> T:
17
+ """
18
+ Returns an instance of this class by deserializing from a YAML file.
19
+
20
+ :param file_path: The path to the YAML file.
21
+ :return: An instance of this class.
22
+ """
23
+ yaml_dict = load_yaml_file(file_path=file_path)
24
+ class_object = cls.model_validate(yaml_dict)
25
+ return class_object
26
+
27
+ def to_json(self, *args, **kwargs) -> str:
28
+ return self.model_dump_json(*args, **kwargs)
29
+
30
+ def to_dict(self, *args, **kwargs) -> dict[str, Any]:
31
+ return recursive_model_dump(self)
32
+
33
+
34
+ def recursive_model_dump(obj: Any) -> Any:
35
+ if isinstance(obj, PydanticBaseModel):
36
+ # Serialize BaseModel to dict
37
+ return obj.model_dump(mode="json")
38
+ elif isinstance(obj, Mapping):
39
+ # Recursively serialize dictionary values
40
+ return {k: recursive_model_dump(v) for k, v in obj.items()}
41
+ elif isinstance(obj, Iterable) and not isinstance(obj, str | bytes):
42
+ # Recursively serialize items in lists, tuples, sets, etc.
43
+ return [recursive_model_dump(item) for item in obj]
44
+ else:
45
+ # Return primitive types as-is
46
+ return obj
@@ -0,0 +1,15 @@
1
+ from urllib.parse import urlsplit, urlunsplit
2
+
3
+
4
+ def remove_query_params(url):
5
+ split_url = urlsplit(url)
6
+ scheme, netloc, path, query, fragment = split_url
7
+
8
+ if query:
9
+ query = ''
10
+ else:
11
+ amp_index = path.find('&')
12
+ if amp_index != -1:
13
+ path = path[:amp_index]
14
+
15
+ return urlunsplit((scheme, netloc, path, query, fragment))
@@ -0,0 +1,6 @@
1
+ import re
2
+
3
+
4
+ def camel_to_snake(camel_case_str: str) -> str:
5
+ # Substitute capital letters with an underscore followed by the lowercase letter
6
+ return re.sub(r'(?<!^)(?=[A-Z])', '_', camel_case_str).lower()
@@ -0,0 +1,13 @@
1
+ from temporalio import activity, workflow
2
+
3
+
4
+ def in_temporal_workflow():
5
+ try:
6
+ return workflow.in_workflow()
7
+ except RuntimeError:
8
+ return False
9
+
10
+
11
+ def heartbeat_if_in_workflow(heartbeat_name: str):
12
+ if in_temporal_workflow():
13
+ activity.heartbeat(heartbeat_name)
agentex/py.typed ADDED
File without changes
@@ -0,0 +1,103 @@
1
+ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ from .spans import (
4
+ SpansResource,
5
+ AsyncSpansResource,
6
+ SpansResourceWithRawResponse,
7
+ AsyncSpansResourceWithRawResponse,
8
+ SpansResourceWithStreamingResponse,
9
+ AsyncSpansResourceWithStreamingResponse,
10
+ )
11
+ from .tasks import (
12
+ TasksResource,
13
+ AsyncTasksResource,
14
+ TasksResourceWithRawResponse,
15
+ AsyncTasksResourceWithRawResponse,
16
+ TasksResourceWithStreamingResponse,
17
+ AsyncTasksResourceWithStreamingResponse,
18
+ )
19
+ from .agents import (
20
+ AgentsResource,
21
+ AsyncAgentsResource,
22
+ AgentsResourceWithRawResponse,
23
+ AsyncAgentsResourceWithRawResponse,
24
+ AgentsResourceWithStreamingResponse,
25
+ AsyncAgentsResourceWithStreamingResponse,
26
+ )
27
+ from .events import (
28
+ EventsResource,
29
+ AsyncEventsResource,
30
+ EventsResourceWithRawResponse,
31
+ AsyncEventsResourceWithRawResponse,
32
+ EventsResourceWithStreamingResponse,
33
+ AsyncEventsResourceWithStreamingResponse,
34
+ )
35
+ from .states import (
36
+ StatesResource,
37
+ AsyncStatesResource,
38
+ StatesResourceWithRawResponse,
39
+ AsyncStatesResourceWithRawResponse,
40
+ StatesResourceWithStreamingResponse,
41
+ AsyncStatesResourceWithStreamingResponse,
42
+ )
43
+ from .tracker import (
44
+ TrackerResource,
45
+ AsyncTrackerResource,
46
+ TrackerResourceWithRawResponse,
47
+ AsyncTrackerResourceWithRawResponse,
48
+ TrackerResourceWithStreamingResponse,
49
+ AsyncTrackerResourceWithStreamingResponse,
50
+ )
51
+ from .messages import (
52
+ MessagesResource,
53
+ AsyncMessagesResource,
54
+ MessagesResourceWithRawResponse,
55
+ AsyncMessagesResourceWithRawResponse,
56
+ MessagesResourceWithStreamingResponse,
57
+ AsyncMessagesResourceWithStreamingResponse,
58
+ )
59
+
60
+ __all__ = [
61
+ "AgentsResource",
62
+ "AsyncAgentsResource",
63
+ "AgentsResourceWithRawResponse",
64
+ "AsyncAgentsResourceWithRawResponse",
65
+ "AgentsResourceWithStreamingResponse",
66
+ "AsyncAgentsResourceWithStreamingResponse",
67
+ "TasksResource",
68
+ "AsyncTasksResource",
69
+ "TasksResourceWithRawResponse",
70
+ "AsyncTasksResourceWithRawResponse",
71
+ "TasksResourceWithStreamingResponse",
72
+ "AsyncTasksResourceWithStreamingResponse",
73
+ "MessagesResource",
74
+ "AsyncMessagesResource",
75
+ "MessagesResourceWithRawResponse",
76
+ "AsyncMessagesResourceWithRawResponse",
77
+ "MessagesResourceWithStreamingResponse",
78
+ "AsyncMessagesResourceWithStreamingResponse",
79
+ "SpansResource",
80
+ "AsyncSpansResource",
81
+ "SpansResourceWithRawResponse",
82
+ "AsyncSpansResourceWithRawResponse",
83
+ "SpansResourceWithStreamingResponse",
84
+ "AsyncSpansResourceWithStreamingResponse",
85
+ "StatesResource",
86
+ "AsyncStatesResource",
87
+ "StatesResourceWithRawResponse",
88
+ "AsyncStatesResourceWithRawResponse",
89
+ "StatesResourceWithStreamingResponse",
90
+ "AsyncStatesResourceWithStreamingResponse",
91
+ "EventsResource",
92
+ "AsyncEventsResource",
93
+ "EventsResourceWithRawResponse",
94
+ "AsyncEventsResourceWithRawResponse",
95
+ "EventsResourceWithStreamingResponse",
96
+ "AsyncEventsResourceWithStreamingResponse",
97
+ "TrackerResource",
98
+ "AsyncTrackerResource",
99
+ "TrackerResourceWithRawResponse",
100
+ "AsyncTrackerResourceWithRawResponse",
101
+ "TrackerResourceWithStreamingResponse",
102
+ "AsyncTrackerResourceWithStreamingResponse",
103
+ ]