dg-dataagent 0.1.0__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 (310) hide show
  1. dataagent/__init__.py +37 -0
  2. dataagent/__main__.py +16 -0
  3. dataagent/a2a_server/__init__.py +25 -0
  4. dataagent/a2a_server/agent_card.py +85 -0
  5. dataagent/a2a_server/agent_executor.py +310 -0
  6. dataagent/a2a_server/server.py +169 -0
  7. dataagent/a2a_server/task_store.py +29 -0
  8. dataagent/actions/__init__.py +12 -0
  9. dataagent/actions/environment/__init__.py +21 -0
  10. dataagent/actions/environment/compound_env.py +89 -0
  11. dataagent/actions/environment/env.py +52 -0
  12. dataagent/actions/environment/env_config.py +101 -0
  13. dataagent/actions/gym/__init__.py +32 -0
  14. dataagent/actions/gym/arithmetic/arithmetic.py +124 -0
  15. dataagent/actions/gym/changping/changping_env.py +480 -0
  16. dataagent/actions/gym/icbc/icbc_env.py +800 -0
  17. dataagent/actions/gym/manufacturing/manufacturing_env.py +534 -0
  18. dataagent/actions/gym/nl2sql/base_env.py +444 -0
  19. dataagent/actions/gym/nl2sql/sqlite_env.py +79 -0
  20. dataagent/actions/gym/ontology_env.py +1310 -0
  21. dataagent/actions/perceptor/perceptor_atomic.py +671 -0
  22. dataagent/actions/perceptor/perceptor_utils.py +31 -0
  23. dataagent/actions/skills/__init__.py +12 -0
  24. dataagent/actions/skills/data_analysis_report/SKILL.md +95 -0
  25. dataagent/actions/skills/ontology_service/SKILL.md +65 -0
  26. dataagent/actions/skills/ontology_service/__init__.py +12 -0
  27. dataagent/actions/skills/ontology_service/references/commands.md +204 -0
  28. dataagent/actions/skills/ontology_service/references/public-api.md +66 -0
  29. dataagent/actions/skills/ontology_service/scripts/__init__.py +12 -0
  30. dataagent/actions/skills/ontology_service/scripts/cli_utils.py +75 -0
  31. dataagent/actions/skills/ontology_service/scripts/describe_ontology.py +39 -0
  32. dataagent/actions/skills/ontology_service/scripts/entity_lookup.py +77 -0
  33. dataagent/actions/skills/ontology_service/scripts/ontology_cli.py +1067 -0
  34. dataagent/actions/skills/ontology_service/scripts/ontology_client.py +533 -0
  35. dataagent/actions/tools/__init__.py +36 -0
  36. dataagent/actions/tools/a2a.py +472 -0
  37. dataagent/actions/tools/backfill.py +126 -0
  38. dataagent/actions/tools/concurrency.py +114 -0
  39. dataagent/actions/tools/context.py +49 -0
  40. dataagent/actions/tools/hooks/__init__.py +34 -0
  41. dataagent/actions/tools/hooks/base.py +123 -0
  42. dataagent/actions/tools/hooks/config.py +73 -0
  43. dataagent/actions/tools/hooks/examples/__init__.py +17 -0
  44. dataagent/actions/tools/hooks/examples/example_hooks.py +95 -0
  45. dataagent/actions/tools/local.py +172 -0
  46. dataagent/actions/tools/local_tool/agent_status_handler.py +221 -0
  47. dataagent/actions/tools/local_tool/document_recall.py +300 -0
  48. dataagent/actions/tools/local_tool/plan.py +166 -0
  49. dataagent/actions/tools/local_tool/sandbox.py +655 -0
  50. dataagent/actions/tools/local_tool/sql_reader.py +36 -0
  51. dataagent/actions/tools/local_tool/sub_agent_entry.py +255 -0
  52. dataagent/actions/tools/local_tool/tools.py +2756 -0
  53. dataagent/actions/tools/mcp.py +486 -0
  54. dataagent/actions/tools/mcp_examples.py +231 -0
  55. dataagent/actions/tools/mcp_tool/nl2sql.py +62 -0
  56. dataagent/actions/tools/schema_validator.py +438 -0
  57. dataagent/actions/tools/semantic_tool/get_join_relations.py +108 -0
  58. dataagent/actions/tools/semantic_tool/get_table_desc.py +35 -0
  59. dataagent/actions/tools/semantic_tool/search_metric_instance.py +991 -0
  60. dataagent/actions/tools/semantic_tool/search_tables_with_schema.py +588 -0
  61. dataagent/actions/tools/semantic_tool/search_udf_functions.py +641 -0
  62. dataagent/actions/tools/utils.py +65 -0
  63. dataagent/agents/document_recall/document_recall_agent.yaml +109 -0
  64. dataagent/agents/document_recall/tools.py +141 -0
  65. dataagent/agents/galatea/__init__.py +13 -0
  66. dataagent/agents/galatea/actions/__init__.py +38 -0
  67. dataagent/agents/galatea/actions/bash.py +59 -0
  68. dataagent/agents/galatea/actions/create_subagent.py +70 -0
  69. dataagent/agents/galatea/actions/edit.py +90 -0
  70. dataagent/agents/galatea/actions/inspect.py +73 -0
  71. dataagent/agents/galatea/actions/read.py +66 -0
  72. dataagent/agents/galatea/actions/search_online.py +80 -0
  73. dataagent/agents/galatea/actions/write.py +45 -0
  74. dataagent/agents/galatea/agent.py +194 -0
  75. dataagent/agents/galatea/core/__init__.py +19 -0
  76. dataagent/agents/galatea/graph/__init__.py +12 -0
  77. dataagent/agents/galatea/graph/executor.py +122 -0
  78. dataagent/agents/galatea/graph/planner.py +125 -0
  79. dataagent/agents/galatea/graph/router.py +139 -0
  80. dataagent/agents/galatea/graph/rule.py +35 -0
  81. dataagent/agents/galatea/hooks/__init__.py +12 -0
  82. dataagent/agents/galatea/hooks/metadata_tracker.py +210 -0
  83. dataagent/agents/galatea/hooks/portraiter.py +150 -0
  84. dataagent/agents/galatea/hooks/pruner.py +84 -0
  85. dataagent/agents/galatea/hooks/streamer.py +141 -0
  86. dataagent/agents/galatea/prompts/planner/system.md +42 -0
  87. dataagent/agents/galatea/prompts/planner/user.md +7 -0
  88. dataagent/agents/galatea/state/__init__.py +12 -0
  89. dataagent/agents/galatea/state/state.py +22 -0
  90. dataagent/agents/galatea/utils/__init__.py +12 -0
  91. dataagent/agents/galatea/utils/history_utils.py +173 -0
  92. dataagent/agents/galatea/utils/json_store.py +40 -0
  93. dataagent/agents/galatea/utils/metadata_utils.py +148 -0
  94. dataagent/agents/galatea/utils/portraiter_utils.py +114 -0
  95. dataagent/agents/galatea/utils/workspace_utils.py +67 -0
  96. dataagent/agents/nl2sql/__init__.py +3 -0
  97. dataagent/agents/nl2sql/agent.py +178 -0
  98. dataagent/agents/nl2sql/errors.py +98 -0
  99. dataagent/agents/nl2sql/nl2sql_agent.yaml +41 -0
  100. dataagent/agents/nl2sql/nodes/__init__.py +31 -0
  101. dataagent/agents/nl2sql/nodes/base_nl2sql_node.py +70 -0
  102. dataagent/agents/nl2sql/nodes/coordinator.py +34 -0
  103. dataagent/agents/nl2sql/nodes/executor.py +54 -0
  104. dataagent/agents/nl2sql/nodes/generator.py +94 -0
  105. dataagent/agents/nl2sql/nodes/perceptor.py +199 -0
  106. dataagent/agents/nl2sql/nodes/reflector.py +59 -0
  107. dataagent/agents/nl2sql/nodes/selector.py +74 -0
  108. dataagent/agents/nl2sql/nodes/validator.py +172 -0
  109. dataagent/agents/nl2sql/prompts/coordinator/system.md +30 -0
  110. dataagent/agents/nl2sql/prompts/coordinator/user.md +7 -0
  111. dataagent/agents/nl2sql/prompts/generator/dc_system.md +44 -0
  112. dataagent/agents/nl2sql/prompts/generator/dc_user.md +12 -0
  113. dataagent/agents/nl2sql/prompts/generator/icl_system.md +33 -0
  114. dataagent/agents/nl2sql/prompts/generator/icl_user.md +18 -0
  115. dataagent/agents/nl2sql/prompts/generator/prompt_system.md +17 -0
  116. dataagent/agents/nl2sql/prompts/generator/prompt_user.md +15 -0
  117. dataagent/agents/nl2sql/prompts/generator/skeleton_system.md +46 -0
  118. dataagent/agents/nl2sql/prompts/generator/skeleton_user.md +10 -0
  119. dataagent/agents/nl2sql/prompts/perceptor/filter_udn_table_system.md +32 -0
  120. dataagent/agents/nl2sql/prompts/perceptor/filter_udn_table_user.md +8 -0
  121. dataagent/agents/nl2sql/prompts/reflector/system.md +29 -0
  122. dataagent/agents/nl2sql/prompts/reflector/user.md +7 -0
  123. dataagent/agents/nl2sql/prompts/selector/system.md +30 -0
  124. dataagent/agents/nl2sql/prompts/selector/user.md +13 -0
  125. dataagent/agents/nl2sql/prompts/user/sql_rules_bird.md +6 -0
  126. dataagent/agents/nl2sql/prompts/user/sql_rules_udn.md +71 -0
  127. dataagent/agents/nl2sql/prompts/user/sql_rules_zdy.md +3 -0
  128. dataagent/agents/nl2sql/prompts/validator/extract_columns_system.md +30 -0
  129. dataagent/agents/nl2sql/prompts/validator/extract_columns_user.md +3 -0
  130. dataagent/agents/nl2sql/prompts/validator/validate_semantic_system.md +30 -0
  131. dataagent/agents/nl2sql/prompts/validator/validate_semantic_user.md +18 -0
  132. dataagent/agents/nl2sql/udn.yaml +33 -0
  133. dataagent/agents/nl2sql/utils/metavisor_client.py +123 -0
  134. dataagent/agents/nl2sql/utils/nl2sql_utils.py +232 -0
  135. dataagent/agents/nl2sql/utils/sql_service.py +310 -0
  136. dataagent/agents/nl2sql/workflow/router.py +63 -0
  137. dataagent/agents/nl2sql/workflow/state.py +104 -0
  138. dataagent/common_utils/knowledge_base/knowledge_base.py +405 -0
  139. dataagent/common_utils/knowledge_base/memory.py +1338 -0
  140. dataagent/common_utils/knowledge_base/metadata_management.py +1129 -0
  141. dataagent/common_utils/knowledge_base/tool_management.py +331 -0
  142. dataagent/common_utils/knowledge_base/utils_common.py +869 -0
  143. dataagent/common_utils/knowledge_base/utils_inference.py +80 -0
  144. dataagent/common_utils/knowledge_base/utils_knowledgebase.py +119 -0
  145. dataagent/common_utils/knowledge_base/utils_memory.py +322 -0
  146. dataagent/common_utils/knowledge_base/utils_metadata.py +267 -0
  147. dataagent/common_utils/storer_utils.py +113 -0
  148. dataagent/config/__init__.py +35 -0
  149. dataagent/config/config_manager.py +343 -0
  150. dataagent/core/__init__.py +30 -0
  151. dataagent/core/cbb/__init__.py +17 -0
  152. dataagent/core/cbb/agent_env.py +63 -0
  153. dataagent/core/cbb/base_agent.py +142 -0
  154. dataagent/core/cbb/base_hook.py +36 -0
  155. dataagent/core/cbb/base_node.py +148 -0
  156. dataagent/core/cbb/base_router.py +81 -0
  157. dataagent/core/cbb/base_state.py +19 -0
  158. dataagent/core/cbb/galatea_base_agent.py +114 -0
  159. dataagent/core/cbb/module.py +27 -0
  160. dataagent/core/cbb/runtime.py +327 -0
  161. dataagent/core/cbb/runtime_env.py +577 -0
  162. dataagent/core/context/contextIR.py +617 -0
  163. dataagent/core/context/context_trajectory.py +1129 -0
  164. dataagent/core/context/flex_context_formatting.py +179 -0
  165. dataagent/core/context/message_history.py +207 -0
  166. dataagent/core/context/todolist_manager.py +202 -0
  167. dataagent/core/context/util.py +113 -0
  168. dataagent/core/context/utils_context_storage.py +320 -0
  169. dataagent/core/context/utils_context_trajectory.py +323 -0
  170. dataagent/core/flex/agent.py +982 -0
  171. dataagent/core/flex/examples/arithmetic.yaml +29 -0
  172. dataagent/core/flex/examples/changping.yaml +87 -0
  173. dataagent/core/flex/examples/deep_analyze.yaml +7 -0
  174. dataagent/core/flex/examples/ecommerce_agent.yaml +55 -0
  175. dataagent/core/flex/examples/example.yaml +292 -0
  176. dataagent/core/flex/examples/icbc.yaml +69 -0
  177. dataagent/core/flex/examples/manufacturing.yaml +92 -0
  178. dataagent/core/flex/examples/nl2sql_flex_e2e_subagent.yaml +44 -0
  179. dataagent/core/flex/examples/ontology_sub_agent.yaml +42 -0
  180. dataagent/core/flex/examples/quickstart.yaml +15 -0
  181. dataagent/core/flex/examples/test_custom_prompt.yaml +65 -0
  182. dataagent/core/flex/examples/test_skills.yaml +36 -0
  183. dataagent/core/flex/examples/test_subagent_tool.yaml +40 -0
  184. dataagent/core/flex/examples/ueg.yaml +35 -0
  185. dataagent/core/flex/examples/yunhe.yaml +21 -0
  186. dataagent/core/flex/flex_default_configs.yaml +60 -0
  187. dataagent/core/flex/flex_runtime_from_config.py +330 -0
  188. dataagent/core/flex/hooks/__init__.py +15 -0
  189. dataagent/core/flex/hooks/agent_turn.py +54 -0
  190. dataagent/core/flex/hooks/cross_session_recall.py +200 -0
  191. dataagent/core/flex/hooks/history_writer.py +54 -0
  192. dataagent/core/flex/hooks/memory_indexer.py +128 -0
  193. dataagent/core/flex/hooks/metadata_tracker.py +263 -0
  194. dataagent/core/flex/hooks/organize_workspace.py +49 -0
  195. dataagent/core/flex/hooks/portraiter.py +346 -0
  196. dataagent/core/flex/hooks/pruner.py +84 -0
  197. dataagent/core/flex/hooks/registry.py +45 -0
  198. dataagent/core/flex/nodes/executor.py +1242 -0
  199. dataagent/core/flex/nodes/human_feedback.py +405 -0
  200. dataagent/core/flex/nodes/planner.py +435 -0
  201. dataagent/core/flex/utils/__init__.py +13 -0
  202. dataagent/core/flex/utils/context_from_state.py +68 -0
  203. dataagent/core/flex/utils/planner_prompt_builder.py +848 -0
  204. dataagent/core/flex/workflow/router.py +212 -0
  205. dataagent/core/flex/workflow/state.py +44 -0
  206. dataagent/core/framework_adapters/checkpoints/__init__.py +9 -0
  207. dataagent/core/framework_adapters/checkpoints/postgres_store.py +110 -0
  208. dataagent/core/framework_adapters/checkpoints/sqlite_store.py +124 -0
  209. dataagent/core/framework_adapters/checkpoints/types.py +24 -0
  210. dataagent/core/framework_adapters/runtime/__init__.py +38 -0
  211. dataagent/core/framework_adapters/runtime/context.py +373 -0
  212. dataagent/core/framework_adapters/runtime/workflow.py +176 -0
  213. dataagent/core/framework_adapters/runtime/workflow_backend.py +208 -0
  214. dataagent/core/framework_adapters/runtime/workflow_backend_factory.py +53 -0
  215. dataagent/core/framework_adapters/runtime/workflow_openjiuwen.py +707 -0
  216. dataagent/core/interface.py +101 -0
  217. dataagent/core/managers/action_manager/__init__.py +35 -0
  218. dataagent/core/managers/action_manager/base.py +220 -0
  219. dataagent/core/managers/action_manager/manager.py +1071 -0
  220. dataagent/core/managers/action_manager/registry.py +81 -0
  221. dataagent/core/managers/action_manager/schemas.py +322 -0
  222. dataagent/core/managers/galatea_action_manager.py +251 -0
  223. dataagent/core/managers/llm_manager/__init__.py +50 -0
  224. dataagent/core/managers/llm_manager/adapters.py +610 -0
  225. dataagent/core/managers/llm_manager/galatea_llm.py +46 -0
  226. dataagent/core/managers/llm_manager/llm_client.py +889 -0
  227. dataagent/core/managers/llm_manager/llm_config.py +82 -0
  228. dataagent/core/managers/llm_manager/llm_manager.py +115 -0
  229. dataagent/core/managers/prompt_manager/__init__.py +31 -0
  230. dataagent/core/managers/prompt_manager/template.py +120 -0
  231. dataagent/core/managers/prompt_manager/templates/__init__.py +12 -0
  232. dataagent/core/managers/prompt_manager/templates/context/fold_messages.md +80 -0
  233. dataagent/core/managers/prompt_manager/templates/human_feedback/system.md +13 -0
  234. dataagent/core/managers/prompt_manager/templates/human_feedback/user.md +7 -0
  235. dataagent/core/managers/prompt_manager/templates/irmanager/system.md +1 -0
  236. dataagent/core/managers/prompt_manager/templates/irmanager/system_update_state.md +8 -0
  237. dataagent/core/managers/prompt_manager/templates/irmanager/user.md +21 -0
  238. dataagent/core/managers/prompt_manager/templates/irmanager/user_update_state.md +11 -0
  239. dataagent/core/managers/prompt_manager/templates/knowledge_base/community_parent_report.md +39 -0
  240. dataagent/core/managers/prompt_manager/templates/knowledge_base/community_report.md +39 -0
  241. dataagent/core/managers/prompt_manager/templates/knowledge_base/extract_column_relationships.md +15 -0
  242. dataagent/core/managers/prompt_manager/templates/knowledge_base/extract_columns.md +14 -0
  243. dataagent/core/managers/prompt_manager/templates/knowledge_base/extract_tool_relationships.md +20 -0
  244. dataagent/core/managers/prompt_manager/templates/knowledge_base/extract_virtual_columns.md +18 -0
  245. dataagent/core/managers/prompt_manager/templates/knowledge_base/infer_data_type.md +24 -0
  246. dataagent/core/managers/prompt_manager/templates/knowledge_base/infer_file_description.md +22 -0
  247. dataagent/core/managers/prompt_manager/templates/knowledge_base/infer_schema_description.md +18 -0
  248. dataagent/core/managers/prompt_manager/templates/knowledge_base/update_column_description.md +28 -0
  249. dataagent/core/managers/prompt_manager/templates/knowledge_base/user_guide_kb.md +11 -0
  250. dataagent/core/managers/prompt_manager/templates/nl2sql_react/system.md +17 -0
  251. dataagent/core/managers/prompt_manager/templates/nl2sql_react/user.md +1 -0
  252. dataagent/core/managers/prompt_manager/templates/perceptor/keyword_extract_system.md +34 -0
  253. dataagent/core/managers/prompt_manager/templates/perceptor/keyword_extract_user.md +7 -0
  254. dataagent/core/managers/prompt_manager/templates/planner/system.md +128 -0
  255. dataagent/core/managers/prompt_manager/templates/planner/todo.md +38 -0
  256. dataagent/core/managers/prompt_manager/templates/planner/user.md +44 -0
  257. dataagent/core/managers/prompt_manager/templates/skill_selector/system.md +118 -0
  258. dataagent/core/managers/prompt_manager/templates/skill_selector/user.md +15 -0
  259. dataagent/core/swarm/__init__.py +15 -0
  260. dataagent/core/swarm/swarm_config.py +65 -0
  261. dataagent/core/swarm/worker_io.py +27 -0
  262. dataagent/core/swarm/worker_lock.py +105 -0
  263. dataagent/core/swarm/worker_memory.py +133 -0
  264. dataagent/core/swarm/worker_metadata.py +247 -0
  265. dataagent/core/swarm/worker_result.py +255 -0
  266. dataagent/core/utils/__init__.py +13 -0
  267. dataagent/core/utils/performance.py +597 -0
  268. dataagent/interface/cli/__init__.py +17 -0
  269. dataagent/interface/cli/main.py +640 -0
  270. dataagent/interface/rest_api/__init__.py +22 -0
  271. dataagent/interface/rest_api/app.py +110 -0
  272. dataagent/interface/rest_api/service.py +242 -0
  273. dataagent/interface/rest_api/start_service.py +52 -0
  274. dataagent/interface/sdk/__init__.py +24 -0
  275. dataagent/interface/sdk/agent.py +309 -0
  276. dataagent/interface/sdk/base_data_agent.py +425 -0
  277. dataagent/interface/sdk/builder.py +410 -0
  278. dataagent/interface/sdk/loader.py +34 -0
  279. dataagent/utils/__init__.py +12 -0
  280. dataagent/utils/builder_utils.py +368 -0
  281. dataagent/utils/cli/rich_renderer.py +889 -0
  282. dataagent/utils/cli/terminal_input.py +132 -0
  283. dataagent/utils/compression_utils.py +237 -0
  284. dataagent/utils/constants.py +472 -0
  285. dataagent/utils/converter/__init__.py +21 -0
  286. dataagent/utils/converter/graph_summary.py +230 -0
  287. dataagent/utils/converter/ir_converter_constants.py +188 -0
  288. dataagent/utils/converter/ir_message_consumer.py +220 -0
  289. dataagent/utils/converter/result_ir_converter.py +747 -0
  290. dataagent/utils/dag_utils.py +145 -0
  291. dataagent/utils/env_file_loader.py +255 -0
  292. dataagent/utils/env_utils.py +35 -0
  293. dataagent/utils/fix_md_image_path.py +300 -0
  294. dataagent/utils/formatting_utils.py +525 -0
  295. dataagent/utils/import_utils.py +154 -0
  296. dataagent/utils/info_utils.py +31 -0
  297. dataagent/utils/log/__init__.py +62 -0
  298. dataagent/utils/log/config.py +54 -0
  299. dataagent/utils/log/configs/default.yaml +49 -0
  300. dataagent/utils/log/configs/dev.yaml +18 -0
  301. dataagent/utils/log/configs/prod.yaml +19 -0
  302. dataagent/utils/log/dataagent_logger.py +311 -0
  303. dataagent/utils/messages_utils.py +390 -0
  304. dataagent/utils/parsing_utils.py +403 -0
  305. dataagent/utils/runtime_paths.py +167 -0
  306. dg_dataagent-0.1.0.dist-info/METADATA +273 -0
  307. dg_dataagent-0.1.0.dist-info/RECORD +310 -0
  308. dg_dataagent-0.1.0.dist-info/WHEEL +5 -0
  309. dg_dataagent-0.1.0.dist-info/licenses/LICENSE +201 -0
  310. dg_dataagent-0.1.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,21 @@
1
+ # Licensed under the Apache License, Version 2.0 (the "License");
2
+ # you may not use this file except in compliance with the License.
3
+ # You may obtain a copy of the License at
4
+ #
5
+ # http://www.apache.org/licenses/LICENSE-2.0
6
+ #
7
+ # Unless required by applicable law or agreed to in writing, software
8
+ # distributed under the License is distributed on an "AS IS" BASIS,
9
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ # See the License for the specific language governing permissions and
11
+ # limitations under the License.
12
+ # ============================================================================
13
+ __all__ = [
14
+ "Env",
15
+ "CompoundEnv",
16
+ "from_config",
17
+ ]
18
+
19
+ from dataagent.actions.environment.compound_env import CompoundEnv
20
+ from dataagent.actions.environment.env import Env
21
+ from dataagent.actions.environment.env_config import from_config
@@ -0,0 +1,89 @@
1
+ # Licensed under the Apache License, Version 2.0 (the "License");
2
+ # you may not use this file except in compliance with the License.
3
+ # You may obtain a copy of the License at
4
+ #
5
+ # http://www.apache.org/licenses/LICENSE-2.0
6
+ #
7
+ # Unless required by applicable law or agreed to in writing, software
8
+ # distributed under the License is distributed on an "AS IS" BASIS,
9
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ # See the License for the specific language governing permissions and
11
+ # limitations under the License.
12
+ # ============================================================================
13
+ from dataagent.actions.environment.env import Env
14
+
15
+
16
+ class CompoundEnv(Env):
17
+ """
18
+ Combines multiple Env instances into a single unified environment.
19
+
20
+ The CompoundEnv merges all tools from the component environments,
21
+ and delegates init/close operations to all sub-environments.
22
+
23
+ Example usage:
24
+ >>> class MathEnv(Env):
25
+ ... @Env.tool
26
+ ... def add(self, a, b):
27
+ ... return a + b
28
+ ...
29
+ >>> class StringEnv(Env):
30
+ ... @Env.tool
31
+ ... def concat(self, a, b):
32
+ ... return a + b
33
+ ...
34
+ >>> math_env = MathEnv()
35
+ >>> string_env = StringEnv()
36
+ >>> compound = CompoundEnv([math_env, string_env])
37
+ >>> compound.tools['add'](5, 3)
38
+ 8
39
+ >>> compound.tools['concat']('Hello', ' World')
40
+ 'Hello World'
41
+
42
+ Notes:
43
+ - Tools from later environments override tools with the same name
44
+ from earlier environments
45
+ - Calling init() on CompoundEnv initializes all sub-environments
46
+ - Calling close() on CompoundEnv closes all sub-environments
47
+ """
48
+
49
+ def __init__(self, envs: list[Env]):
50
+ """
51
+ Initialize CompoundEnv with a list of Env instances.
52
+
53
+ Args:
54
+ envs: List of Env instances to combine
55
+ """
56
+ # Set envs BEFORE calling super().__init__() because _register_tools() needs it
57
+ self.envs = envs
58
+ super().__init__()
59
+
60
+ def __repr__(self) -> str:
61
+ """String representation showing number of environments and tools"""
62
+ return f"CompoundEnv(envs={len(self.envs)}, tools={len(self.tools)})"
63
+
64
+ def init(self):
65
+ """Initialize all component environments"""
66
+ for env in self.envs:
67
+ env.init()
68
+
69
+ def close(self):
70
+ """Close all component environments"""
71
+ for env in self.envs:
72
+ env.close()
73
+
74
+ def get_description(self) -> str:
75
+ """Combine all descriptions"""
76
+ return "\n".join([env.get_description() for env in self.envs])
77
+
78
+ def _register_tools(self):
79
+ """
80
+ Override parent's _register_tools to merge tools from all sub-environments.
81
+
82
+ Tools from later environments will override tools with the same name
83
+ from earlier environments.
84
+ """
85
+ super()._register_tools()
86
+
87
+ for env in self.envs:
88
+ env_tools = env.get_tools()
89
+ self.tools.update(env_tools)
@@ -0,0 +1,52 @@
1
+ # Licensed under the Apache License, Version 2.0 (the "License");
2
+ # you may not use this file except in compliance with the License.
3
+ # You may obtain a copy of the License at
4
+ #
5
+ # http://www.apache.org/licenses/LICENSE-2.0
6
+ #
7
+ # Unless required by applicable law or agreed to in writing, software
8
+ # distributed under the License is distributed on an "AS IS" BASIS,
9
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ # See the License for the specific language governing permissions and
11
+ # limitations under the License.
12
+ # ============================================================================
13
+ from collections.abc import Callable
14
+
15
+
16
+ class Env:
17
+ def __init__(self):
18
+ self.tools: dict[str, Callable] = {}
19
+ self.init()
20
+ self._register_tools()
21
+
22
+ def __del__(self):
23
+ self.close()
24
+
25
+ @staticmethod
26
+ def tool(func: Callable) -> Callable:
27
+ """Decorator to mark a method as a tool"""
28
+ func._is_tool = True
29
+ return func
30
+
31
+ def init(self):
32
+ """Initialize the environment, override in subclass"""
33
+ pass
34
+
35
+ def close(self):
36
+ """Close the environment, override in subclass"""
37
+ pass
38
+
39
+ def get_tools(self) -> dict[str, Callable]:
40
+ """Return the tools bound the the environment"""
41
+ return self.tools
42
+
43
+ def get_description(self) -> str:
44
+ """Return the description of the environment"""
45
+ return ""
46
+
47
+ def _register_tools(self):
48
+ """Register all methods marked with the @tool decorator"""
49
+ for name in dir(self):
50
+ attr = getattr(self, name)
51
+ if callable(attr) and hasattr(attr, "_is_tool"):
52
+ self.tools[name] = attr
@@ -0,0 +1,101 @@
1
+ # Licensed under the Apache License, Version 2.0 (the "License");
2
+ # you may not use this file except in compliance with the License.
3
+ # You may obtain a copy of the License at
4
+ #
5
+ # http://www.apache.org/licenses/LICENSE-2.0
6
+ #
7
+ # Unless required by applicable law or agreed to in writing, software
8
+ # distributed under the License is distributed on an "AS IS" BASIS,
9
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ # See the License for the specific language governing permissions and
11
+ # limitations under the License.
12
+ # ============================================================================
13
+ from typing import Any
14
+
15
+ from dataagent.actions.environment.compound_env import CompoundEnv
16
+ from dataagent.actions.environment.env import Env
17
+ from dataagent.utils.import_utils import import_class
18
+
19
+
20
+ def from_config(config: list[dict[str, Any]] | dict[str, Any]) -> Env:
21
+ """
22
+ Create an Env instance from configuration.
23
+
24
+ Args:
25
+ config: Either a single environment configuration dict or a list of dicts.
26
+ Each dict must contain a "module" field specifying the Env subclass
27
+ to instantiate (e.g., "mypackage.envs.MyEnv").
28
+ Other fields in the dict are passed as keyword arguments to __init__.
29
+
30
+ Returns:
31
+ An Env instance. If config is a list, returns a CompoundEnv.
32
+
33
+ Raises:
34
+ ValueError: If configuration is invalid
35
+ ImportError: If the specified module cannot be imported
36
+ AttributeError: If the specified class doesn't exist in the module
37
+
38
+ Examples:
39
+ Single environment:
40
+ >>> config = {
41
+ ... "module": "mypackage.envs.MathEnv",
42
+ ... "precision": 10
43
+ ... }
44
+ >>> env = from_config(config)
45
+
46
+ Multiple environments (creates CompoundEnv):
47
+ >>> config = [
48
+ ... {"module": "mypackage.envs.MathEnv"},
49
+ ... {"module": "mypackage.envs.StringEnv", "encoding": "utf-8"}
50
+ ... ]
51
+ >>> compound_env = from_config(config)
52
+ """
53
+ if isinstance(config, list):
54
+ # Create multiple environments and combine them
55
+ if not config:
56
+ raise ValueError("Configuration list cannot be empty")
57
+
58
+ envs = [_create_single_env(env_config) for env_config in config]
59
+ return CompoundEnv(envs)
60
+ if isinstance(config, dict):
61
+ # Create a single environment
62
+ return _create_single_env(config)
63
+ raise ValueError(f"Configuration must be a dict or list of dicts, got {type(config)}")
64
+
65
+
66
+ def _create_single_env(config: dict[str, Any]) -> Env:
67
+ """
68
+ Create a single Env instance from a configuration dict.
69
+
70
+ Args:
71
+ config: Configuration dict with "module" field and optional init parameters
72
+
73
+ Returns:
74
+ An Env instance
75
+
76
+ Raises:
77
+ ValueError: If "module" field is missing
78
+ ImportError: If module cannot be imported
79
+ AttributeError: If class doesn't exist
80
+ TypeError: If the class is not a subclass of Env
81
+ """
82
+ if "module" not in config:
83
+ raise ValueError("Configuration dict must contain a 'module' field")
84
+
85
+ class_path = config["module"]
86
+
87
+ # Load the class using the utility function
88
+ env_class = import_class(class_path)
89
+
90
+ # Verify it's an Env subclass
91
+ if not issubclass(env_class, Env):
92
+ raise TypeError(f"Class {class_path} must be a subclass of Env, got {env_class}")
93
+
94
+ # Extract init parameters (everything except "module")
95
+ init_params = {k: v for k, v in config.items() if k != "module"}
96
+
97
+ # Instantiate the environment
98
+ try:
99
+ return env_class(**init_params)
100
+ except TypeError as e:
101
+ raise TypeError(f"Failed to instantiate {class_path} with parameters {init_params}: {e}") from e
@@ -0,0 +1,32 @@
1
+ # Licensed under the Apache License, Version 2.0 (the "License");
2
+ # you may not use this file except in compliance with the License.
3
+ # You may obtain a copy of the License at
4
+ #
5
+ # http://www.apache.org/licenses/LICENSE-2.0
6
+ #
7
+ # Unless required by applicable law or agreed to in writing, software
8
+ # distributed under the License is distributed on an "AS IS" BASIS,
9
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ # See the License for the specific language governing permissions and
11
+ # limitations under the License.
12
+ # ============================================================================
13
+
14
+ __all__ = ["ArithmeticEnv", "ICBCEnv", "ManufacureEnv", "OntologyEnv", "SQLiteEnv"]
15
+
16
+ import importlib
17
+
18
+ _ENV_REGISTRY = {
19
+ "ArithmeticEnv": "dataagent.actions.gym.arithmetic.arithmetic",
20
+ "ICBCEnv": "dataagent.actions.gym.icbc.icbc_env",
21
+ "ManufacureEnv": "dataagent.actions.gym.manufacturing.manufacturing_env",
22
+ "OntologyEnv": "dataagent.actions.gym.ontology_env",
23
+ "SQLiteEnv": "dataagent.actions.gym.nl2sql.sqlite_env",
24
+ }
25
+
26
+
27
+ def __getattr__(name: str):
28
+ if name not in _ENV_REGISTRY:
29
+ raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
30
+
31
+ module = importlib.import_module(_ENV_REGISTRY[name])
32
+ return getattr(module, name)
@@ -0,0 +1,124 @@
1
+ # Licensed under the Apache License, Version 2.0 (the "License");
2
+ # you may not use this file except in compliance with the License.
3
+ # You may obtain a copy of the License at
4
+ #
5
+ # http://www.apache.org/licenses/LICENSE-2.0
6
+ #
7
+ # Unless required by applicable law or agreed to in writing, software
8
+ # distributed under the License is distributed on an "AS IS" BASIS,
9
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ # See the License for the specific language governing permissions and
11
+ # limitations under the License.
12
+ # ============================================================================
13
+ from dataagent.actions.environment.env import Env
14
+
15
+
16
+ class ArithmeticEnv(Env):
17
+ """
18
+ Environment providing basic arithmetic operations.
19
+
20
+ This environment provides four fundamental mathematical operations:
21
+ addition, subtraction, multiplication, and division.
22
+
23
+ Example:
24
+ >>> env = ArithmeticEnv()
25
+ >>> env.tools['add'](5, 3)
26
+ 8
27
+ >>> env.tools['multiply'](4, 7)
28
+ 28
29
+ >>> env.tools['divide'](10, 2)
30
+ 5.0
31
+ """
32
+
33
+ def __init__(self):
34
+ """
35
+ Initialize the arithmetic environment.
36
+
37
+ Args:
38
+ precision: Number of decimal places to round results to (default: 2)
39
+ """
40
+ super().__init__()
41
+
42
+ @Env.tool
43
+ def add(self, a: float, b: float) -> float:
44
+ """
45
+ Add two numbers.
46
+
47
+ Args:
48
+ a: First number
49
+ b: Second number
50
+
51
+ Returns:
52
+ The sum of a and b
53
+
54
+ Example:
55
+ >>> add(5, 3)
56
+ 8.0
57
+ >>> add(1.5, 2.7)
58
+ 4.2
59
+ """
60
+ return a + b
61
+
62
+ @Env.tool
63
+ def subtract(self, a: float, b: float) -> float:
64
+ """
65
+ Subtract b from a.
66
+
67
+ Args:
68
+ a: Number to subtract from
69
+ b: Number to subtract
70
+
71
+ Returns:
72
+ The difference (a - b)
73
+
74
+ Example:
75
+ >>> subtract(10, 3)
76
+ 7.0
77
+ >>> subtract(5.5, 2.3)
78
+ 3.2
79
+ """
80
+ return a - b
81
+
82
+ @Env.tool
83
+ def multiply(self, a: float, b: float) -> float:
84
+ """
85
+ Multiply two numbers.
86
+
87
+ Args:
88
+ a: First number
89
+ b: Second number
90
+
91
+ Returns:
92
+ The product of a and b
93
+
94
+ Example:
95
+ >>> multiply(4, 7)
96
+ 28.0
97
+ >>> multiply(2.5, 3.2)
98
+ 8.0
99
+ """
100
+ return a * b
101
+
102
+ @Env.tool
103
+ def divide(self, a: float, b: float) -> float:
104
+ """
105
+ Divide a by b.
106
+
107
+ Args:
108
+ a: Dividend (number to be divided)
109
+ b: Divisor (number to divide by)
110
+
111
+ Returns:
112
+ The quotient (a / b), or NaN if b is zero
113
+
114
+ Example:
115
+ >>> divide(10, 2)
116
+ 5.0
117
+ >>> divide(7, 3)
118
+ 2.33
119
+ >>> divide(5, 0)
120
+ nan
121
+ """
122
+ if b == 0:
123
+ return float("nan")
124
+ return a / b