Name | liteswarm JSON |
Version |
0.6.0
JSON |
| download |
home_page | None |
Summary | A lightweight framework for building AI agent systems |
upload_time | 2025-01-21 21:48:41 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.11 |
license | MIT License
Copyright (c) 2025 GlyphyAI
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
|
keywords |
ai
agents
llm
swarm
multi-agent
agent-systems
agent-orchestration
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# LiteSwarm 🐝
A lightweight, LLM-agnostic framework for building AI agents with dynamic agent switching. Supports 100+ language models through [litellm](https://github.com/BerriAI/litellm).
> [!WARNING]
> LiteSwarm is currently in early preview and the API is likely to change as we gather feedback.
>
> If you find any issues or have suggestions, please open an issue in the [Issues](https://github.com/glyphyai/liteswarm/issues) section.
## Features
- **Lightweight Core**: Minimal base implementation that's easy to understand and extend
- **LLM Agnostic**: Support for OpenAI, Anthropic, Google, and many more through litellm
- **Dynamic Agent Switching**: Switch between specialized agents during execution
- **Type-Safe Context**: Full type safety for context parameters and outputs
- **Stateful Chat Interface**: Build chat applications with built-in state management
- **Event Streaming**: Real-time streaming of agent responses and tool calls
## Installation
```bash
pip install liteswarm
```
## Requirements
- **Python**: Version 3.11 or higher
- **Async Runtime**: LiteSwarm provides only async API, so you need to use an event loop to run it
- **LLM Provider Key**: You'll need an API key from a supported LLM provider (see [supported providers](https://docs.litellm.ai/docs/providers))
<details>
<summary>[click to see how to set keys]</summary>
```python
# Environment variable
export OPENAI_API_KEY=sk-...
os.environ["OPENAI_API_KEY"] = "sk-..."
# .env file
OPENAI_API_KEY=sk-...
# Direct in code
LLM(model="gpt-4o", key="sk-...")
```
</details>
## Quick Start
> [!NOTE]
> All examples below are complete and can be run as is.
### Hello World
Here's a minimal example showing how to use LiteSwarm's core functionality:
```python
import asyncio
from liteswarm import LLM, Agent, Message, Swarm
async def main() -> None:
# Create a simple agent
agent = Agent(
id="assistant",
instructions="You are a helpful assistant.",
llm=LLM(model="gpt-4o"),
)
# Create swarm and run
swarm = Swarm()
result = await swarm.run(
agent=agent,
messages=[Message(role="user", content="Hello!")],
)
print(result.final_response.content)
if __name__ == "__main__":
asyncio.run(main())
```
### Streaming with Agent Switching
This example demonstrates real-time streaming and dynamic agent switching:
```python
import asyncio
from liteswarm import LLM, Agent, Message, Swarm, ToolResult, tool_plain
async def main() -> None:
# Define a tool that can switch to another agent
@tool_plain
def switch_to_expert(domain: str) -> ToolResult:
expert_agent = Agent(
id=f"{domain}-expert",
instructions=f"You are a {domain} expert.",
llm=LLM(
model="gpt-4o",
temperature=0.0,
),
)
return ToolResult.switch_to(expert_agent)
# Create a router agent that can switch to experts
router = Agent(
id="router",
instructions="Route questions to appropriate experts.",
llm=LLM(model="gpt-4o"),
tools=[switch_to_expert],
)
# Stream responses in real-time
swarm = Swarm()
stream = swarm.stream(
agent=router,
messages=[Message(role="user", content="Explain quantum physics like I'm 5")],
)
async for event in stream:
if event.type == "agent_response_chunk":
completion = event.chunk.completion
if completion.delta.content:
print(completion.delta.content, end="", flush=True)
if completion.finish_reason == "stop":
print()
# Optionally, get complete run result from stream
result = await stream.get_return_value()
print(result.final_response.content)
if __name__ == "__main__":
asyncio.run(main())
```
### Stateful Chat
Here's how to build a stateful chat application that maintains conversation history:
```python
import asyncio
from liteswarm import LLM, Agent, SwarmChat, SwarmEvent
def handle_event(event: SwarmEvent) -> None:
if event.type == "agent_response_chunk":
completion = event.chunk.completion
if completion.delta.content:
print(completion.delta.content, end="", flush=True)
if completion.finish_reason == "stop":
print()
async def main() -> None:
# Create an agent
agent = Agent(
id="assistant",
instructions="You are a helpful assistant. Provide short answers.",
llm=LLM(model="gpt-4o"),
)
# Create stateful chat
chat = SwarmChat()
# First message
print("First message:")
async for event in chat.send_message("Tell me about Python", agent=agent):
handle_event(event)
# Second message - chat remembers the context
print("\nSecond message:")
async for event in chat.send_message("What are its key features?", agent=agent):
handle_event(event)
# Access conversation history
messages = await chat.get_messages()
print(f"\nMessages in history: {len(messages)}")
if __name__ == "__main__":
asyncio.run(main())
```
For more examples, check out the [examples](examples/) directory. To learn more about advanced features and API details, see our [documentation](docs/).
## Documentation
- [Advanced Features](docs/advanced.md)
- [Examples](docs/examples.md)
- [API Reference](docs/api.md)
- [Contributing](docs/contributing.md)
## Citation
If you use LiteSwarm in your research, please cite our work:
```bibtex
@software{Mozharovskii_LiteSwarm_2025,
author = {Mozharovskii, Evgenii and {GlyphyAI}},
license = {MIT},
month = jan,
title = {{LiteSwarm}},
url = {https://github.com/glyphyai/liteswarm},
version = {0.6.0},
year = {2025}
}
```
## License
MIT License - see [LICENSE](LICENSE) file for details.
Raw data
{
"_id": null,
"home_page": null,
"name": "liteswarm",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.11",
"maintainer_email": null,
"keywords": "ai, agents, llm, swarm, multi-agent, agent-systems, agent-orchestration",
"author": null,
"author_email": "Evgenii Mozharovskii <eugene@glyphy.ai>",
"download_url": "https://files.pythonhosted.org/packages/bd/a5/fb34d44efa596d68acadf158706d1f053f20015772d365079a83b22e15c8/liteswarm-0.6.0.tar.gz",
"platform": null,
"description": "# LiteSwarm \ud83d\udc1d\n\nA lightweight, LLM-agnostic framework for building AI agents with dynamic agent switching. Supports 100+ language models through [litellm](https://github.com/BerriAI/litellm).\n\n> [!WARNING]\n> LiteSwarm is currently in early preview and the API is likely to change as we gather feedback.\n>\n> If you find any issues or have suggestions, please open an issue in the [Issues](https://github.com/glyphyai/liteswarm/issues) section.\n\n## Features\n\n- **Lightweight Core**: Minimal base implementation that's easy to understand and extend\n- **LLM Agnostic**: Support for OpenAI, Anthropic, Google, and many more through litellm\n- **Dynamic Agent Switching**: Switch between specialized agents during execution\n- **Type-Safe Context**: Full type safety for context parameters and outputs\n- **Stateful Chat Interface**: Build chat applications with built-in state management\n- **Event Streaming**: Real-time streaming of agent responses and tool calls\n\n## Installation\n\n```bash\npip install liteswarm\n```\n\n## Requirements\n\n- **Python**: Version 3.11 or higher\n- **Async Runtime**: LiteSwarm provides only async API, so you need to use an event loop to run it\n- **LLM Provider Key**: You'll need an API key from a supported LLM provider (see [supported providers](https://docs.litellm.ai/docs/providers))\n <details>\n <summary>[click to see how to set keys]</summary>\n\n ```python\n # Environment variable\n export OPENAI_API_KEY=sk-...\n os.environ[\"OPENAI_API_KEY\"] = \"sk-...\"\n \n # .env file\n OPENAI_API_KEY=sk-...\n \n # Direct in code\n LLM(model=\"gpt-4o\", key=\"sk-...\")\n ```\n </details>\n\n## Quick Start\n\n> [!NOTE]\n> All examples below are complete and can be run as is.\n\n### Hello World\n\nHere's a minimal example showing how to use LiteSwarm's core functionality:\n\n```python\nimport asyncio\n\nfrom liteswarm import LLM, Agent, Message, Swarm\n\n\nasync def main() -> None:\n # Create a simple agent\n agent = Agent(\n id=\"assistant\",\n instructions=\"You are a helpful assistant.\",\n llm=LLM(model=\"gpt-4o\"),\n )\n\n # Create swarm and run\n swarm = Swarm()\n result = await swarm.run(\n agent=agent,\n messages=[Message(role=\"user\", content=\"Hello!\")],\n )\n print(result.final_response.content)\n\n\nif __name__ == \"__main__\":\n asyncio.run(main())\n```\n\n### Streaming with Agent Switching\n\nThis example demonstrates real-time streaming and dynamic agent switching:\n\n```python\nimport asyncio\n\nfrom liteswarm import LLM, Agent, Message, Swarm, ToolResult, tool_plain\n\n\nasync def main() -> None:\n # Define a tool that can switch to another agent\n @tool_plain\n def switch_to_expert(domain: str) -> ToolResult:\n expert_agent = Agent(\n id=f\"{domain}-expert\",\n instructions=f\"You are a {domain} expert.\",\n llm=LLM(\n model=\"gpt-4o\",\n temperature=0.0,\n ),\n )\n\n return ToolResult.switch_to(expert_agent)\n\n # Create a router agent that can switch to experts\n router = Agent(\n id=\"router\",\n instructions=\"Route questions to appropriate experts.\",\n llm=LLM(model=\"gpt-4o\"),\n tools=[switch_to_expert],\n )\n\n # Stream responses in real-time\n swarm = Swarm()\n stream = swarm.stream(\n agent=router,\n messages=[Message(role=\"user\", content=\"Explain quantum physics like I'm 5\")],\n )\n\n async for event in stream:\n if event.type == \"agent_response_chunk\":\n completion = event.chunk.completion\n if completion.delta.content:\n print(completion.delta.content, end=\"\", flush=True)\n if completion.finish_reason == \"stop\":\n print()\n\n # Optionally, get complete run result from stream\n result = await stream.get_return_value()\n print(result.final_response.content)\n\n\nif __name__ == \"__main__\":\n asyncio.run(main())\n```\n\n### Stateful Chat\n\nHere's how to build a stateful chat application that maintains conversation history:\n\n```python\nimport asyncio\n\nfrom liteswarm import LLM, Agent, SwarmChat, SwarmEvent\n\n\ndef handle_event(event: SwarmEvent) -> None:\n if event.type == \"agent_response_chunk\":\n completion = event.chunk.completion\n if completion.delta.content:\n print(completion.delta.content, end=\"\", flush=True)\n if completion.finish_reason == \"stop\":\n print()\n\n\nasync def main() -> None:\n # Create an agent\n agent = Agent(\n id=\"assistant\",\n instructions=\"You are a helpful assistant. Provide short answers.\",\n llm=LLM(model=\"gpt-4o\"),\n )\n\n # Create stateful chat\n chat = SwarmChat()\n\n # First message\n print(\"First message:\")\n async for event in chat.send_message(\"Tell me about Python\", agent=agent):\n handle_event(event)\n\n # Second message - chat remembers the context\n print(\"\\nSecond message:\")\n async for event in chat.send_message(\"What are its key features?\", agent=agent):\n handle_event(event)\n\n # Access conversation history\n messages = await chat.get_messages()\n print(f\"\\nMessages in history: {len(messages)}\")\n\n\nif __name__ == \"__main__\":\n asyncio.run(main())\n```\n\nFor more examples, check out the [examples](examples/) directory. To learn more about advanced features and API details, see our [documentation](docs/).\n\n## Documentation\n\n- [Advanced Features](docs/advanced.md)\n- [Examples](docs/examples.md)\n- [API Reference](docs/api.md)\n- [Contributing](docs/contributing.md)\n\n## Citation\n\nIf you use LiteSwarm in your research, please cite our work:\n\n```bibtex\n@software{Mozharovskii_LiteSwarm_2025,\n author = {Mozharovskii, Evgenii and {GlyphyAI}},\n license = {MIT},\n month = jan,\n title = {{LiteSwarm}},\n url = {https://github.com/glyphyai/liteswarm},\n version = {0.6.0},\n year = {2025}\n}\n``` \n\n## License\n\nMIT License - see [LICENSE](LICENSE) file for details.\n",
"bugtrack_url": null,
"license": "MIT License\n \n Copyright (c) 2025 GlyphyAI\n \n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n \n The above copyright notice and this permission notice shall be included in all\n copies or substantial portions of the Software.\n \n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n SOFTWARE.\n ",
"summary": "A lightweight framework for building AI agent systems",
"version": "0.6.0",
"project_urls": {
"bug-tracker": "https://github.com/GlyphyAI/liteswarm/issues",
"changelog": "https://github.com/GlyphyAI/liteswarm/blob/main/CHANGELOG.md",
"documentation": "https://github.com/GlyphyAI/liteswarm#readme",
"homepage": "https://github.com/GlyphyAI/liteswarm",
"repository": "https://github.com/GlyphyAI/liteswarm"
},
"split_keywords": [
"ai",
" agents",
" llm",
" swarm",
" multi-agent",
" agent-systems",
" agent-orchestration"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "0509ab157ee31f266f85221ede17a501e85ced9428a695d1d4f8f1fd62f41355",
"md5": "18c042d66f25afdf8b0ad15588b5aba7",
"sha256": "4b784a9c2034e9b009f064554bbda5bf670274a82418f805794e30015b195fa8"
},
"downloads": -1,
"filename": "liteswarm-0.6.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "18c042d66f25afdf8b0ad15588b5aba7",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.11",
"size": 100148,
"upload_time": "2025-01-21T21:48:37",
"upload_time_iso_8601": "2025-01-21T21:48:37.946362Z",
"url": "https://files.pythonhosted.org/packages/05/09/ab157ee31f266f85221ede17a501e85ced9428a695d1d4f8f1fd62f41355/liteswarm-0.6.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "bda5fb34d44efa596d68acadf158706d1f053f20015772d365079a83b22e15c8",
"md5": "637df4c59826e73b9ded14df19ccb783",
"sha256": "d069683726f3cb56943513d1523fc14e28320a1686dec22282f3c5720f36d077"
},
"downloads": -1,
"filename": "liteswarm-0.6.0.tar.gz",
"has_sig": false,
"md5_digest": "637df4c59826e73b9ded14df19ccb783",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.11",
"size": 85373,
"upload_time": "2025-01-21T21:48:41",
"upload_time_iso_8601": "2025-01-21T21:48:41.247038Z",
"url": "https://files.pythonhosted.org/packages/bd/a5/fb34d44efa596d68acadf158706d1f053f20015772d365079a83b22e15c8/liteswarm-0.6.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-01-21 21:48:41",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "GlyphyAI",
"github_project": "liteswarm",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "liteswarm"
}