swarms 7.6.0__py3-none-any.whl → 7.6.2__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.
- swarms/agents/__init__.py +9 -2
- swarms/agents/agent_judge.py +119 -0
- swarms/agents/flexion_agent.py +625 -0
- swarms/agents/gkp_agent.py +581 -0
- swarms/agents/reasoning_agents.py +32 -0
- swarms/prompts/agent_judge_prompt.py +38 -0
- swarms/structs/__init__.py +7 -2
- swarms/structs/agent.py +37 -8
- swarms/structs/agent_builder.py +6 -8
- swarms/structs/concurrent_workflow.py +1 -1
- swarms/structs/deep_research_swarm.py +482 -0
- swarms/structs/dynamic_conversational_swarm.py +226 -0
- swarms/structs/hiearchical_swarm.py +1 -1
- swarms/structs/hybrid_hiearchical_peer_swarm.py +273 -0
- swarms/structs/majority_voting.py +1 -1
- swarms/structs/mixture_of_agents.py +1 -1
- swarms/structs/multi_agent_orchestrator.py +1 -1
- swarms/structs/output_types.py +3 -0
- swarms/structs/rearrange.py +1 -1
- swarms/structs/sequential_workflow.py +1 -1
- swarms/structs/swarm_router.py +12 -1
- swarms/structs/swarms_api.py +1 -1
- swarms/telemetry/main.py +7 -3
- swarms/tools/mcp_integration.py +554 -0
- swarms/tools/tool_schema_base_model.py +57 -0
- {swarms-7.6.0.dist-info → swarms-7.6.2.dist-info}/METADATA +79 -1
- {swarms-7.6.0.dist-info → swarms-7.6.2.dist-info}/RECORD +30 -24
- swarms/structs/agent_security.py +0 -318
- swarms/structs/airflow_swarm.py +0 -430
- swarms/structs/output_type.py +0 -18
- {swarms-7.6.0.dist-info → swarms-7.6.2.dist-info}/LICENSE +0 -0
- {swarms-7.6.0.dist-info → swarms-7.6.2.dist-info}/WHEEL +0 -0
- {swarms-7.6.0.dist-info → swarms-7.6.2.dist-info}/entry_points.txt +0 -0
@@ -1,13 +1,16 @@
|
|
1
1
|
swarms/__init__.py,sha256=DDfir3E4H8z1PlQqpc2HzovJQtNvIAzye4Fs165J0o8,512
|
2
|
-
swarms/agents/__init__.py,sha256=
|
2
|
+
swarms/agents/__init__.py,sha256=a0vqrSGmY93Z2Zi5uBg-B5WQJnEX0Wr0C2nfTcQAWCI,1225
|
3
|
+
swarms/agents/agent_judge.py,sha256=xT242CX5mV64cq2B-3RGkuEHiV5aD04P_Zq8_s64iMQ,3967
|
3
4
|
swarms/agents/agent_print.py,sha256=SXqWA2ZzXwRFdv8hkuYwOPMTasvaGTG6U29413qRCAA,918
|
4
5
|
swarms/agents/ape_agent.py,sha256=1kz_65LJgjLlY1yv2WLBeVMs7sP9BgEVWk0w1f67YLc,1563
|
5
6
|
swarms/agents/auto_generate_swarm_config.py,sha256=7eJ873xS7PJmyreMaa5Uub8qFu-qIinuyMuogB2Ehjc,8474
|
6
7
|
swarms/agents/consistency_agent.py,sha256=41h0yvnjzmKsE8-q4UsN0ckHP7WWmB5E_z64ec9QaJM,7414
|
7
8
|
swarms/agents/create_agents_from_yaml.py,sha256=PgFIpuYZehxEl79BAK6TolSZwydDQzvGMAKhLsHuBbc,13008
|
9
|
+
swarms/agents/flexion_agent.py,sha256=gVkQi5DDMLnYdyp2hkpgBnagDlMlKbnfnlWEaA8YrCo,21467
|
10
|
+
swarms/agents/gkp_agent.py,sha256=5Jms3zHQ2qwJ6-PHDh9X-cFtAlH4dSUoDgRqN-xZzog,21067
|
8
11
|
swarms/agents/i_agent.py,sha256=_eKUcgPfiVqQpF5Q-Sv1tT-JZxIeNl9Fp7OrnjVUtz8,12276
|
9
12
|
swarms/agents/openai_assistant.py,sha256=mTSEtj26J0mc5pCeWrmMY0EXzTRYQfyfw_BtOqtcCHc,11044
|
10
|
-
swarms/agents/reasoning_agents.py,sha256=
|
13
|
+
swarms/agents/reasoning_agents.py,sha256=tF7K710lj-VZQVc2VjqxMWGLNGMsEWRarXcJnXz1wkc,5741
|
11
14
|
swarms/agents/reasoning_duo.py,sha256=s9SnXoproQaBrShLtiruGJituy8sJlZJATc5Vy_FdwI,3875
|
12
15
|
swarms/agents/tool_agent.py,sha256=G7rhBACsHsGUMT4H9eF5aY7e3Gx-5jOmJkhCF1jm9mU,5087
|
13
16
|
swarms/artifacts/__init__.py,sha256=M111xTw7IVVt8gLDwW7Kau5n1YdwkL3vbCJPVeEWktI,83
|
@@ -20,6 +23,7 @@ swarms/prompts/__init__.py,sha256=ZFcghAs4b0Rsjcc_DIFssiztZub5tJ66rxmJD2_tXpQ,74
|
|
20
23
|
swarms/prompts/accountant_swarm_prompts.py,sha256=swceN1B0fZCOedd3-y3gjNOHDmR-3H5YK17ytp7tTDM,11320
|
21
24
|
swarms/prompts/ag_prompt.py,sha256=_mydaflPh3kPpogqfObJ9UK5D8ySAGgtcO4BoNBN3LE,2658
|
22
25
|
swarms/prompts/aga.py,sha256=4rRG7r9LF9JBrGOLN4Hy_6cSe0z5YOeKFbGnOmRfFJ0,9156
|
26
|
+
swarms/prompts/agent_judge_prompt.py,sha256=-2q5mWLRyO7pj7j512ZNYRm-uEZttPgDGaxZo3oM_QQ,2235
|
23
27
|
swarms/prompts/agent_prompt.py,sha256=6SXkMWcFIIAY02N9P6kMdzo4wtPwzg1Bl9R2qsIdicM,2705
|
24
28
|
swarms/prompts/agent_prompts.py,sha256=63ZqAO1jfH3TKtl9ibLLagSG5kAPlbq4xtCGgGEuuoA,6886
|
25
29
|
swarms/prompts/agent_system_prompts.py,sha256=DXHqZ1ELY4lg4LC37fNq52P2lRkNPjgOCfoan7r9vzY,7113
|
@@ -74,15 +78,13 @@ swarms/schemas/__init__.py,sha256=EqqtVcpoptF1kfy19Wykp22ut4AA0z-yMQ5H9WB7ptA,18
|
|
74
78
|
swarms/schemas/agent_input_schema.py,sha256=qhPyThMx2on91yG9mzNdP_08GpMh1IRDHDwFna29jPs,6345
|
75
79
|
swarms/schemas/agent_step_schemas.py,sha256=a14gb58vR0xOwB_fwSJQbN6yb9HddEaT30E6hUrzEQA,2573
|
76
80
|
swarms/schemas/base_schemas.py,sha256=UvBLVWg2qRen4tK5GJz50v42SiX95EQ5qK7hfyAHTEU,3267
|
77
|
-
swarms/structs/__init__.py,sha256=
|
78
|
-
swarms/structs/agent.py,sha256=
|
79
|
-
swarms/structs/agent_builder.py,sha256=
|
81
|
+
swarms/structs/__init__.py,sha256=S-I4b0CT6uZoUJht66JDFuKwi8yZ50TSW7rGjszEBdY,4578
|
82
|
+
swarms/structs/agent.py,sha256=X1IG7pB1PkHOdqOiUh9NbPhU-oZ6TuGqX8FwFoHOKVQ,97286
|
83
|
+
swarms/structs/agent_builder.py,sha256=tYNpfO4_8cgfMHfgA5DAOWffHnt70p6CLt59esqfVCY,12133
|
80
84
|
swarms/structs/agent_registry.py,sha256=il507cO1NF-d4ChyANVLuWrN8bXsEAi8_7bLJ_sTU6A,12112
|
81
85
|
swarms/structs/agent_roles.py,sha256=8XEw6RjOOZelaZaWt4gXaYQm5WMLEhSO7W6Z8sQjmFg,582
|
82
86
|
swarms/structs/agent_router.py,sha256=YZw5AaK2yTvxkOA7ouED_4MoYgn0XZggvo1wrglp-4E,13017
|
83
|
-
swarms/structs/agent_security.py,sha256=uDQ6zoCm6mY2eMGSpjo-vidZrnLSdd-LTD75OpXDpKw,10618
|
84
87
|
swarms/structs/agents_available.py,sha256=SedxDim-0IWgGsNwJZxRIUMfKyAFFXdvXSYeBNu0zGw,2804
|
85
|
-
swarms/structs/airflow_swarm.py,sha256=3wekDOYx4eLLO68eVvSO89_sv5G-4-uMpXTmrhsHPuE,14250
|
86
88
|
swarms/structs/async_workflow.py,sha256=7YWsLPyGY-1-mMxoIXWQ0FnYH6F227nxsS9PFAJoF9Q,26214
|
87
89
|
swarms/structs/auto_swarm.py,sha256=AHWswlEWDL_i3V8IP362tx6pi_B2arlZhALykrkI5OA,8215
|
88
90
|
swarms/structs/auto_swarm_builder.py,sha256=vPM5Kq59D_FvuWJB8hxgHuEvTXsxDxovlBnHGVQsM4o,10938
|
@@ -90,33 +92,35 @@ swarms/structs/base_structure.py,sha256=GDu4QJQQmhU7IyuFJHIh9UVThACCva-L7uoMbVD9
|
|
90
92
|
swarms/structs/base_swarm.py,sha256=_pggyl32BoEq-W2Cg-03h0z9xpPT_wXFjss4Yvysoxc,24033
|
91
93
|
swarms/structs/base_workflow.py,sha256=DTfFwX3AdFYxACDYwUDqhsbcDZnITlg5TeEYyxmJBCc,11414
|
92
94
|
swarms/structs/concat.py,sha256=utezSxNyh1mIwXgdf8-dJ803NDPyEy79WE8zJHuooGk,732
|
93
|
-
swarms/structs/concurrent_workflow.py,sha256=
|
95
|
+
swarms/structs/concurrent_workflow.py,sha256=MgK6xPjwCUrLHC1UzM4O45BELnVBoomgaw6CPa_9SgQ,15526
|
94
96
|
swarms/structs/conversation.py,sha256=7oh3x5XFyscnG1TAIMyL1BKJ4jC-unDEv-RFRVmxJO8,17966
|
95
97
|
swarms/structs/csv_to_agent.py,sha256=ug9JqQFPguXeU9JQpSUXuVtOpHYdJhlpKJUJBovo694,9443
|
96
98
|
swarms/structs/de_hallucination_swarm.py,sha256=Aa1kIJLmyXXrFl6qpmAq6mfkSaItQYD0MPgQ_e-nPvc,10305
|
99
|
+
swarms/structs/deep_research_swarm.py,sha256=h4jtrcuiAKMWMYo8I7oaq6eFn8cJpqHhml58EveNbZ4,16756
|
100
|
+
swarms/structs/dynamic_conversational_swarm.py,sha256=n_d1jDCzBwiGb0QjJpW_MlXxqEkhGEhC1ttaebH7f3Q,8098
|
97
101
|
swarms/structs/graph_swarm.py,sha256=HPHlLWwdSPSe4o-I06ZOIgtBg72a06llEnv8-aglf3Q,20962
|
98
102
|
swarms/structs/graph_workflow.py,sha256=TAaUG_J3898hhghPOp0WEAV3Zf0in6s48ZSVbSTX-vQ,8629
|
99
103
|
swarms/structs/groupchat.py,sha256=oLaWLuZ0ObHVXN9k3K8CpLSDSZwnCHBgJHsdGmHqAS8,15906
|
100
|
-
swarms/structs/hiearchical_swarm.py,sha256
|
101
|
-
swarms/structs/
|
104
|
+
swarms/structs/hiearchical_swarm.py,sha256=XDEdy5kAISmWKraMR26VX47eCT4YgGTI2FNcBQzIvLE,35274
|
105
|
+
swarms/structs/hybrid_hiearchical_peer_swarm.py,sha256=s6ievLmSo93feHB9xwHAQJIohPgLqco04dngvAFRxQw,9680
|
106
|
+
swarms/structs/majority_voting.py,sha256=F_t_MOC3YCRyMw5N6qKdFThpaXZxwixRw592Ku5Uhto,10122
|
102
107
|
swarms/structs/malt.py,sha256=0ZOuLfOzaJ4vAVOM6J1aZ3yWAiKxfMkNIBNp8pjsEqE,19392
|
103
108
|
swarms/structs/matrix_swarm.py,sha256=qHuhOYrTyOv6ujHMe8PrQT-h-WmaCPCfX4ghv5L8UFI,9765
|
104
109
|
swarms/structs/meme_agent_persona_generator.py,sha256=b3kKlumhsV4KV88-GS3CUnGO1UfKTU3fT8SAMj0ZlwQ,10645
|
105
|
-
swarms/structs/mixture_of_agents.py,sha256=
|
110
|
+
swarms/structs/mixture_of_agents.py,sha256=G8_MVMrDd0-ZD_gJ5YZgtTCUjl7COha9Me-vOYMXsAE,10575
|
106
111
|
swarms/structs/model_router.py,sha256=V5pZHYlxSmCvAA2Gsns7LaCz8dXtRi7pCvb-oLGHYIY,12739
|
107
112
|
swarms/structs/multi_agent_collab.py,sha256=odh2NQRR23LidsphCxUfAke369lDdgL__w3Xovu9jkA,7731
|
108
113
|
swarms/structs/multi_agent_exec.py,sha256=NbR-CnxxBuCa0Ll3Os9wfKdkIsQiCpqsTgFX9hWRefw,17421
|
109
|
-
swarms/structs/multi_agent_orchestrator.py,sha256=
|
114
|
+
swarms/structs/multi_agent_orchestrator.py,sha256=_trjXCW31ZeVR7N2hURLUPDZhYa-Wa3ADMk1wnNJdcQ,13400
|
110
115
|
swarms/structs/octotools.py,sha256=GZo0qtFM69W7vvewk6_k09vicgw0c0_v7MiPvEZCagE,31406
|
111
116
|
swarms/structs/omni_agent_types.py,sha256=RdKLfZ-lXDJrEa0aJT_Rfx9TypJQo8SISqKz4fnLkAk,230
|
112
|
-
swarms/structs/
|
113
|
-
swarms/structs/output_types.py,sha256=i56WfkzUR6YgP1qINJ8t-By8OVS_sdbO64IvCmV-pbM,213
|
117
|
+
swarms/structs/output_types.py,sha256=F1jNbDLJrubRIUyheMGMahJfGikbWZ_yNmbE9QVIz9A,280
|
114
118
|
swarms/structs/pulsar_swarm.py,sha256=4_L0GqPBgnA3AJajpNLgO4IAG6U36nIntFK9WNJScv8,15968
|
115
119
|
swarms/structs/queue_swarm.py,sha256=8vcA-rh280midcdgfA5IwJzBmMgdn71nRH6KndWu-DA,6770
|
116
|
-
swarms/structs/rearrange.py,sha256=
|
120
|
+
swarms/structs/rearrange.py,sha256=_WiWNab5NFRhpeXrlO_57o2Q0j194A-6k405Gwr4hQU,28639
|
117
121
|
swarms/structs/round_robin.py,sha256=MGk623KiN9uSxTMG6MY_BIAkvEDh1RPwyl5Min7GLOU,7573
|
118
122
|
swarms/structs/safe_loading.py,sha256=gmYX8G9TsvAIp6OCvREBZt5mwSFc-p-t1rSnDBfhEmE,7124
|
119
|
-
swarms/structs/sequential_workflow.py,sha256=
|
123
|
+
swarms/structs/sequential_workflow.py,sha256=KrIfR9SToNTdyBTDd3DYvXbYa3SNELxUbeYDdjVhUZo,8685
|
120
124
|
swarms/structs/spreadsheet_swarm.py,sha256=ToX56QJjlm_nnC3MYppvKC_NTr9Zy_orkBzfxNLdwbA,14845
|
121
125
|
swarms/structs/stopping_conditions.py,sha256=Z0Jx0U2feAfQfuVV_IJGgal62DoVsGPN8K6HkkqB_bM,484
|
122
126
|
swarms/structs/swarm_arange.py,sha256=6fexCPsXRgdLbpY0p9rp_REipeXzsbv1_GOtD9B4HaI,15179
|
@@ -127,9 +131,9 @@ swarms/structs/swarm_load_balancer.py,sha256=pUCc5FEBcuJ_GmOFeTWBPfXlUdiTOjYcJqV
|
|
127
131
|
swarms/structs/swarm_matcher.py,sha256=E2KwHHEJxmW-UfTeMPWZ6VCmYdQ_I9_fwrfJbxD02GY,23322
|
128
132
|
swarms/structs/swarm_output_type.py,sha256=tW8Iqar1Jaf2Lzw66nAPc6MDk7-srQl5_XUKFvzoam4,755
|
129
133
|
swarms/structs/swarm_registry.py,sha256=P0XRrqp1qBNyt0BycqPQljUzKv9jClaQMhtaBMinhYg,5578
|
130
|
-
swarms/structs/swarm_router.py,sha256=
|
134
|
+
swarms/structs/swarm_router.py,sha256=A7efNKGkyj_Tqjv8v-bJJVkl22zyiNBLAlJqWNFtWjM,26803
|
131
135
|
swarms/structs/swarming_architectures.py,sha256=VvkSA9nQnF91V2C5-ALwSY1peZckeM1G4pPeQS7IVsE,13109
|
132
|
-
swarms/structs/swarms_api.py,sha256=
|
136
|
+
swarms/structs/swarms_api.py,sha256=f-RpvfKfRK2AaapkyPN2ihXJvIGN4JWB_A7pJu4WyiU,13735
|
133
137
|
swarms/structs/talk_hier.py,sha256=npyEuL52SCgQmMynIvGjfatNqOz4toq0EyhEtSNmQhQ,25649
|
134
138
|
swarms/structs/tree_swarm.py,sha256=AnIxrt0KhWxAQN8uGjfCcOq-XCmsuTJiH8Ex4mXy8V8,12500
|
135
139
|
swarms/structs/utils.py,sha256=Mo6wHQYOB8baWZUKnAJN5Dsgubpo81umNwJIEDitb2A,1873
|
@@ -137,7 +141,7 @@ swarms/structs/various_alt_swarms.py,sha256=qdBuOF31UjatlKRu-9bxwyRQzIjohRhTv_63
|
|
137
141
|
swarms/structs/workspace_manager.py,sha256=t0OgUP9dDU7xS6N3mAT2PbXvjHTsUK3nf2mxppcfZ70,5473
|
138
142
|
swarms/telemetry/__init__.py,sha256=yibtkHEbQRPUv6ir1FhDHlAO_3nwKJPQH4LjzBC2AuQ,661
|
139
143
|
swarms/telemetry/bootup.py,sha256=tBuhOb3m7o2q7nMjb2j9v2ib5Hx2E9Oya8yff5z4zIA,1655
|
140
|
-
swarms/telemetry/main.py,sha256=
|
144
|
+
swarms/telemetry/main.py,sha256=ZoVvf4XInh0Q5CcfwBFj9KmpxrQjOm2Aje70CElgGZA,8420
|
141
145
|
swarms/tools/__init__.py,sha256=pqIMcRQr4gtoNdbyI1N5k4upkYSBMxACJbxfB9yrV4c,1493
|
142
146
|
swarms/tools/base_tool.py,sha256=BiBCFHin8AyZO3FYOGA-n3M2o-F36xUeIBUiybnZYjI,15179
|
143
147
|
swarms/tools/cohere_func_call_schema.py,sha256=XJ6_yBMXCrV9KjN7v9Bk1iFj69TRlGIWYKsUTA1oGiQ,600
|
@@ -147,12 +151,14 @@ swarms/tools/function_util.py,sha256=DAnAPO0Ik__TAqL7IJzFmkukHnhpsW_QtALl3yj837g
|
|
147
151
|
swarms/tools/json_former.py,sha256=4ugLQ_EZpghhuhFsVKsy-ehin9K64pqVE2gLU7BTO_M,14376
|
148
152
|
swarms/tools/json_utils.py,sha256=WKMZjcJ0Vt6lgIjiTBenslcfjgRSLX4UWs4uDkKFMQI,1316
|
149
153
|
swarms/tools/logits_processor.py,sha256=NifZZ5w9yemWGJAJ5nHFrphtZVX1XlyesgvYZTxK1GM,2965
|
154
|
+
swarms/tools/mcp_integration.py,sha256=Aqt2gLTIinJdHM_ZnIICqCXp2Fz_AbDPfaJVljDuIAI,17529
|
150
155
|
swarms/tools/openai_func_calling_schema_pydantic.py,sha256=6BAH9kuaVTvJIbjgSSJ5XvHhWvWszPxgarkfUuE5Ads,978
|
151
156
|
swarms/tools/openai_tool_creator_decorator.py,sha256=SYZjHnARjWvnH9cBdj7Kc_Yy1muvNxMT3RQz8KkA2SE,2578
|
152
157
|
swarms/tools/py_func_to_openai_func_str.py,sha256=W112Gu0CmAiHrNWnRMcnoGiVZEy2FxAU4xMvnG9XP4g,15710
|
153
158
|
swarms/tools/pydantic_to_json.py,sha256=-tjUBwKVnKUWWtEGfYGLEfJbIOCrSVF-p1e6kT4_Geg,3850
|
154
159
|
swarms/tools/tool_parse_exec.py,sha256=FW5XzkuNEs2YrroybjKChbCzDvaCs7ypknSDpYhfkd4,8717
|
155
160
|
swarms/tools/tool_registry.py,sha256=ULZmIKBTx9XRCJRD9hwXfY3iQw9v94arw-VV6jcuftY,7992
|
161
|
+
swarms/tools/tool_schema_base_model.py,sha256=0biTGIoibsPPP3fOrkC6WvNU5vXaalyccVKC1fpO_eg,1409
|
156
162
|
swarms/tools/tool_utils.py,sha256=yXzzqG7Ytd8ybB8bsjNUNLaXIuIp9JbbpUKCiHxQqo8,2816
|
157
163
|
swarms/utils/__init__.py,sha256=9qKE_11pxom74j3qExSm6Z_LwR5lrpC5YG17v22eLlo,975
|
158
164
|
swarms/utils/agent_ops_check.py,sha256=08UomeSv1uw_oEDlum0yG-5SsKkxqPRbeIWeKC75b08,685
|
@@ -177,8 +183,8 @@ swarms/utils/swarm_reliability_checks.py,sha256=MsgUULt3HYg72D0HifZNmtCyJYpLA2UD
|
|
177
183
|
swarms/utils/try_except_wrapper.py,sha256=appEGu9Afy3TmdkNNXUgQ9yU9lj2j0uNkIoW0JhVzzY,3917
|
178
184
|
swarms/utils/visualizer.py,sha256=0ylohEk62MAS6iPRaDOV03m9qo2k5J56tWlKJk_46p4,16927
|
179
185
|
swarms/utils/wrapper_clusterop.py,sha256=PMSCVM7ZT1vgj1D_MYAe835RR3SMLYxA-si2JS02yNQ,4220
|
180
|
-
swarms-7.6.
|
181
|
-
swarms-7.6.
|
182
|
-
swarms-7.6.
|
183
|
-
swarms-7.6.
|
184
|
-
swarms-7.6.
|
186
|
+
swarms-7.6.2.dist-info/LICENSE,sha256=jwRtEmTWjLrEsvFB6QFdYs2cEeZPRMdj-UMOFkPF8_0,11363
|
187
|
+
swarms-7.6.2.dist-info/METADATA,sha256=WGZDZCWtB66TM0b9VrFeXvKaD1fKdAkQi2itc4u7mkA,105115
|
188
|
+
swarms-7.6.2.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
189
|
+
swarms-7.6.2.dist-info/entry_points.txt,sha256=2K0rTtfO1X1WaO-waJlXIKw5Voa_EpAL_yU0HXE2Jgc,47
|
190
|
+
swarms-7.6.2.dist-info/RECORD,,
|
swarms/structs/agent_security.py
DELETED
@@ -1,318 +0,0 @@
|
|
1
|
-
import base64
|
2
|
-
import json
|
3
|
-
import uuid
|
4
|
-
from datetime import datetime
|
5
|
-
from dataclasses import dataclass
|
6
|
-
from typing import Optional, Union, Dict, List
|
7
|
-
|
8
|
-
from cryptography.fernet import Fernet
|
9
|
-
from cryptography.hazmat.primitives import hashes, serialization
|
10
|
-
from cryptography.hazmat.primitives.asymmetric import padding, rsa
|
11
|
-
from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC
|
12
|
-
|
13
|
-
|
14
|
-
@dataclass
|
15
|
-
class EncryptedMessage:
|
16
|
-
"""Structure for encrypted messages between agents"""
|
17
|
-
|
18
|
-
sender_id: str
|
19
|
-
receiver_id: str
|
20
|
-
encrypted_content: bytes
|
21
|
-
timestamp: float
|
22
|
-
message_id: str
|
23
|
-
session_id: str
|
24
|
-
|
25
|
-
|
26
|
-
class EncryptionSession:
|
27
|
-
"""Represents an encrypted communication session between agents"""
|
28
|
-
|
29
|
-
def __init__(
|
30
|
-
self,
|
31
|
-
session_id: str,
|
32
|
-
agent_ids: List[str],
|
33
|
-
encrypted_keys: Dict[str, bytes],
|
34
|
-
created_at: datetime,
|
35
|
-
):
|
36
|
-
self.session_id = session_id
|
37
|
-
self.agent_ids = agent_ids
|
38
|
-
self.encrypted_keys = encrypted_keys
|
39
|
-
self.created_at = created_at
|
40
|
-
|
41
|
-
|
42
|
-
class AgentEncryption:
|
43
|
-
"""
|
44
|
-
Handles encryption for agent data both at rest and in transit.
|
45
|
-
Supports both symmetric (for data at rest) and asymmetric (for data in transit) encryption.
|
46
|
-
Also supports secure multi-agent communication.
|
47
|
-
"""
|
48
|
-
|
49
|
-
def __init__(
|
50
|
-
self,
|
51
|
-
agent_id: Optional[str] = None,
|
52
|
-
encryption_key: Optional[str] = None,
|
53
|
-
enable_transit_encryption: bool = False,
|
54
|
-
enable_rest_encryption: bool = False,
|
55
|
-
enable_multi_agent: bool = False,
|
56
|
-
):
|
57
|
-
self.agent_id = agent_id or str(uuid.uuid4())
|
58
|
-
self.enable_transit_encryption = enable_transit_encryption
|
59
|
-
self.enable_rest_encryption = enable_rest_encryption
|
60
|
-
self.enable_multi_agent = enable_multi_agent
|
61
|
-
|
62
|
-
# Multi-agent communication storage
|
63
|
-
self.sessions: Dict[str, EncryptionSession] = {}
|
64
|
-
self.known_agents: Dict[str, "AgentEncryption"] = {}
|
65
|
-
|
66
|
-
if enable_rest_encryption:
|
67
|
-
# Initialize encryption for data at rest
|
68
|
-
if encryption_key:
|
69
|
-
self.encryption_key = base64.urlsafe_b64encode(
|
70
|
-
PBKDF2HMAC(
|
71
|
-
algorithm=hashes.SHA256(),
|
72
|
-
length=32,
|
73
|
-
salt=f"agent_{self.agent_id}".encode(), # Unique salt per agent
|
74
|
-
iterations=100000,
|
75
|
-
).derive(encryption_key.encode())
|
76
|
-
)
|
77
|
-
else:
|
78
|
-
self.encryption_key = Fernet.generate_key()
|
79
|
-
|
80
|
-
self.cipher_suite = Fernet(self.encryption_key)
|
81
|
-
|
82
|
-
if enable_transit_encryption or enable_multi_agent:
|
83
|
-
# Generate RSA key pair for transit encryption
|
84
|
-
self.private_key = rsa.generate_private_key(
|
85
|
-
public_exponent=65537, key_size=2048
|
86
|
-
)
|
87
|
-
self.public_key = self.private_key.public_key()
|
88
|
-
|
89
|
-
def register_agent(
|
90
|
-
self, agent_id: str, agent_encryption: "AgentEncryption"
|
91
|
-
) -> None:
|
92
|
-
"""Register another agent for secure communication"""
|
93
|
-
if not self.enable_multi_agent:
|
94
|
-
raise ValueError("Multi-agent support is not enabled")
|
95
|
-
self.known_agents[agent_id] = agent_encryption
|
96
|
-
|
97
|
-
def create_session(self, agent_ids: List[str]) -> str:
|
98
|
-
"""Create a new encrypted session between multiple agents"""
|
99
|
-
if not self.enable_multi_agent:
|
100
|
-
raise ValueError("Multi-agent support is not enabled")
|
101
|
-
|
102
|
-
session_id = str(uuid.uuid4())
|
103
|
-
|
104
|
-
# Generate a shared session key
|
105
|
-
session_key = Fernet.generate_key()
|
106
|
-
|
107
|
-
# Create encrypted copies of the session key for each agent
|
108
|
-
encrypted_keys = {}
|
109
|
-
for agent_id in agent_ids:
|
110
|
-
if (
|
111
|
-
agent_id not in self.known_agents
|
112
|
-
and agent_id != self.agent_id
|
113
|
-
):
|
114
|
-
raise ValueError(f"Agent {agent_id} not registered")
|
115
|
-
|
116
|
-
if agent_id == self.agent_id:
|
117
|
-
agent_public_key = self.public_key
|
118
|
-
else:
|
119
|
-
agent_public_key = self.known_agents[
|
120
|
-
agent_id
|
121
|
-
].public_key
|
122
|
-
|
123
|
-
encrypted_key = agent_public_key.encrypt(
|
124
|
-
session_key,
|
125
|
-
padding.OAEP(
|
126
|
-
mgf=padding.MGF1(algorithm=hashes.SHA256()),
|
127
|
-
algorithm=hashes.SHA256(),
|
128
|
-
label=None,
|
129
|
-
),
|
130
|
-
)
|
131
|
-
encrypted_keys[agent_id] = encrypted_key
|
132
|
-
|
133
|
-
# Store session information
|
134
|
-
self.sessions[session_id] = EncryptionSession(
|
135
|
-
session_id=session_id,
|
136
|
-
agent_ids=agent_ids,
|
137
|
-
encrypted_keys=encrypted_keys,
|
138
|
-
created_at=datetime.now(),
|
139
|
-
)
|
140
|
-
|
141
|
-
return session_id
|
142
|
-
|
143
|
-
def encrypt_message(
|
144
|
-
self,
|
145
|
-
content: Union[str, dict],
|
146
|
-
receiver_id: str,
|
147
|
-
session_id: str,
|
148
|
-
) -> EncryptedMessage:
|
149
|
-
"""Encrypt a message for another agent within a session"""
|
150
|
-
if not self.enable_multi_agent:
|
151
|
-
raise ValueError("Multi-agent support is not enabled")
|
152
|
-
|
153
|
-
if session_id not in self.sessions:
|
154
|
-
raise ValueError("Invalid session ID")
|
155
|
-
|
156
|
-
session = self.sessions[session_id]
|
157
|
-
if (
|
158
|
-
self.agent_id not in session.agent_ids
|
159
|
-
or receiver_id not in session.agent_ids
|
160
|
-
):
|
161
|
-
raise ValueError("Sender or receiver not in session")
|
162
|
-
|
163
|
-
# Serialize content if it's a dictionary
|
164
|
-
if isinstance(content, dict):
|
165
|
-
content = json.dumps(content)
|
166
|
-
|
167
|
-
# Get the session key
|
168
|
-
encrypted_session_key = session.encrypted_keys[self.agent_id]
|
169
|
-
session_key = self.decrypt_session_key(encrypted_session_key)
|
170
|
-
|
171
|
-
# Create Fernet cipher with session key
|
172
|
-
cipher = Fernet(session_key)
|
173
|
-
|
174
|
-
# Encrypt the message
|
175
|
-
encrypted_content = cipher.encrypt(content.encode())
|
176
|
-
|
177
|
-
return EncryptedMessage(
|
178
|
-
sender_id=self.agent_id,
|
179
|
-
receiver_id=receiver_id,
|
180
|
-
encrypted_content=encrypted_content,
|
181
|
-
timestamp=datetime.now().timestamp(),
|
182
|
-
message_id=str(uuid.uuid4()),
|
183
|
-
session_id=session_id,
|
184
|
-
)
|
185
|
-
|
186
|
-
def decrypt_message(
|
187
|
-
self, message: EncryptedMessage
|
188
|
-
) -> Union[str, dict]:
|
189
|
-
"""Decrypt a message from another agent"""
|
190
|
-
if not self.enable_multi_agent:
|
191
|
-
raise ValueError("Multi-agent support is not enabled")
|
192
|
-
|
193
|
-
if message.session_id not in self.sessions:
|
194
|
-
raise ValueError("Invalid session ID")
|
195
|
-
|
196
|
-
if self.agent_id != message.receiver_id:
|
197
|
-
raise ValueError("Message not intended for this agent")
|
198
|
-
|
199
|
-
session = self.sessions[message.session_id]
|
200
|
-
|
201
|
-
# Get the session key
|
202
|
-
encrypted_session_key = session.encrypted_keys[self.agent_id]
|
203
|
-
session_key = self.decrypt_session_key(encrypted_session_key)
|
204
|
-
|
205
|
-
# Create Fernet cipher with session key
|
206
|
-
cipher = Fernet(session_key)
|
207
|
-
|
208
|
-
# Decrypt the message
|
209
|
-
decrypted_content = cipher.decrypt(
|
210
|
-
message.encrypted_content
|
211
|
-
).decode()
|
212
|
-
|
213
|
-
# Try to parse as JSON
|
214
|
-
try:
|
215
|
-
return json.loads(decrypted_content)
|
216
|
-
except json.JSONDecodeError:
|
217
|
-
return decrypted_content
|
218
|
-
|
219
|
-
def decrypt_session_key(self, encrypted_key: bytes) -> bytes:
|
220
|
-
"""Decrypt a session key using the agent's private key"""
|
221
|
-
return self.private_key.decrypt(
|
222
|
-
encrypted_key,
|
223
|
-
padding.OAEP(
|
224
|
-
mgf=padding.MGF1(algorithm=hashes.SHA256()),
|
225
|
-
algorithm=hashes.SHA256(),
|
226
|
-
label=None,
|
227
|
-
),
|
228
|
-
)
|
229
|
-
|
230
|
-
# Original methods preserved below
|
231
|
-
def encrypt_at_rest(self, data: Union[str, dict, bytes]) -> bytes:
|
232
|
-
"""Encrypts data for storage"""
|
233
|
-
if not self.enable_rest_encryption:
|
234
|
-
return (
|
235
|
-
data
|
236
|
-
if isinstance(data, bytes)
|
237
|
-
else str(data).encode()
|
238
|
-
)
|
239
|
-
|
240
|
-
if isinstance(data, dict):
|
241
|
-
data = json.dumps(data)
|
242
|
-
if isinstance(data, str):
|
243
|
-
data = data.encode()
|
244
|
-
|
245
|
-
return self.cipher_suite.encrypt(data)
|
246
|
-
|
247
|
-
def decrypt_at_rest(
|
248
|
-
self, encrypted_data: bytes
|
249
|
-
) -> Union[str, dict]:
|
250
|
-
"""Decrypts stored data"""
|
251
|
-
if not self.enable_rest_encryption:
|
252
|
-
return encrypted_data.decode()
|
253
|
-
|
254
|
-
decrypted_data = self.cipher_suite.decrypt(encrypted_data)
|
255
|
-
|
256
|
-
try:
|
257
|
-
return json.loads(decrypted_data)
|
258
|
-
except json.JSONDecodeError:
|
259
|
-
return decrypted_data.decode()
|
260
|
-
|
261
|
-
def encrypt_for_transit(self, data: Union[str, dict]) -> bytes:
|
262
|
-
"""Encrypts data for transmission"""
|
263
|
-
if not self.enable_transit_encryption:
|
264
|
-
return str(data).encode()
|
265
|
-
|
266
|
-
if isinstance(data, dict):
|
267
|
-
data = json.dumps(data)
|
268
|
-
|
269
|
-
return self.public_key.encrypt(
|
270
|
-
data.encode(),
|
271
|
-
padding.OAEP(
|
272
|
-
mgf=padding.MGF1(algorithm=hashes.SHA256()),
|
273
|
-
algorithm=hashes.SHA256(),
|
274
|
-
label=None,
|
275
|
-
),
|
276
|
-
)
|
277
|
-
|
278
|
-
def decrypt_from_transit(
|
279
|
-
self, data: Union[bytes, str]
|
280
|
-
) -> Union[str, dict]:
|
281
|
-
"""Decrypts received data, handling both encrypted and unencrypted inputs"""
|
282
|
-
if not self.enable_transit_encryption:
|
283
|
-
return data.decode() if isinstance(data, bytes) else data
|
284
|
-
|
285
|
-
try:
|
286
|
-
if isinstance(data, bytes) and len(data) == 256:
|
287
|
-
decrypted_data = self.private_key.decrypt(
|
288
|
-
data,
|
289
|
-
padding.OAEP(
|
290
|
-
mgf=padding.MGF1(algorithm=hashes.SHA256()),
|
291
|
-
algorithm=hashes.SHA256(),
|
292
|
-
label=None,
|
293
|
-
),
|
294
|
-
).decode()
|
295
|
-
else:
|
296
|
-
return (
|
297
|
-
data.decode() if isinstance(data, bytes) else data
|
298
|
-
)
|
299
|
-
|
300
|
-
try:
|
301
|
-
return json.loads(decrypted_data)
|
302
|
-
except json.JSONDecodeError:
|
303
|
-
return decrypted_data
|
304
|
-
except ValueError:
|
305
|
-
return data.decode() if isinstance(data, bytes) else data
|
306
|
-
|
307
|
-
def get_public_key_pem(self) -> bytes:
|
308
|
-
"""Returns the public key in PEM format for sharing"""
|
309
|
-
if (
|
310
|
-
not self.enable_transit_encryption
|
311
|
-
and not self.enable_multi_agent
|
312
|
-
):
|
313
|
-
return b""
|
314
|
-
|
315
|
-
return self.public_key.public_bytes(
|
316
|
-
encoding=serialization.Encoding.PEM,
|
317
|
-
format=serialization.PublicFormat.SubjectPublicKeyInfo,
|
318
|
-
)
|