swarms 7.5.7__tar.gz → 7.5.9__tar.gz

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 (184) hide show
  1. {swarms-7.5.7 → swarms-7.5.9}/PKG-INFO +1 -1
  2. {swarms-7.5.7 → swarms-7.5.9}/pyproject.toml +1 -1
  3. {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/agent_builder.py +32 -18
  4. swarms-7.5.9/swarms/utils/str_to_dict.py +27 -0
  5. swarms-7.5.7/swarms/utils/str_to_dict.py +0 -51
  6. {swarms-7.5.7 → swarms-7.5.9}/LICENSE +0 -0
  7. {swarms-7.5.7 → swarms-7.5.9}/README.md +0 -0
  8. {swarms-7.5.7 → swarms-7.5.9}/swarms/__init__.py +0 -0
  9. {swarms-7.5.7 → swarms-7.5.9}/swarms/agents/__init__.py +0 -0
  10. {swarms-7.5.7 → swarms-7.5.9}/swarms/agents/agent_print.py +0 -0
  11. {swarms-7.5.7 → swarms-7.5.9}/swarms/agents/ape_agent.py +0 -0
  12. {swarms-7.5.7 → swarms-7.5.9}/swarms/agents/auto_generate_swarm_config.py +0 -0
  13. {swarms-7.5.7 → swarms-7.5.9}/swarms/agents/consistency_agent.py +0 -0
  14. {swarms-7.5.7 → swarms-7.5.9}/swarms/agents/create_agents_from_yaml.py +0 -0
  15. {swarms-7.5.7 → swarms-7.5.9}/swarms/agents/i_agent.py +0 -0
  16. {swarms-7.5.7 → swarms-7.5.9}/swarms/agents/openai_assistant.py +0 -0
  17. {swarms-7.5.7 → swarms-7.5.9}/swarms/agents/reasoning_agents.py +0 -0
  18. {swarms-7.5.7 → swarms-7.5.9}/swarms/agents/reasoning_duo.py +0 -0
  19. {swarms-7.5.7 → swarms-7.5.9}/swarms/agents/tool_agent.py +0 -0
  20. {swarms-7.5.7 → swarms-7.5.9}/swarms/artifacts/__init__.py +0 -0
  21. {swarms-7.5.7 → swarms-7.5.9}/swarms/artifacts/main_artifact.py +0 -0
  22. {swarms-7.5.7 → swarms-7.5.9}/swarms/cli/__init__.py +0 -0
  23. {swarms-7.5.7 → swarms-7.5.9}/swarms/cli/create_agent.py +0 -0
  24. {swarms-7.5.7 → swarms-7.5.9}/swarms/cli/main.py +0 -0
  25. {swarms-7.5.7 → swarms-7.5.9}/swarms/cli/onboarding_process.py +0 -0
  26. {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/__init__.py +0 -0
  27. {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/accountant_swarm_prompts.py +0 -0
  28. {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/ag_prompt.py +0 -0
  29. {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/aga.py +0 -0
  30. {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/agent_prompt.py +0 -0
  31. {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/agent_prompts.py +0 -0
  32. {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/agent_system_prompts.py +0 -0
  33. {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/ai_research_team.py +0 -0
  34. {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/aot_prompt.py +0 -0
  35. {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/autobloggen.py +0 -0
  36. {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/autoswarm.py +0 -0
  37. {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/chat_prompt.py +0 -0
  38. {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/code_interpreter.py +0 -0
  39. {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/code_spawner.py +0 -0
  40. {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/debate.py +0 -0
  41. {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/documentation.py +0 -0
  42. {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/education.py +0 -0
  43. {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/finance_agent_prompt.py +0 -0
  44. {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/finance_agent_sys_prompt.py +0 -0
  45. {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/growth_agent_prompt.py +0 -0
  46. {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/idea2img.py +0 -0
  47. {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/legal_agent_prompt.py +0 -0
  48. {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/logistics.py +0 -0
  49. {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/meta_system_prompt.py +0 -0
  50. {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/multi_modal_autonomous_instruction_prompt.py +0 -0
  51. {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/multi_modal_prompts.py +0 -0
  52. {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/multi_modal_visual_prompts.py +0 -0
  53. {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/operations_agent_prompt.py +0 -0
  54. {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/personal_stylist.py +0 -0
  55. {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/product_agent_prompt.py +0 -0
  56. {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/programming.py +0 -0
  57. {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/project_manager.py +0 -0
  58. {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/prompt.py +0 -0
  59. {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/prompt_generator.py +0 -0
  60. {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/prompt_generator_optimizer.py +0 -0
  61. {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/python.py +0 -0
  62. {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/react.py +0 -0
  63. {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/reasoning_prompt.py +0 -0
  64. {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/refiner_agent_prompt.py +0 -0
  65. {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/sales.py +0 -0
  66. {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/sales_prompts.py +0 -0
  67. {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/security_team.py +0 -0
  68. {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/self_operating_prompt.py +0 -0
  69. {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/sop_generator_agent_prompt.py +0 -0
  70. {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/summaries_prompts.py +0 -0
  71. {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/support_agent_prompt.py +0 -0
  72. {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/swarm_manager_agent.py +0 -0
  73. {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/task_assignment_prompt.py +0 -0
  74. {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/tests.py +0 -0
  75. {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/tools.py +0 -0
  76. {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/urban_planning.py +0 -0
  77. {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/visual_cot.py +0 -0
  78. {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/worker_prompt.py +0 -0
  79. {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/xray_swarm_prompt.py +0 -0
  80. {swarms-7.5.7 → swarms-7.5.9}/swarms/schemas/__init__.py +0 -0
  81. {swarms-7.5.7 → swarms-7.5.9}/swarms/schemas/agent_input_schema.py +0 -0
  82. {swarms-7.5.7 → swarms-7.5.9}/swarms/schemas/agent_step_schemas.py +0 -0
  83. {swarms-7.5.7 → swarms-7.5.9}/swarms/schemas/base_schemas.py +0 -0
  84. {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/__init__.py +0 -0
  85. {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/agent.py +0 -0
  86. {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/agent_registry.py +0 -0
  87. {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/agent_roles.py +0 -0
  88. {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/agent_router.py +0 -0
  89. {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/agent_security.py +0 -0
  90. {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/agents_available.py +0 -0
  91. {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/airflow_swarm.py +0 -0
  92. {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/async_workflow.py +0 -0
  93. {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/auto_swarm.py +0 -0
  94. {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/auto_swarm_builder.py +0 -0
  95. {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/base_structure.py +0 -0
  96. {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/base_swarm.py +0 -0
  97. {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/base_workflow.py +0 -0
  98. {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/concat.py +0 -0
  99. {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/concurrent_workflow.py +0 -0
  100. {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/conversation.py +0 -0
  101. {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/csv_to_agent.py +0 -0
  102. {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/de_hallucination_swarm.py +0 -0
  103. {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/graph_swarm.py +0 -0
  104. {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/graph_workflow.py +0 -0
  105. {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/groupchat.py +0 -0
  106. {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/hiearchical_swarm.py +0 -0
  107. {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/majority_voting.py +0 -0
  108. {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/malt.py +0 -0
  109. {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/matrix_swarm.py +0 -0
  110. {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/meme_agent_persona_generator.py +0 -0
  111. {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/mixture_of_agents.py +0 -0
  112. {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/model_router.py +0 -0
  113. {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/multi_agent_collab.py +0 -0
  114. {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/multi_agent_exec.py +0 -0
  115. {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/multi_agent_orchestrator.py +0 -0
  116. {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/octotools.py +0 -0
  117. {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/omni_agent_types.py +0 -0
  118. {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/output_type.py +0 -0
  119. {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/output_types.py +0 -0
  120. {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/pulsar_swarm.py +0 -0
  121. {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/queue_swarm.py +0 -0
  122. {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/rearrange.py +0 -0
  123. {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/round_robin.py +0 -0
  124. {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/safe_loading.py +0 -0
  125. {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/sequential_workflow.py +0 -0
  126. {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/spreadsheet_swarm.py +0 -0
  127. {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/stopping_conditions.py +0 -0
  128. {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/swarm_arange.py +0 -0
  129. {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/swarm_builder.py +0 -0
  130. {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/swarm_eval.py +0 -0
  131. {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/swarm_id_generator.py +0 -0
  132. {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/swarm_load_balancer.py +0 -0
  133. {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/swarm_matcher.py +0 -0
  134. {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/swarm_output_type.py +0 -0
  135. {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/swarm_registry.py +0 -0
  136. {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/swarm_router.py +0 -0
  137. {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/swarming_architectures.py +0 -0
  138. {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/swarms_api.py +0 -0
  139. {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/talk_hier.py +0 -0
  140. {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/tree_swarm.py +0 -0
  141. {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/utils.py +0 -0
  142. {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/various_alt_swarms.py +0 -0
  143. {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/workspace_manager.py +0 -0
  144. {swarms-7.5.7 → swarms-7.5.9}/swarms/telemetry/__init__.py +0 -0
  145. {swarms-7.5.7 → swarms-7.5.9}/swarms/telemetry/bootup.py +0 -0
  146. {swarms-7.5.7 → swarms-7.5.9}/swarms/telemetry/main.py +0 -0
  147. {swarms-7.5.7 → swarms-7.5.9}/swarms/tools/__init__.py +0 -0
  148. {swarms-7.5.7 → swarms-7.5.9}/swarms/tools/base_tool.py +0 -0
  149. {swarms-7.5.7 → swarms-7.5.9}/swarms/tools/cohere_func_call_schema.py +0 -0
  150. {swarms-7.5.7 → swarms-7.5.9}/swarms/tools/func_calling_utils.py +0 -0
  151. {swarms-7.5.7 → swarms-7.5.9}/swarms/tools/func_to_str.py +0 -0
  152. {swarms-7.5.7 → swarms-7.5.9}/swarms/tools/function_util.py +0 -0
  153. {swarms-7.5.7 → swarms-7.5.9}/swarms/tools/json_former.py +0 -0
  154. {swarms-7.5.7 → swarms-7.5.9}/swarms/tools/json_utils.py +0 -0
  155. {swarms-7.5.7 → swarms-7.5.9}/swarms/tools/logits_processor.py +0 -0
  156. {swarms-7.5.7 → swarms-7.5.9}/swarms/tools/openai_func_calling_schema_pydantic.py +0 -0
  157. {swarms-7.5.7 → swarms-7.5.9}/swarms/tools/openai_tool_creator_decorator.py +0 -0
  158. {swarms-7.5.7 → swarms-7.5.9}/swarms/tools/py_func_to_openai_func_str.py +0 -0
  159. {swarms-7.5.7 → swarms-7.5.9}/swarms/tools/pydantic_to_json.py +0 -0
  160. {swarms-7.5.7 → swarms-7.5.9}/swarms/tools/tool_parse_exec.py +0 -0
  161. {swarms-7.5.7 → swarms-7.5.9}/swarms/tools/tool_registry.py +0 -0
  162. {swarms-7.5.7 → swarms-7.5.9}/swarms/tools/tool_utils.py +0 -0
  163. {swarms-7.5.7 → swarms-7.5.9}/swarms/utils/__init__.py +0 -0
  164. {swarms-7.5.7 → swarms-7.5.9}/swarms/utils/agent_ops_check.py +0 -0
  165. {swarms-7.5.7 → swarms-7.5.9}/swarms/utils/any_to_str.py +0 -0
  166. {swarms-7.5.7 → swarms-7.5.9}/swarms/utils/auto_download_check_packages.py +0 -0
  167. {swarms-7.5.7 → swarms-7.5.9}/swarms/utils/calculate_func_metrics.py +0 -0
  168. {swarms-7.5.7 → swarms-7.5.9}/swarms/utils/data_to_text.py +0 -0
  169. {swarms-7.5.7 → swarms-7.5.9}/swarms/utils/disable_logging.py +0 -0
  170. {swarms-7.5.7 → swarms-7.5.9}/swarms/utils/file_processing.py +0 -0
  171. {swarms-7.5.7 → swarms-7.5.9}/swarms/utils/formatter.py +0 -0
  172. {swarms-7.5.7 → swarms-7.5.9}/swarms/utils/function_caller_model.py +0 -0
  173. {swarms-7.5.7 → swarms-7.5.9}/swarms/utils/history_output_formatter.py +0 -0
  174. {swarms-7.5.7 → swarms-7.5.9}/swarms/utils/litellm_tokenizer.py +0 -0
  175. {swarms-7.5.7 → swarms-7.5.9}/swarms/utils/litellm_wrapper.py +0 -0
  176. {swarms-7.5.7 → swarms-7.5.9}/swarms/utils/loguru_logger.py +0 -0
  177. {swarms-7.5.7 → swarms-7.5.9}/swarms/utils/markdown_message.py +0 -0
  178. {swarms-7.5.7 → swarms-7.5.9}/swarms/utils/pandas_utils.py +0 -0
  179. {swarms-7.5.7 → swarms-7.5.9}/swarms/utils/parse_code.py +0 -0
  180. {swarms-7.5.7 → swarms-7.5.9}/swarms/utils/pdf_to_text.py +0 -0
  181. {swarms-7.5.7 → swarms-7.5.9}/swarms/utils/swarm_reliability_checks.py +0 -0
  182. {swarms-7.5.7 → swarms-7.5.9}/swarms/utils/try_except_wrapper.py +0 -0
  183. {swarms-7.5.7 → swarms-7.5.9}/swarms/utils/visualizer.py +0 -0
  184. {swarms-7.5.7 → swarms-7.5.9}/swarms/utils/wrapper_clusterop.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: swarms
3
- Version: 7.5.7
3
+ Version: 7.5.9
4
4
  Summary: Swarms - TGSC
5
5
  Home-page: https://github.com/kyegomez/swarms
6
6
  License: MIT
@@ -5,7 +5,7 @@ build-backend = "poetry.core.masonry.api"
5
5
 
6
6
  [tool.poetry]
7
7
  name = "swarms"
8
- version = "7.5.7"
8
+ version = "7.5.9"
9
9
  description = "Swarms - TGSC"
10
10
  license = "MIT"
11
11
  authors = ["Kye Gomez <kye@apac.ai>"]
@@ -1,13 +1,11 @@
1
1
  import os
2
- from typing import List, Optional, Tuple
2
+ from typing import Any, List, Optional, Tuple
3
3
 
4
4
  from loguru import logger
5
5
  from pydantic import BaseModel, Field
6
6
 
7
7
  from swarms.structs.agent import Agent
8
- from swarms.utils.any_to_str import any_to_str
9
8
  from swarms.utils.function_caller_model import OpenAIFunctionCaller
10
- from swarms.utils.litellm_tokenizer import count_tokens
11
9
 
12
10
  BOSS_SYSTEM_PROMPT = """
13
11
  # Swarm Intelligence Orchestrator
@@ -148,13 +146,17 @@ class AgentsBuilder:
148
146
  description: str = "This is a swarm that creates swarms",
149
147
  verbose: bool = True,
150
148
  max_loops: int = 1,
149
+ model_name: str = "gpt-4o",
150
+ return_dictionary: bool = True,
151
151
  ):
152
152
  self.name = name
153
153
  self.description = description
154
154
  self.verbose = verbose
155
155
  self.max_loops = max_loops
156
156
  self.agents_pool = []
157
-
157
+ self.model_name = model_name
158
+ self.return_dictionary = return_dictionary
159
+
158
160
  logger.info(
159
161
  f"Initialized AutoSwarmBuilder: {name} {description}"
160
162
  )
@@ -174,11 +176,11 @@ class AgentsBuilder:
174
176
  The output from the swarm's execution
175
177
  """
176
178
  logger.info(f"Running swarm on task: {task}")
177
- agents, tokens = self._create_agents(
179
+ agents = self._create_agents(
178
180
  task, image_url, *args, **kwargs
179
181
  )
180
182
 
181
- return agents, tokens
183
+ return agents
182
184
 
183
185
  def _create_agents(self, task: str, *args, **kwargs):
184
186
  """Create the necessary agents for a task.
@@ -197,23 +199,28 @@ class AgentsBuilder:
197
199
  api_key=os.getenv("OPENAI_API_KEY"),
198
200
  temperature=0.1,
199
201
  base_model=Agents,
200
- model_name="gpt-4o",
202
+ model_name=self.model_name,
203
+ max_tokens = 8192,
201
204
  )
202
205
 
203
206
  agents_dictionary = model.run(task)
204
-
207
+ print(agents_dictionary)
208
+
209
+ print(type(agents_dictionary))
205
210
  logger.info("Agents successfully created")
206
211
  logger.info(f"Agents: {len(agents_dictionary.agents)}")
207
212
 
208
- total_tokens = any_to_str(agents_dictionary)
209
-
210
- tokens = count_tokens(total_tokens)
211
- # logger.info(f"Tokens: {tokens}")
212
-
213
- # # Convert dictionary to SwarmConfig if needed
214
- # if isinstance(agents_dictionary, dict):
215
- # agents_dictionary = Agents(**agents_dictionary)
216
-
213
+ if self.return_dictionary:
214
+ logger.info("Returning dictionary")
215
+
216
+ # Convert swarm config to dictionary
217
+ agents_dictionary = agents_dictionary.model_dump()
218
+ return agents_dictionary
219
+ else:
220
+ logger.info("Returning agents")
221
+ return self.create_agents(agents_dictionary)
222
+
223
+ def create_agents(self, agents_dictionary: Any):
217
224
  # Create agents from config
218
225
  agents = []
219
226
  for agent_config in agents_dictionary.agents:
@@ -235,7 +242,7 @@ class AgentsBuilder:
235
242
  )
236
243
  agents.append(agent)
237
244
 
238
- return agents, tokens
245
+ return agents
239
246
 
240
247
  def build_agent(
241
248
  self,
@@ -278,3 +285,10 @@ class AgentsBuilder:
278
285
  )
279
286
 
280
287
  return agent
288
+
289
+
290
+ # if __name__ == "__main__":
291
+ # builder = AgentsBuilder(model_name="gpt-4o")
292
+ # agents = builder.run("Create a swarm that can write a book about the history of the world")
293
+ # print(agents)
294
+ # print(type(agents))
@@ -0,0 +1,27 @@
1
+ import json
2
+ from typing import Dict
3
+
4
+
5
+ def str_to_dict(s: str, retries: int = 3) -> Dict:
6
+ """
7
+ Converts a JSON string to dictionary.
8
+
9
+ Args:
10
+ s (str): The JSON string to be converted.
11
+ retries (int): The number of times to retry parsing the string in case of a JSONDecodeError. Default is 3.
12
+
13
+ Returns:
14
+ Dict: The parsed dictionary from the JSON string.
15
+
16
+ Raises:
17
+ json.JSONDecodeError: If the string cannot be parsed into a dictionary after the specified number of retries.
18
+ """
19
+ for attempt in range(retries):
20
+ try:
21
+ # Run json.loads directly since it's fast enough
22
+ return json.loads(s)
23
+ except json.JSONDecodeError as e:
24
+ if attempt < retries - 1:
25
+ continue # Retry on failure
26
+ else:
27
+ raise e # Raise the error if all retries fail
@@ -1,51 +0,0 @@
1
- import json
2
- from typing import Dict
3
- import asyncio
4
-
5
-
6
- async def async_str_to_dict(s: str, retries: int = 3) -> Dict:
7
- """
8
- Asynchronously converts a JSON-formatted string to a dictionary.
9
-
10
- Args:
11
- s (str): The JSON string to be converted.
12
- retries (int): The number of times to retry parsing the string in case of a JSONDecodeError. Default is 3.
13
-
14
- Returns:
15
- Dict: The parsed dictionary from the JSON string.
16
-
17
- Raises:
18
- json.JSONDecodeError: If the string cannot be parsed into a dictionary after the specified number of retries.
19
- """
20
- for attempt in range(retries):
21
- try:
22
- # Run json.loads directly since it's fast enough
23
- return json.loads(s)
24
- except json.JSONDecodeError as e:
25
- if attempt < retries - 1:
26
- continue # Retry on failure
27
- else:
28
- raise e # Raise the error if all retries fail
29
-
30
-
31
- def str_to_dict(s: str, retries: int = 3) -> Dict:
32
- """
33
- Converts a JSON string to dictionary, handling both sync and async contexts.
34
-
35
- Args:
36
- s (str): The JSON string to be converted.
37
- retries (int): The number of times to retry parsing the string in case of a JSONDecodeError. Default is 3.
38
-
39
- Returns:
40
- Dict: The parsed dictionary from the JSON string.
41
- """
42
- # For simplicity and reliability, just try to parse the JSON directly first
43
- try:
44
- return json.loads(s)
45
- except json.JSONDecodeError:
46
- # If direct parsing fails, try the async path
47
- try:
48
- return async_str_to_dict(s, retries).__await__()
49
- except (AttributeError, RuntimeError):
50
- # If we can't await (not in async context), use run
51
- return asyncio.run(async_str_to_dict(s, retries))
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes