strands-swarms 0.1.0__tar.gz → 0.1.2__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.
- strands_swarms-0.1.2/.claude/settings.local.json +12 -0
- strands_swarms-0.1.2/.github/workflows/ci.yml +50 -0
- {strands_swarms-0.1.0 → strands_swarms-0.1.2}/.gitignore +1 -0
- strands_swarms-0.1.2/PKG-INFO +171 -0
- strands_swarms-0.1.2/README.md +143 -0
- strands_swarms-0.1.2/examples/simple.py +51 -0
- {strands_swarms-0.1.0 → strands_swarms-0.1.2}/pyproject.toml +6 -3
- {strands_swarms-0.1.0 → strands_swarms-0.1.2}/src/strands_swarms/__init__.py +33 -46
- strands_swarms-0.1.2/src/strands_swarms/definition.py +169 -0
- strands_swarms-0.1.2/src/strands_swarms/dynamic_swarm.py +439 -0
- strands_swarms-0.1.2/src/strands_swarms/orchestrator.py +116 -0
- strands_swarms-0.1.0/PKG-INFO +0 -386
- strands_swarms-0.1.0/README.md +0 -359
- strands_swarms-0.1.0/examples/dynamic_swarm.py +0 -207
- strands_swarms-0.1.0/src/strands_swarms/events.py +0 -564
- strands_swarms-0.1.0/src/strands_swarms/orchestrator.py +0 -265
- strands_swarms-0.1.0/src/strands_swarms/py.typed +0 -0
- strands_swarms-0.1.0/src/strands_swarms/swarm.py +0 -738
- {strands_swarms-0.1.0 → strands_swarms-0.1.2}/LICENSE +0 -0
- {strands_swarms-0.1.0 → strands_swarms-0.1.2}/assets/architecture.png +0 -0
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [main]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
lint:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
steps:
|
|
13
|
+
- uses: actions/checkout@v4
|
|
14
|
+
- name: Set up Python
|
|
15
|
+
uses: actions/setup-python@v5
|
|
16
|
+
with:
|
|
17
|
+
python-version: "3.12"
|
|
18
|
+
- name: Install dependencies
|
|
19
|
+
run: |
|
|
20
|
+
python -m pip install --upgrade pip
|
|
21
|
+
pip install ruff mypy
|
|
22
|
+
pip install -e .
|
|
23
|
+
- name: Lint with ruff
|
|
24
|
+
run: ruff check src/
|
|
25
|
+
- name: Type check with mypy
|
|
26
|
+
run: mypy src/
|
|
27
|
+
|
|
28
|
+
test:
|
|
29
|
+
runs-on: ubuntu-latest
|
|
30
|
+
strategy:
|
|
31
|
+
fail-fast: false
|
|
32
|
+
matrix:
|
|
33
|
+
python-version: ["3.10", "3.11", "3.12", "3.13"]
|
|
34
|
+
steps:
|
|
35
|
+
- uses: actions/checkout@v4
|
|
36
|
+
- name: Set up Python ${{ matrix.python-version }}
|
|
37
|
+
uses: actions/setup-python@v5
|
|
38
|
+
with:
|
|
39
|
+
python-version: ${{ matrix.python-version }}
|
|
40
|
+
- name: Install dependencies
|
|
41
|
+
run: |
|
|
42
|
+
python -m pip install --upgrade pip
|
|
43
|
+
pip install -e ".[dev]"
|
|
44
|
+
- name: Run tests
|
|
45
|
+
run: |
|
|
46
|
+
if [ -d "tests" ]; then
|
|
47
|
+
pytest -v
|
|
48
|
+
else
|
|
49
|
+
echo "No tests directory found, skipping tests"
|
|
50
|
+
fi
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: strands-swarms
|
|
3
|
+
Version: 0.1.2
|
|
4
|
+
Summary: Task-based workflow orchestration for Strands Agents
|
|
5
|
+
Project-URL: Homepage, https://github.com/JackXu0/strands-swarms
|
|
6
|
+
Project-URL: Issues, https://github.com/JackXu0/strands-swarms/issues
|
|
7
|
+
Author-email: Zhuocheng Xu <zhuocheng.xu@icloud.com>
|
|
8
|
+
License: Apache-2.0
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
20
|
+
Requires-Python: >=3.10
|
|
21
|
+
Requires-Dist: strands-agents>=0.1.0
|
|
22
|
+
Provides-Extra: dev
|
|
23
|
+
Requires-Dist: mypy>=1.15.0; extra == 'dev'
|
|
24
|
+
Requires-Dist: pytest-asyncio>=1.0.0; extra == 'dev'
|
|
25
|
+
Requires-Dist: pytest>=8.0.0; extra == 'dev'
|
|
26
|
+
Requires-Dist: ruff>=0.13.0; extra == 'dev'
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
|
|
29
|
+
# strands-swarms
|
|
30
|
+
|
|
31
|
+
[](https://github.com/JackXu0/strands-swarms/actions/workflows/ci.yml)
|
|
32
|
+
[](https://pypi.org/project/strands-swarms/)
|
|
33
|
+
[](https://opensource.org/licenses/Apache-2.0)
|
|
34
|
+
|
|
35
|
+
**Turn natural language into multi-agent workflows — automatically.**
|
|
36
|
+
|
|
37
|
+
Give `DynamicSwarm` a query, and it automatically plans the workflow, spawns specialized agents, and executes tasks with dependencies. No manual graph configuration or agent wiring required.
|
|
38
|
+
|
|
39
|
+
```python
|
|
40
|
+
swarm = DynamicSwarm(available_tools={...}, available_models={...})
|
|
41
|
+
result = swarm.execute("Research AI trends and write a summary report")
|
|
42
|
+
# → Spawns researcher + writer agents, handles dependencies, returns final report
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Inspiration
|
|
46
|
+
|
|
47
|
+
This project is inspired by [Kimi K2.5's Agent Swarm](https://www.kimi.com/blog/kimi-k2-5.html) — where a trainable orchestrator dynamically creates and coordinates sub-agents without predefined roles or workflows. The goal is to build an open-source foundation for training orchestrators that can spin up agent swarms on the fly.
|
|
48
|
+
|
|
49
|
+
## How It Works
|
|
50
|
+
|
|
51
|
+

|
|
52
|
+
|
|
53
|
+
## Installation
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
pip install strands-swarms
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Quick Start
|
|
60
|
+
|
|
61
|
+
```python
|
|
62
|
+
from strands import tool
|
|
63
|
+
from strands.models import BedrockModel
|
|
64
|
+
from strands_swarms import DynamicSwarm
|
|
65
|
+
|
|
66
|
+
# Define your tools
|
|
67
|
+
@tool
|
|
68
|
+
def search_web(query: str) -> str:
|
|
69
|
+
"""Search the web for information."""
|
|
70
|
+
return f"[Search Results for '{query}']\n- Result 1: Latest developments..."
|
|
71
|
+
|
|
72
|
+
@tool
|
|
73
|
+
def analyze_data(data: str) -> str:
|
|
74
|
+
"""Analyze data and extract insights."""
|
|
75
|
+
return f"[Analysis]\nKey insights: ..."
|
|
76
|
+
|
|
77
|
+
@tool
|
|
78
|
+
def write_file(path: str, content: str) -> str:
|
|
79
|
+
"""Write content to a file."""
|
|
80
|
+
return f"Successfully wrote {len(content)} characters to {path}"
|
|
81
|
+
|
|
82
|
+
# Configure models
|
|
83
|
+
powerful_model = BedrockModel(model_id="us.anthropic.claude-3-opus-20240229-v1:0")
|
|
84
|
+
fast_model = BedrockModel(model_id="us.anthropic.claude-3-5-haiku-20241022-v1:0")
|
|
85
|
+
|
|
86
|
+
# Create the swarm
|
|
87
|
+
swarm = DynamicSwarm(
|
|
88
|
+
available_tools={
|
|
89
|
+
"search_web": search_web,
|
|
90
|
+
"analyze_data": analyze_data,
|
|
91
|
+
"write_file": write_file,
|
|
92
|
+
},
|
|
93
|
+
available_models={
|
|
94
|
+
"powerful": powerful_model,
|
|
95
|
+
"fast": fast_model,
|
|
96
|
+
},
|
|
97
|
+
orchestrator_model=powerful_model,
|
|
98
|
+
default_agent_model="fast",
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
# Execute with natural language
|
|
102
|
+
result = swarm.execute("Research the latest AI trends and write a summary report")
|
|
103
|
+
|
|
104
|
+
print(f"Status: {result.status}")
|
|
105
|
+
print(f"Agents spawned: {result.agents_spawned_count}")
|
|
106
|
+
for agent in result.agents_spawned:
|
|
107
|
+
print(f" - {agent.name}: {agent.role}")
|
|
108
|
+
print(f"Tasks created: {result.tasks_created_count}")
|
|
109
|
+
for task in result.tasks_created:
|
|
110
|
+
depends = f" (depends: [{', '.join(task.depends_on)}])" if task.depends_on else ""
|
|
111
|
+
print(f" - {task.name} -> {task.agent}{depends}")
|
|
112
|
+
print(f"Final response: {result.final_response}")
|
|
113
|
+
```
|
|
114
|
+
<details>
|
|
115
|
+
<summary>Example output (see examples/simple.py)</summary>
|
|
116
|
+
|
|
117
|
+
```
|
|
118
|
+
Status: Status.COMPLETED
|
|
119
|
+
Agents spawned: 2
|
|
120
|
+
- researcher: AI trends researcher
|
|
121
|
+
- writer: AI trends summary writer
|
|
122
|
+
Tasks created: 3
|
|
123
|
+
- web_research -> researcher
|
|
124
|
+
- analyze_trends -> researcher (depends: [web_research])
|
|
125
|
+
- write_summary -> writer (depends: [analyze_trends])
|
|
126
|
+
Final response: <thinking>
|
|
127
|
+
The job is complete. The researchers gathered comprehensive information on the latest AI trends through web searches, analyzed that information to identify the most important developments and themes, and the writer put it together into a clear summary report touching on:
|
|
128
|
+
|
|
129
|
+
- Major AI breakthroughs in the last year across language, vision, multimodal and generative models
|
|
130
|
+
- Potential applications of these advancing AI capabilities
|
|
131
|
+
- Rapid growth in enterprise adoption and startup investment
|
|
132
|
+
- Key technical challenges like robustness, interpretability and scalability
|
|
133
|
+
- Important societal and ethical considerations around safety, bias and responsible use
|
|
134
|
+
- Longer-term possibilities around artificial general intelligence
|
|
135
|
+
|
|
136
|
+
The report provides a succinct yet informative overview of the state of the art in AI and the key trends shaping the field. It directly addresses the original request, so no further analysis or synthesis is needed. The final report can be delivered as-is to the human who made the request.
|
|
137
|
+
</thinking>
|
|
138
|
+
|
|
139
|
+
Here is a summary report on the latest trends in artificial intelligence:
|
|
140
|
+
|
|
141
|
+
Artificial intelligence continues to progress rapidly, with significant developments over the past year in areas like natural language processing, computer vision, multimodal learning, and generative AI. Powerful language models can now engage in human-like dialogue and assist with writing. AI systems can perceive and reason jointly about text, images, audio and video. New generative models can create highly realistic images from textual descriptions. And AI has achieved human-level performance on complex strategy games.
|
|
142
|
+
|
|
143
|
+
These advances open up transformative potential applications — enhancing creative workflows, accelerating scientific discovery, enabling more natural human-computer interaction. Enterprises across sectors are increasingly adopting AI technologies, and venture capital investment into AI startups reached record levels in 2022.
|
|
144
|
+
|
|
145
|
+
However, key technical challenges remain in making AI systems more robust, interpretable and scalable. Important societal considerations are also in play around AI ethics, safety, bias and responsible use. Longer-term, some believe AI could progress toward human-level artificial general intelligence, though this remains a future possibility.
|
|
146
|
+
|
|
147
|
+
In summary, AI capabilities are advancing quickly, with potentially profound impacts across domains in the coming years. Ongoing research aims to further enhance performance while addressing crucial challenges. Organizations will need to balance leveraging AI's competitive advantages with deploying it in a trustworthy manner. The field's rapid progress looks set to continue — and to reshape the world in the process.
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
</details>
|
|
151
|
+
|
|
152
|
+
## Status & Roadmap
|
|
153
|
+
|
|
154
|
+
> **Current version: Rollout-only**
|
|
155
|
+
>
|
|
156
|
+
> This release supports **rollout execution** (string-in, string-out) — ideal for inference and deployment.
|
|
157
|
+
>
|
|
158
|
+
> **Coming soon:** RL support via [strands-sglang](https://github.com/strands-agents/strands-sglang) integration.
|
|
159
|
+
|
|
160
|
+
- [x] Rollout execution — string-in, string-out multi-agent workflows
|
|
161
|
+
- [x] Dynamic orchestration — automatic agent creation and task assignment
|
|
162
|
+
- [ ] Streaming trajectory output — consume `stream_async()`
|
|
163
|
+
- [ ] RL support — training and fine-tuning via strands-sglang
|
|
164
|
+
|
|
165
|
+
## Contributing
|
|
166
|
+
|
|
167
|
+
Contributions welcome! Please feel free to submit issues and pull requests.
|
|
168
|
+
|
|
169
|
+
## License
|
|
170
|
+
|
|
171
|
+
Apache-2.0
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
# strands-swarms
|
|
2
|
+
|
|
3
|
+
[](https://github.com/JackXu0/strands-swarms/actions/workflows/ci.yml)
|
|
4
|
+
[](https://pypi.org/project/strands-swarms/)
|
|
5
|
+
[](https://opensource.org/licenses/Apache-2.0)
|
|
6
|
+
|
|
7
|
+
**Turn natural language into multi-agent workflows — automatically.**
|
|
8
|
+
|
|
9
|
+
Give `DynamicSwarm` a query, and it automatically plans the workflow, spawns specialized agents, and executes tasks with dependencies. No manual graph configuration or agent wiring required.
|
|
10
|
+
|
|
11
|
+
```python
|
|
12
|
+
swarm = DynamicSwarm(available_tools={...}, available_models={...})
|
|
13
|
+
result = swarm.execute("Research AI trends and write a summary report")
|
|
14
|
+
# → Spawns researcher + writer agents, handles dependencies, returns final report
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Inspiration
|
|
18
|
+
|
|
19
|
+
This project is inspired by [Kimi K2.5's Agent Swarm](https://www.kimi.com/blog/kimi-k2-5.html) — where a trainable orchestrator dynamically creates and coordinates sub-agents without predefined roles or workflows. The goal is to build an open-source foundation for training orchestrators that can spin up agent swarms on the fly.
|
|
20
|
+
|
|
21
|
+
## How It Works
|
|
22
|
+
|
|
23
|
+

|
|
24
|
+
|
|
25
|
+
## Installation
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
pip install strands-swarms
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Quick Start
|
|
32
|
+
|
|
33
|
+
```python
|
|
34
|
+
from strands import tool
|
|
35
|
+
from strands.models import BedrockModel
|
|
36
|
+
from strands_swarms import DynamicSwarm
|
|
37
|
+
|
|
38
|
+
# Define your tools
|
|
39
|
+
@tool
|
|
40
|
+
def search_web(query: str) -> str:
|
|
41
|
+
"""Search the web for information."""
|
|
42
|
+
return f"[Search Results for '{query}']\n- Result 1: Latest developments..."
|
|
43
|
+
|
|
44
|
+
@tool
|
|
45
|
+
def analyze_data(data: str) -> str:
|
|
46
|
+
"""Analyze data and extract insights."""
|
|
47
|
+
return f"[Analysis]\nKey insights: ..."
|
|
48
|
+
|
|
49
|
+
@tool
|
|
50
|
+
def write_file(path: str, content: str) -> str:
|
|
51
|
+
"""Write content to a file."""
|
|
52
|
+
return f"Successfully wrote {len(content)} characters to {path}"
|
|
53
|
+
|
|
54
|
+
# Configure models
|
|
55
|
+
powerful_model = BedrockModel(model_id="us.anthropic.claude-3-opus-20240229-v1:0")
|
|
56
|
+
fast_model = BedrockModel(model_id="us.anthropic.claude-3-5-haiku-20241022-v1:0")
|
|
57
|
+
|
|
58
|
+
# Create the swarm
|
|
59
|
+
swarm = DynamicSwarm(
|
|
60
|
+
available_tools={
|
|
61
|
+
"search_web": search_web,
|
|
62
|
+
"analyze_data": analyze_data,
|
|
63
|
+
"write_file": write_file,
|
|
64
|
+
},
|
|
65
|
+
available_models={
|
|
66
|
+
"powerful": powerful_model,
|
|
67
|
+
"fast": fast_model,
|
|
68
|
+
},
|
|
69
|
+
orchestrator_model=powerful_model,
|
|
70
|
+
default_agent_model="fast",
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
# Execute with natural language
|
|
74
|
+
result = swarm.execute("Research the latest AI trends and write a summary report")
|
|
75
|
+
|
|
76
|
+
print(f"Status: {result.status}")
|
|
77
|
+
print(f"Agents spawned: {result.agents_spawned_count}")
|
|
78
|
+
for agent in result.agents_spawned:
|
|
79
|
+
print(f" - {agent.name}: {agent.role}")
|
|
80
|
+
print(f"Tasks created: {result.tasks_created_count}")
|
|
81
|
+
for task in result.tasks_created:
|
|
82
|
+
depends = f" (depends: [{', '.join(task.depends_on)}])" if task.depends_on else ""
|
|
83
|
+
print(f" - {task.name} -> {task.agent}{depends}")
|
|
84
|
+
print(f"Final response: {result.final_response}")
|
|
85
|
+
```
|
|
86
|
+
<details>
|
|
87
|
+
<summary>Example output (see examples/simple.py)</summary>
|
|
88
|
+
|
|
89
|
+
```
|
|
90
|
+
Status: Status.COMPLETED
|
|
91
|
+
Agents spawned: 2
|
|
92
|
+
- researcher: AI trends researcher
|
|
93
|
+
- writer: AI trends summary writer
|
|
94
|
+
Tasks created: 3
|
|
95
|
+
- web_research -> researcher
|
|
96
|
+
- analyze_trends -> researcher (depends: [web_research])
|
|
97
|
+
- write_summary -> writer (depends: [analyze_trends])
|
|
98
|
+
Final response: <thinking>
|
|
99
|
+
The job is complete. The researchers gathered comprehensive information on the latest AI trends through web searches, analyzed that information to identify the most important developments and themes, and the writer put it together into a clear summary report touching on:
|
|
100
|
+
|
|
101
|
+
- Major AI breakthroughs in the last year across language, vision, multimodal and generative models
|
|
102
|
+
- Potential applications of these advancing AI capabilities
|
|
103
|
+
- Rapid growth in enterprise adoption and startup investment
|
|
104
|
+
- Key technical challenges like robustness, interpretability and scalability
|
|
105
|
+
- Important societal and ethical considerations around safety, bias and responsible use
|
|
106
|
+
- Longer-term possibilities around artificial general intelligence
|
|
107
|
+
|
|
108
|
+
The report provides a succinct yet informative overview of the state of the art in AI and the key trends shaping the field. It directly addresses the original request, so no further analysis or synthesis is needed. The final report can be delivered as-is to the human who made the request.
|
|
109
|
+
</thinking>
|
|
110
|
+
|
|
111
|
+
Here is a summary report on the latest trends in artificial intelligence:
|
|
112
|
+
|
|
113
|
+
Artificial intelligence continues to progress rapidly, with significant developments over the past year in areas like natural language processing, computer vision, multimodal learning, and generative AI. Powerful language models can now engage in human-like dialogue and assist with writing. AI systems can perceive and reason jointly about text, images, audio and video. New generative models can create highly realistic images from textual descriptions. And AI has achieved human-level performance on complex strategy games.
|
|
114
|
+
|
|
115
|
+
These advances open up transformative potential applications — enhancing creative workflows, accelerating scientific discovery, enabling more natural human-computer interaction. Enterprises across sectors are increasingly adopting AI technologies, and venture capital investment into AI startups reached record levels in 2022.
|
|
116
|
+
|
|
117
|
+
However, key technical challenges remain in making AI systems more robust, interpretable and scalable. Important societal considerations are also in play around AI ethics, safety, bias and responsible use. Longer-term, some believe AI could progress toward human-level artificial general intelligence, though this remains a future possibility.
|
|
118
|
+
|
|
119
|
+
In summary, AI capabilities are advancing quickly, with potentially profound impacts across domains in the coming years. Ongoing research aims to further enhance performance while addressing crucial challenges. Organizations will need to balance leveraging AI's competitive advantages with deploying it in a trustworthy manner. The field's rapid progress looks set to continue — and to reshape the world in the process.
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
</details>
|
|
123
|
+
|
|
124
|
+
## Status & Roadmap
|
|
125
|
+
|
|
126
|
+
> **Current version: Rollout-only**
|
|
127
|
+
>
|
|
128
|
+
> This release supports **rollout execution** (string-in, string-out) — ideal for inference and deployment.
|
|
129
|
+
>
|
|
130
|
+
> **Coming soon:** RL support via [strands-sglang](https://github.com/strands-agents/strands-sglang) integration.
|
|
131
|
+
|
|
132
|
+
- [x] Rollout execution — string-in, string-out multi-agent workflows
|
|
133
|
+
- [x] Dynamic orchestration — automatic agent creation and task assignment
|
|
134
|
+
- [ ] Streaming trajectory output — consume `stream_async()`
|
|
135
|
+
- [ ] RL support — training and fine-tuning via strands-sglang
|
|
136
|
+
|
|
137
|
+
## Contributing
|
|
138
|
+
|
|
139
|
+
Contributions welcome! Please feel free to submit issues and pull requests.
|
|
140
|
+
|
|
141
|
+
## License
|
|
142
|
+
|
|
143
|
+
Apache-2.0
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
from strands import tool
|
|
2
|
+
from strands.models import BedrockModel
|
|
3
|
+
from strands_swarms import DynamicSwarm
|
|
4
|
+
|
|
5
|
+
# Define your tools
|
|
6
|
+
@tool
|
|
7
|
+
def search_web(query: str) -> str:
|
|
8
|
+
"""Search the web for information."""
|
|
9
|
+
return f"[Search Results for '{query}']\n- Result 1: Latest developments..."
|
|
10
|
+
|
|
11
|
+
@tool
|
|
12
|
+
def analyze_data(data: str) -> str:
|
|
13
|
+
"""Analyze data and extract insights."""
|
|
14
|
+
return f"[Analysis]\nKey insights: ..."
|
|
15
|
+
|
|
16
|
+
@tool
|
|
17
|
+
def write_file(path: str, content: str) -> str:
|
|
18
|
+
"""Write content to a file."""
|
|
19
|
+
return f"Successfully wrote {len(content)} characters to {path}"
|
|
20
|
+
|
|
21
|
+
# Configure models
|
|
22
|
+
powerful_model = BedrockModel(model_id="us.anthropic.claude-3-opus-20240229-v1:0")
|
|
23
|
+
fast_model = BedrockModel(model_id="us.anthropic.claude-3-5-haiku-20241022-v1:0")
|
|
24
|
+
|
|
25
|
+
# Create the swarm
|
|
26
|
+
swarm = DynamicSwarm(
|
|
27
|
+
available_tools={
|
|
28
|
+
"search_web": search_web,
|
|
29
|
+
"analyze_data": analyze_data,
|
|
30
|
+
"write_file": write_file,
|
|
31
|
+
},
|
|
32
|
+
available_models={
|
|
33
|
+
"powerful": powerful_model,
|
|
34
|
+
"fast": fast_model,
|
|
35
|
+
},
|
|
36
|
+
orchestrator_model=powerful_model,
|
|
37
|
+
default_agent_model="fast",
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
# Execute with natural language
|
|
41
|
+
result = swarm.execute("Research the latest AI trends and write a summary report")
|
|
42
|
+
|
|
43
|
+
print(f"Status: {result.status}")
|
|
44
|
+
print(f"Agents spawned: {result.agents_spawned_count}")
|
|
45
|
+
for agent in result.agents_spawned:
|
|
46
|
+
print(f" - {agent.name}: {agent.role}")
|
|
47
|
+
print(f"Tasks created: {result.tasks_created_count}")
|
|
48
|
+
for task in result.tasks_created:
|
|
49
|
+
depends = f" (depends: [{', '.join(task.depends_on)}])" if task.depends_on else ""
|
|
50
|
+
print(f" - {task.name} -> {task.agent}{depends}")
|
|
51
|
+
print(f"Final response: {result.final_response}")
|
|
@@ -4,8 +4,11 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "strands-swarms"
|
|
7
|
-
version = "0.1.
|
|
7
|
+
version = "0.1.2"
|
|
8
8
|
description = "Task-based workflow orchestration for Strands Agents"
|
|
9
|
+
authors = [
|
|
10
|
+
{name = "Zhuocheng Xu", email = "zhuocheng.xu@icloud.com"}
|
|
11
|
+
]
|
|
9
12
|
readme = "README.md"
|
|
10
13
|
requires-python = ">=3.10"
|
|
11
14
|
license = {text = "Apache-2.0"}
|
|
@@ -34,8 +37,8 @@ dev = [
|
|
|
34
37
|
]
|
|
35
38
|
|
|
36
39
|
[project.urls]
|
|
37
|
-
Homepage = "https://github.com/
|
|
38
|
-
Issues = "https://github.com/
|
|
40
|
+
Homepage = "https://github.com/JackXu0/strands-swarms"
|
|
41
|
+
Issues = "https://github.com/JackXu0/strands-swarms/issues"
|
|
39
42
|
|
|
40
43
|
[tool.hatch.build.targets.wheel]
|
|
41
44
|
packages = ["src/strands_swarms"]
|
|
@@ -26,63 +26,50 @@ Example:
|
|
|
26
26
|
'''Search the web.'''
|
|
27
27
|
return f"Results for: {query}"
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
verbose=True,
|
|
32
|
-
)
|
|
29
|
+
# Basic usage
|
|
30
|
+
swarm = DynamicSwarm(available_tools={"search_web": search_web})
|
|
33
31
|
result = swarm.execute("Research AI trends and summarize")
|
|
34
|
-
"""
|
|
35
32
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
TaskCompletedEvent,
|
|
49
|
-
TaskFailedEvent,
|
|
50
|
-
ExecutionCompletedEvent,
|
|
51
|
-
SwarmCompletedEvent,
|
|
52
|
-
SwarmFailedEvent,
|
|
53
|
-
# Hook provider
|
|
54
|
-
PrintingHookProvider,
|
|
55
|
-
)
|
|
33
|
+
# Streaming trajectory
|
|
34
|
+
import asyncio
|
|
35
|
+
|
|
36
|
+
async def run():
|
|
37
|
+
async for event in swarm.stream_async(
|
|
38
|
+
"Research AI trends and summarize",
|
|
39
|
+
include_subagent_events=False,
|
|
40
|
+
):
|
|
41
|
+
print(event)
|
|
42
|
+
|
|
43
|
+
asyncio.run(run())
|
|
44
|
+
"""
|
|
56
45
|
|
|
57
46
|
# Re-export strands types for convenience
|
|
58
|
-
from strands.hooks import HookProvider, HookRegistry
|
|
59
47
|
from strands.multiagent.base import Status
|
|
60
48
|
|
|
61
|
-
|
|
49
|
+
from .definition import (
|
|
50
|
+
AgentDefinition,
|
|
51
|
+
DynamicSwarmCapabilities,
|
|
52
|
+
SessionConfig,
|
|
53
|
+
SwarmDefinition,
|
|
54
|
+
TaskDefinition,
|
|
55
|
+
)
|
|
56
|
+
from .dynamic_swarm import DynamicSwarm, DynamicSwarmResult, build_swarm
|
|
57
|
+
from .orchestrator import create_orchestrator_agent
|
|
58
|
+
|
|
59
|
+
__version__ = "0.1.1"
|
|
62
60
|
|
|
63
61
|
__all__ = [
|
|
64
62
|
# Main API
|
|
65
63
|
"DynamicSwarm",
|
|
66
64
|
"DynamicSwarmResult",
|
|
67
|
-
|
|
65
|
+
"build_swarm",
|
|
66
|
+
# Definition types
|
|
67
|
+
"DynamicSwarmCapabilities",
|
|
68
|
+
"SwarmDefinition",
|
|
69
|
+
"AgentDefinition",
|
|
70
|
+
"TaskDefinition",
|
|
71
|
+
"SessionConfig",
|
|
72
|
+
# Orchestrator
|
|
68
73
|
"create_orchestrator_agent",
|
|
69
|
-
# Status enum
|
|
70
74
|
"Status",
|
|
71
|
-
# Events (for custom hooks)
|
|
72
|
-
"SwarmStartedEvent",
|
|
73
|
-
"PlanningStartedEvent",
|
|
74
|
-
"AgentSpawnedEvent",
|
|
75
|
-
"TaskCreatedEvent",
|
|
76
|
-
"PlanningCompletedEvent",
|
|
77
|
-
"ExecutionStartedEvent",
|
|
78
|
-
"TaskStartedEvent",
|
|
79
|
-
"TaskCompletedEvent",
|
|
80
|
-
"TaskFailedEvent",
|
|
81
|
-
"ExecutionCompletedEvent",
|
|
82
|
-
"SwarmCompletedEvent",
|
|
83
|
-
"SwarmFailedEvent",
|
|
84
|
-
# Hook system
|
|
85
|
-
"PrintingHookProvider",
|
|
86
|
-
"HookProvider",
|
|
87
|
-
"HookRegistry",
|
|
88
75
|
]
|