deepcrew-ai 0.1.0__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.
- deepcrew_ai-0.1.0/.claude/launch.json +11 -0
- deepcrew_ai-0.1.0/.gitignore +220 -0
- deepcrew_ai-0.1.0/CHANGELOG.md +62 -0
- deepcrew_ai-0.1.0/LICENSE +21 -0
- deepcrew_ai-0.1.0/PKG-INFO +314 -0
- deepcrew_ai-0.1.0/README.md +283 -0
- deepcrew_ai-0.1.0/docs/.nojekyll +0 -0
- deepcrew_ai-0.1.0/docs/assets/css/style.css +1151 -0
- deepcrew_ai-0.1.0/docs/assets/js/main.js +225 -0
- deepcrew_ai-0.1.0/docs/assets/logo.svg +26 -0
- deepcrew_ai-0.1.0/docs/index.html +1223 -0
- deepcrew_ai-0.1.0/examples/automated_example.py +83 -0
- deepcrew_ai-0.1.0/examples/mcp_example.py +88 -0
- deepcrew_ai-0.1.0/examples/simple_agent.py +46 -0
- deepcrew_ai-0.1.0/examples/workflow_example.py +97 -0
- deepcrew_ai-0.1.0/pyproject.toml +50 -0
- deepcrew_ai-0.1.0/src/deepcrew/__init__.py +88 -0
- deepcrew_ai-0.1.0/src/deepcrew/agent.py +70 -0
- deepcrew_ai-0.1.0/src/deepcrew/exceptions.py +22 -0
- deepcrew_ai-0.1.0/src/deepcrew/mcp/__init__.py +7 -0
- deepcrew_ai-0.1.0/src/deepcrew/mcp/base.py +55 -0
- deepcrew_ai-0.1.0/src/deepcrew/mcp/http.py +168 -0
- deepcrew_ai-0.1.0/src/deepcrew/mcp/manager.py +87 -0
- deepcrew_ai-0.1.0/src/deepcrew/mcp/sse.py +155 -0
- deepcrew_ai-0.1.0/src/deepcrew/mcp/stdio.py +138 -0
- deepcrew_ai-0.1.0/src/deepcrew/orchestrator.py +277 -0
- deepcrew_ai-0.1.0/src/deepcrew/runner.py +236 -0
- deepcrew_ai-0.1.0/src/deepcrew/stream.py +33 -0
- deepcrew_ai-0.1.0/src/deepcrew/tools.py +144 -0
- deepcrew_ai-0.1.0/src/deepcrew/types.py +92 -0
- deepcrew_ai-0.1.0/src/deepcrew/workflow.py +271 -0
- deepcrew_ai-0.1.0/tests/conftest.py +6 -0
- deepcrew_ai-0.1.0/tests/test_mcp.py +124 -0
- deepcrew_ai-0.1.0/tests/test_orchestrator.py +111 -0
- deepcrew_ai-0.1.0/tests/test_runner.py +161 -0
- deepcrew_ai-0.1.0/tests/test_tools.py +94 -0
- deepcrew_ai-0.1.0/tests/test_workflow.py +106 -0
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[codz]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
share/python-wheels/
|
|
24
|
+
*.egg-info/
|
|
25
|
+
.installed.cfg
|
|
26
|
+
*.egg
|
|
27
|
+
MANIFEST
|
|
28
|
+
|
|
29
|
+
# PyInstaller
|
|
30
|
+
# Usually these files are written by a python script from a template
|
|
31
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
32
|
+
*.manifest
|
|
33
|
+
*.spec
|
|
34
|
+
|
|
35
|
+
# Installer logs
|
|
36
|
+
pip-log.txt
|
|
37
|
+
pip-delete-this-directory.txt
|
|
38
|
+
|
|
39
|
+
# Unit test / coverage reports
|
|
40
|
+
htmlcov/
|
|
41
|
+
.tox/
|
|
42
|
+
.nox/
|
|
43
|
+
.coverage
|
|
44
|
+
.coverage.*
|
|
45
|
+
.cache
|
|
46
|
+
nosetests.xml
|
|
47
|
+
coverage.xml
|
|
48
|
+
*.cover
|
|
49
|
+
*.py.cover
|
|
50
|
+
*.lcov
|
|
51
|
+
.hypothesis/
|
|
52
|
+
.pytest_cache/
|
|
53
|
+
cover/
|
|
54
|
+
|
|
55
|
+
# Translations
|
|
56
|
+
*.mo
|
|
57
|
+
*.pot
|
|
58
|
+
|
|
59
|
+
# Django stuff:
|
|
60
|
+
*.log
|
|
61
|
+
local_settings.py
|
|
62
|
+
db.sqlite3
|
|
63
|
+
db.sqlite3-journal
|
|
64
|
+
|
|
65
|
+
# Flask stuff:
|
|
66
|
+
instance/
|
|
67
|
+
.webassets-cache
|
|
68
|
+
|
|
69
|
+
# Scrapy stuff:
|
|
70
|
+
.scrapy
|
|
71
|
+
|
|
72
|
+
# Sphinx documentation
|
|
73
|
+
docs/_build/
|
|
74
|
+
|
|
75
|
+
# PyBuilder
|
|
76
|
+
.pybuilder/
|
|
77
|
+
target/
|
|
78
|
+
|
|
79
|
+
# Jupyter Notebook
|
|
80
|
+
.ipynb_checkpoints
|
|
81
|
+
|
|
82
|
+
# IPython
|
|
83
|
+
profile_default/
|
|
84
|
+
ipython_config.py
|
|
85
|
+
|
|
86
|
+
# pyenv
|
|
87
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
88
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
89
|
+
# .python-version
|
|
90
|
+
|
|
91
|
+
# pipenv
|
|
92
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
93
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
94
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
95
|
+
# install all needed dependencies.
|
|
96
|
+
# Pipfile.lock
|
|
97
|
+
|
|
98
|
+
# UV
|
|
99
|
+
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
|
|
100
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
101
|
+
# commonly ignored for libraries.
|
|
102
|
+
# uv.lock
|
|
103
|
+
|
|
104
|
+
# poetry
|
|
105
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
106
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
107
|
+
# commonly ignored for libraries.
|
|
108
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
109
|
+
# poetry.lock
|
|
110
|
+
# poetry.toml
|
|
111
|
+
|
|
112
|
+
# pdm
|
|
113
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
114
|
+
# pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
|
|
115
|
+
# https://pdm-project.org/en/latest/usage/project/#working-with-version-control
|
|
116
|
+
# pdm.lock
|
|
117
|
+
# pdm.toml
|
|
118
|
+
.pdm-python
|
|
119
|
+
.pdm-build/
|
|
120
|
+
|
|
121
|
+
# pixi
|
|
122
|
+
# Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
|
|
123
|
+
# pixi.lock
|
|
124
|
+
# Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
|
|
125
|
+
# in the .venv directory. It is recommended not to include this directory in version control.
|
|
126
|
+
.pixi/*
|
|
127
|
+
!.pixi/config.toml
|
|
128
|
+
|
|
129
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
130
|
+
__pypackages__/
|
|
131
|
+
|
|
132
|
+
# Celery stuff
|
|
133
|
+
celerybeat-schedule*
|
|
134
|
+
celerybeat.pid
|
|
135
|
+
|
|
136
|
+
# Redis
|
|
137
|
+
*.rdb
|
|
138
|
+
*.aof
|
|
139
|
+
*.pid
|
|
140
|
+
|
|
141
|
+
# RabbitMQ
|
|
142
|
+
mnesia/
|
|
143
|
+
rabbitmq/
|
|
144
|
+
rabbitmq-data/
|
|
145
|
+
|
|
146
|
+
# ActiveMQ
|
|
147
|
+
activemq-data/
|
|
148
|
+
|
|
149
|
+
# SageMath parsed files
|
|
150
|
+
*.sage.py
|
|
151
|
+
|
|
152
|
+
# Environments
|
|
153
|
+
.env
|
|
154
|
+
.envrc
|
|
155
|
+
.venv
|
|
156
|
+
env/
|
|
157
|
+
venv/
|
|
158
|
+
ENV/
|
|
159
|
+
env.bak/
|
|
160
|
+
venv.bak/
|
|
161
|
+
|
|
162
|
+
# Spyder project settings
|
|
163
|
+
.spyderproject
|
|
164
|
+
.spyproject
|
|
165
|
+
|
|
166
|
+
# Rope project settings
|
|
167
|
+
.ropeproject
|
|
168
|
+
|
|
169
|
+
# mkdocs documentation
|
|
170
|
+
/site
|
|
171
|
+
|
|
172
|
+
# mypy
|
|
173
|
+
.mypy_cache/
|
|
174
|
+
.dmypy.json
|
|
175
|
+
dmypy.json
|
|
176
|
+
|
|
177
|
+
# Pyre type checker
|
|
178
|
+
.pyre/
|
|
179
|
+
|
|
180
|
+
# pytype static type analyzer
|
|
181
|
+
.pytype/
|
|
182
|
+
|
|
183
|
+
# Cython debug symbols
|
|
184
|
+
cython_debug/
|
|
185
|
+
|
|
186
|
+
# PyCharm
|
|
187
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
188
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
189
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
190
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
191
|
+
# .idea/
|
|
192
|
+
|
|
193
|
+
# Abstra
|
|
194
|
+
# Abstra is an AI-powered process automation framework.
|
|
195
|
+
# Ignore directories containing user credentials, local state, and settings.
|
|
196
|
+
# Learn more at https://abstra.io/docs
|
|
197
|
+
.abstra/
|
|
198
|
+
|
|
199
|
+
# Visual Studio Code
|
|
200
|
+
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
|
|
201
|
+
# that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
|
|
202
|
+
# and can be added to the global gitignore or merged into this file. However, if you prefer,
|
|
203
|
+
# you could uncomment the following to ignore the entire vscode folder
|
|
204
|
+
# .vscode/
|
|
205
|
+
# Temporary file for partial code execution
|
|
206
|
+
tempCodeRunnerFile.py
|
|
207
|
+
|
|
208
|
+
# Ruff stuff:
|
|
209
|
+
.ruff_cache/
|
|
210
|
+
|
|
211
|
+
# PyPI configuration file
|
|
212
|
+
.pypirc
|
|
213
|
+
|
|
214
|
+
# Marimo
|
|
215
|
+
marimo/_static/
|
|
216
|
+
marimo/_lsp/
|
|
217
|
+
__marimo__/
|
|
218
|
+
|
|
219
|
+
# Streamlit
|
|
220
|
+
.streamlit/secrets.toml
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to `deepcrew-ai` are documented here.
|
|
4
|
+
|
|
5
|
+
Format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
|
|
6
|
+
Versioning follows [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## [0.1.0] — 2026-06-21
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
#### Core
|
|
15
|
+
- `Agent` dataclass — define name, model (litellm string), system prompt, MCP clients, Python function tools, temperature, max tokens, and arbitrary `extra_params` forwarded to litellm
|
|
16
|
+
- `run_agent()` — async agentic loop: LLM → parallel tool execution → LLM, repeating until no tool calls or `max_turns` exceeded; streams `StreamEvent` objects to an optional `asyncio.Queue`
|
|
17
|
+
- `MaxTurnsError` raised when an agent exhausts its turn budget
|
|
18
|
+
|
|
19
|
+
#### Orchestrator (automated mode)
|
|
20
|
+
- `Orchestrator` — three-stage pipeline: router LLM decides single-agent vs. parallel fan-out, agents run via `asyncio.gather`, synthesizer LLM merges results
|
|
21
|
+
- `Orchestrator.run()` — returns `OrchestratorResult` with final text, per-agent results, and token counts
|
|
22
|
+
- `Orchestrator.stream()` — async generator yielding `StreamEvent` objects in real time
|
|
23
|
+
- Built-in router and synthesizer system prompts; both overridable
|
|
24
|
+
- `max_parallel_agents` cap to bound fan-out
|
|
25
|
+
|
|
26
|
+
#### Workflow Builder (explicit DAG mode)
|
|
27
|
+
- `WorkflowBuilder` — fluent API to declare agent nodes and dependency edges
|
|
28
|
+
- `.add_agent(name, agent, task)` — add a node with a string template (`{input}`, `{node_name}`) or callable task
|
|
29
|
+
- `.then(predecessor, successor)` — declare ordering constraint
|
|
30
|
+
- `.run()` / `.stream()` — execute the DAG; independent nodes at each topological level run in parallel via `asyncio.gather`
|
|
31
|
+
- `WorkflowResult` with per-node `AgentResult` outputs and aggregate token counts
|
|
32
|
+
- `WorkflowError` on cycle detection or unknown node references
|
|
33
|
+
|
|
34
|
+
#### Python Function Tools
|
|
35
|
+
- `@tool` decorator — marks any callable as an agent tool; optional `name` and `description` overrides
|
|
36
|
+
- `fn_to_tool_def()` — converts any Python function to a `ToolDef` with JSON Schema generated from type hints (`str`, `int`, `float`, `bool`, `list[X]`, `dict[str, X]`, `Optional[X]`, `Union`, `Literal`)
|
|
37
|
+
- Google-style docstring parameter descriptions extracted automatically
|
|
38
|
+
|
|
39
|
+
#### MCP Integration
|
|
40
|
+
- `MCPClient` abstract base class with `connect()`, `list_tools()`, `call_tool()`, `close()`, and async context manager support
|
|
41
|
+
- `StdioMCP` — spawns a subprocess and communicates via JSON-RPC over stdin/stdout; supports MCP `2024-11-05` initialize handshake
|
|
42
|
+
- `HTTPMCP` — modern streamable-HTTP MCP transport with `Mcp-Session-Id` session management, automatic session re-initialization on `400/401`, and exponential-backoff retries
|
|
43
|
+
- `SSEMCP` — legacy SSE transport; connects to `/sse`, receives the `endpoint` event, posts JSON-RPC to the resolved URL
|
|
44
|
+
- `MCPManager` — aggregates multiple MCP clients; discovers tools in parallel and maintains a routing table for `call_tool()` dispatch; implements `MCPClient` interface so it can be passed directly to `Agent.mcps`
|
|
45
|
+
|
|
46
|
+
#### Streaming
|
|
47
|
+
- `StreamEvent` dataclass with `event` (`EventType` enum), `agent_id`, and `data` dict
|
|
48
|
+
- `StreamEvent.to_sse()` — produces a ready-to-stream Server-Sent Event string
|
|
49
|
+
- `queue_to_stream()` — drains an `asyncio.Queue[StreamEvent | None]` as an async generator
|
|
50
|
+
- `EventType` values: `agent_start`, `text_delta`, `thinking_delta`, `tool_call`, `tool_result`, `agent_done`, `step_start`, `step_done`, `error`, `done`
|
|
51
|
+
|
|
52
|
+
#### Types & Exceptions
|
|
53
|
+
- `AgentResult`, `WorkflowResult`, `OrchestratorResult`, `ToolDef`
|
|
54
|
+
- `DeepCrewError`, `MCPError`, `ToolError`, `MaxTurnsError`, `RouterError`, `WorkflowError`
|
|
55
|
+
|
|
56
|
+
#### Package
|
|
57
|
+
- `pyproject.toml` with hatchling build backend; Python ≥ 3.11 required
|
|
58
|
+
- Dependencies: `litellm>=1.63.0`, `httpx>=0.27.0`, `httpx-sse>=0.4.0`, `pydantic>=2.0.0`, `anyio>=4.4.0`, `typing-extensions>=4.9.0`
|
|
59
|
+
- 37 unit tests (pytest-asyncio); all passing on Python 3.13
|
|
60
|
+
- 4 runnable examples: `simple_agent.py`, `workflow_example.py`, `automated_example.py`, `mcp_example.py`
|
|
61
|
+
|
|
62
|
+
[0.1.0]: https://github.com/deepcrew-ai/deepcrew-ai/releases/tag/v0.1.0
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 DeepCrew AI
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: deepcrew-ai
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Multi-agent spawning library with litellm, MCP tools, and parallel workflows
|
|
5
|
+
Project-URL: Homepage, https://github.com/deepcrew-ai/deepcrew-ai
|
|
6
|
+
Project-URL: Repository, https://github.com/deepcrew-ai/deepcrew-ai
|
|
7
|
+
Project-URL: Issues, https://github.com/deepcrew-ai/deepcrew-ai/issues
|
|
8
|
+
License: MIT
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Keywords: agents,ai,litellm,llm,mcp,multi-agent,workflow
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Framework :: AsyncIO
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
19
|
+
Requires-Python: >=3.11
|
|
20
|
+
Requires-Dist: anyio>=4.4.0
|
|
21
|
+
Requires-Dist: httpx-sse>=0.4.0
|
|
22
|
+
Requires-Dist: httpx>=0.27.0
|
|
23
|
+
Requires-Dist: litellm>=1.63.0
|
|
24
|
+
Requires-Dist: pydantic>=2.0.0
|
|
25
|
+
Requires-Dist: typing-extensions>=4.9.0
|
|
26
|
+
Provides-Extra: dev
|
|
27
|
+
Requires-Dist: pytest-asyncio>=0.23; extra == 'dev'
|
|
28
|
+
Requires-Dist: pytest>=8.0; extra == 'dev'
|
|
29
|
+
Requires-Dist: respx>=0.21; extra == 'dev'
|
|
30
|
+
Description-Content-Type: text/markdown
|
|
31
|
+
|
|
32
|
+
# deepcrew-ai
|
|
33
|
+
|
|
34
|
+
Multi-agent spawning library for Python. Build parallel AI workflows using any LLM provider, with MCP tool integration and SSE streaming — all with minimal boilerplate.
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
pip install deepcrew-ai
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
## Features
|
|
43
|
+
|
|
44
|
+
- **100+ LLM providers** via [LiteLLM](https://github.com/BerriAI/litellm) — OpenAI, Anthropic, Gemini, Bedrock, Azure, and more
|
|
45
|
+
- **Two orchestration modes** — explicit DAG workflows or automated AI-driven routing
|
|
46
|
+
- **Parallel execution** — independent agents always run concurrently via `asyncio.gather`
|
|
47
|
+
- **MCP tool integration** — stdio (subprocess), SSE (legacy), and streamable-HTTP transports
|
|
48
|
+
- **Python function tools** — decorate any function with `@tool`, schema auto-generated from type hints
|
|
49
|
+
- **SSE streaming** — stream events as they happen, compatible with FastAPI `StreamingResponse`
|
|
50
|
+
- **PyPI-ready** — clean package structure, no extra config needed
|
|
51
|
+
|
|
52
|
+
---
|
|
53
|
+
|
|
54
|
+
## Quick Start
|
|
55
|
+
|
|
56
|
+
```python
|
|
57
|
+
import asyncio
|
|
58
|
+
from deepcrew import Agent, run_agent, tool
|
|
59
|
+
|
|
60
|
+
@tool
|
|
61
|
+
def get_weather(city: str) -> dict:
|
|
62
|
+
"Get current weather."
|
|
63
|
+
return {"city": city, "temp": 22, "condition": "sunny"}
|
|
64
|
+
|
|
65
|
+
async def main():
|
|
66
|
+
agent = Agent(
|
|
67
|
+
name="assistant",
|
|
68
|
+
model="openai/gpt-4o",
|
|
69
|
+
system_prompt="You are a helpful assistant.",
|
|
70
|
+
tools=[get_weather],
|
|
71
|
+
)
|
|
72
|
+
result = await run_agent(agent, [{"role": "user", "content": "Weather in Paris?"}])
|
|
73
|
+
print(result.text)
|
|
74
|
+
|
|
75
|
+
asyncio.run(main())
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
---
|
|
79
|
+
|
|
80
|
+
## Orchestration Modes
|
|
81
|
+
|
|
82
|
+
### 1. Workflow Builder (explicit DAG)
|
|
83
|
+
|
|
84
|
+
Define agents and their dependencies. Independent nodes run in parallel automatically.
|
|
85
|
+
|
|
86
|
+
```python
|
|
87
|
+
from deepcrew import Agent, WorkflowBuilder
|
|
88
|
+
|
|
89
|
+
researcher = Agent("researcher", model="openai/gpt-4o-mini",
|
|
90
|
+
system_prompt="Research the topic thoroughly.")
|
|
91
|
+
critic = Agent("critic", model="openai/gpt-4o-mini",
|
|
92
|
+
system_prompt="Find gaps and weaknesses in the research.")
|
|
93
|
+
writer = Agent("writer", model="openai/gpt-4o",
|
|
94
|
+
system_prompt="Write a polished report.")
|
|
95
|
+
|
|
96
|
+
workflow = (
|
|
97
|
+
WorkflowBuilder()
|
|
98
|
+
.add_agent("research", researcher, task="{input}")
|
|
99
|
+
.add_agent("critique", critic, task="Critique this research:\n{research}")
|
|
100
|
+
.add_agent("report", writer, task="Write a report using:\n{research}\n\nCritique:\n{critique}")
|
|
101
|
+
.then("research", "critique") # critique waits for research
|
|
102
|
+
.then("research", "report") # report waits for research
|
|
103
|
+
.then("critique", "report") # report waits for critique
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
# research runs first, then critique + expand in PARALLEL, then report
|
|
107
|
+
result = await workflow.run("The future of renewable energy")
|
|
108
|
+
print(result.final_output.text)
|
|
109
|
+
print(f"Total tokens: {result.total_tokens}")
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### 2. Automated Orchestrator (AI-driven routing)
|
|
113
|
+
|
|
114
|
+
The router LLM decides at runtime: use one agent, or fan out to multiple in parallel.
|
|
115
|
+
|
|
116
|
+
```python
|
|
117
|
+
from deepcrew import Agent, Orchestrator
|
|
118
|
+
|
|
119
|
+
agents = [
|
|
120
|
+
Agent("researcher", model="openai/gpt-4o-mini", system_prompt="Research specialist."),
|
|
121
|
+
Agent("analyst", model="openai/gpt-4o-mini", system_prompt="Data analyst."),
|
|
122
|
+
Agent("writer", model="openai/gpt-4o-mini", system_prompt="Content writer."),
|
|
123
|
+
]
|
|
124
|
+
|
|
125
|
+
orch = Orchestrator(
|
|
126
|
+
agents=agents,
|
|
127
|
+
router_model="openai/gpt-4o-mini",
|
|
128
|
+
synthesizer_model="openai/gpt-4o",
|
|
129
|
+
)
|
|
130
|
+
|
|
131
|
+
# Non-streaming
|
|
132
|
+
result = await orch.run("Summarize the state of quantum computing")
|
|
133
|
+
print(result.final_text)
|
|
134
|
+
|
|
135
|
+
# Streaming (yields StreamEvent objects)
|
|
136
|
+
async for event in orch.stream("Summarize the state of quantum computing"):
|
|
137
|
+
print(event.to_sse(), end="") # ready for FastAPI StreamingResponse
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
---
|
|
141
|
+
|
|
142
|
+
## MCP Tools
|
|
143
|
+
|
|
144
|
+
### Stdio MCP (subprocess)
|
|
145
|
+
|
|
146
|
+
```python
|
|
147
|
+
from deepcrew import Agent, run_agent
|
|
148
|
+
from deepcrew.mcp import StdioMCP
|
|
149
|
+
|
|
150
|
+
async with StdioMCP("npx", ["-y", "@modelcontextprotocol/server-filesystem", "."]) as mcp:
|
|
151
|
+
agent = Agent("file_agent", model="openai/gpt-4o", mcps=[mcp])
|
|
152
|
+
result = await run_agent(agent, [{"role": "user", "content": "List files here"}])
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### HTTP MCP (streamable-HTTP, modern)
|
|
156
|
+
|
|
157
|
+
```python
|
|
158
|
+
from deepcrew.mcp import HTTPMCP
|
|
159
|
+
|
|
160
|
+
async with HTTPMCP("https://my-mcp.example.com/mcp",
|
|
161
|
+
headers={"Authorization": "Bearer sk-..."}) as mcp:
|
|
162
|
+
agent = Agent("agent", model="openai/gpt-4o", mcps=[mcp])
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
### SSE MCP (legacy)
|
|
166
|
+
|
|
167
|
+
```python
|
|
168
|
+
from deepcrew.mcp import SSEMCP
|
|
169
|
+
|
|
170
|
+
async with SSEMCP("http://localhost:3000") as mcp:
|
|
171
|
+
agent = Agent("agent", model="openai/gpt-4o", mcps=[mcp])
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
### MCPManager (multiple servers)
|
|
175
|
+
|
|
176
|
+
```python
|
|
177
|
+
from deepcrew.mcp import MCPManager, StdioMCP, HTTPMCP
|
|
178
|
+
|
|
179
|
+
async with MCPManager([
|
|
180
|
+
StdioMCP("npx", ["-y", "@modelcontextprotocol/server-filesystem", "."]),
|
|
181
|
+
HTTPMCP("https://search-mcp.example.com/mcp"),
|
|
182
|
+
]) as manager:
|
|
183
|
+
tools = await manager.discover_tools()
|
|
184
|
+
agent = Agent("agent", model="openai/gpt-4o", mcps=[manager])
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
---
|
|
188
|
+
|
|
189
|
+
## Python Function Tools
|
|
190
|
+
|
|
191
|
+
```python
|
|
192
|
+
from deepcrew import tool, fn_to_tool_def
|
|
193
|
+
|
|
194
|
+
@tool
|
|
195
|
+
def calculate(expression: str) -> float:
|
|
196
|
+
"""Evaluate a mathematical expression.
|
|
197
|
+
|
|
198
|
+
Args:
|
|
199
|
+
expression (str): A Python math expression like '2 ** 10'.
|
|
200
|
+
"""
|
|
201
|
+
return eval(expression) # noqa: S307 — replace with safe parser in production
|
|
202
|
+
|
|
203
|
+
# Or without decorator (schema still auto-generated):
|
|
204
|
+
def search_db(query: str, limit: int = 10) -> list:
|
|
205
|
+
...
|
|
206
|
+
|
|
207
|
+
agent = Agent("agent", model="openai/gpt-4o", tools=[calculate, search_db])
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
---
|
|
211
|
+
|
|
212
|
+
## Streaming with FastAPI
|
|
213
|
+
|
|
214
|
+
```python
|
|
215
|
+
from fastapi import FastAPI
|
|
216
|
+
from fastapi.responses import StreamingResponse
|
|
217
|
+
from deepcrew import Orchestrator, Agent
|
|
218
|
+
|
|
219
|
+
app = FastAPI()
|
|
220
|
+
orch = Orchestrator([Agent("assistant", model="openai/gpt-4o")])
|
|
221
|
+
|
|
222
|
+
@app.post("/chat")
|
|
223
|
+
async def chat(query: str):
|
|
224
|
+
async def event_stream():
|
|
225
|
+
async for event in orch.stream(query):
|
|
226
|
+
yield event.to_sse()
|
|
227
|
+
return StreamingResponse(event_stream(), media_type="text/event-stream")
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
---
|
|
231
|
+
|
|
232
|
+
## Stream Events
|
|
233
|
+
|
|
234
|
+
All events have `event`, `agent_id`, and a `data` dict:
|
|
235
|
+
|
|
236
|
+
| Event | Data keys | Meaning |
|
|
237
|
+
|---|---|---|
|
|
238
|
+
| `agent_start` | `model` | Agent loop begins |
|
|
239
|
+
| `text_delta` | `chunk` | Incremental text from LLM |
|
|
240
|
+
| `thinking_delta` | `chunk`, `tokens` | Thinking/reasoning text |
|
|
241
|
+
| `tool_call` | `tool`, `args` | Tool about to be called |
|
|
242
|
+
| `tool_result` | `tool`, `result` | Tool call completed |
|
|
243
|
+
| `agent_done` | `input_tokens`, `output_tokens` | Agent finished |
|
|
244
|
+
| `step_start` | `node` | Workflow node beginning |
|
|
245
|
+
| `step_done` | `node` | Workflow node completed |
|
|
246
|
+
| `error` | `message` | An error occurred |
|
|
247
|
+
| `done` | `final_text` | Entire run complete |
|
|
248
|
+
|
|
249
|
+
---
|
|
250
|
+
|
|
251
|
+
## Agent Configuration
|
|
252
|
+
|
|
253
|
+
```python
|
|
254
|
+
Agent(
|
|
255
|
+
name="my_agent",
|
|
256
|
+
model="anthropic/claude-opus-4-8", # any litellm model string
|
|
257
|
+
system_prompt="You are...",
|
|
258
|
+
mcps=[mcp1, mcp2], # MCP tool servers
|
|
259
|
+
tools=[my_fn, another_fn], # Python function tools
|
|
260
|
+
max_turns=10, # LLM→tool→LLM cycles
|
|
261
|
+
temperature=0.7,
|
|
262
|
+
max_tokens=4096,
|
|
263
|
+
extra_params={"thinking": {"type": "enabled", "budget_tokens": 5000}},
|
|
264
|
+
)
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
---
|
|
268
|
+
|
|
269
|
+
## Provider Examples
|
|
270
|
+
|
|
271
|
+
```python
|
|
272
|
+
# OpenAI
|
|
273
|
+
Agent("a", model="openai/gpt-4o")
|
|
274
|
+
Agent("a", model="openai/gpt-4o-mini")
|
|
275
|
+
|
|
276
|
+
# Anthropic
|
|
277
|
+
Agent("a", model="anthropic/claude-opus-4-8")
|
|
278
|
+
Agent("a", model="anthropic/claude-haiku-4-5-20251001")
|
|
279
|
+
|
|
280
|
+
# Google
|
|
281
|
+
Agent("a", model="gemini/gemini-2.0-flash")
|
|
282
|
+
Agent("a", model="gemini/gemini-2.5-pro")
|
|
283
|
+
|
|
284
|
+
# AWS Bedrock
|
|
285
|
+
Agent("a", model="bedrock/anthropic.claude-opus-4-8-20250514-v1:0")
|
|
286
|
+
|
|
287
|
+
# Azure OpenAI
|
|
288
|
+
Agent("a", model="azure/gpt-4o", extra_params={"api_base": "https://..."})
|
|
289
|
+
|
|
290
|
+
# Local (Ollama)
|
|
291
|
+
Agent("a", model="ollama/llama3.2")
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
---
|
|
295
|
+
|
|
296
|
+
## Installation
|
|
297
|
+
|
|
298
|
+
```bash
|
|
299
|
+
pip install deepcrew-ai
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
With development dependencies:
|
|
303
|
+
|
|
304
|
+
```bash
|
|
305
|
+
pip install deepcrew-ai[dev]
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
Requires Python 3.11+.
|
|
309
|
+
|
|
310
|
+
---
|
|
311
|
+
|
|
312
|
+
## License
|
|
313
|
+
|
|
314
|
+
MIT
|