Merge branch 'master' into update/docs

pull/981/head^2
harshalmore31 2 days ago committed by GitHub
commit 8a858d0f4b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -228,7 +228,15 @@ nav:
- Quickstart: "quickstart.md" - Quickstart: "quickstart.md"
- Agents: "swarms/agents/index.md" - Agents: "swarms/agents/index.md"
- Multi-Agent Architectures: "swarms/structs/index.md" - Multi-Agent Architectures: "swarms/structs/index.md"
- Protocol:
- Overview: "protocol/overview.md"
- SIPs: "protocol/sip.md"
- Feature Set: "swarms/features.md" - Feature Set: "swarms/features.md"
- Swarms Ecosystem: "swarms/ecosystem.md"
- Technical Support: "swarms/support.md"
- Agents: - Agents:
- Overview: "swarms/framework/agents_explained.md" - Overview: "swarms/framework/agents_explained.md"
- Quickstart: "swarms/agents/index.md" - Quickstart: "swarms/agents/index.md"
@ -319,10 +327,6 @@ nav:
- Communication Structure: "swarms/structs/conversation.md" - Communication Structure: "swarms/structs/conversation.md"
- Protocol:
- Overview: "protocol/overview.md"
- SIPs: "protocol/sip.md"
- Tools: - Tools:
- Overview: "swarms_tools/overview.md" - Overview: "swarms_tools/overview.md"
- BaseTool Reference: "swarms/tools/base_tool.md" - BaseTool Reference: "swarms/tools/base_tool.md"
@ -346,10 +350,6 @@ nav:
- Deploy on Phala: "swarms_cloud/phala_deploy.md" - Deploy on Phala: "swarms_cloud/phala_deploy.md"
# - Deploy on FastAPI: "swarms_cloud/fastapi_deploy.md" # - Deploy on FastAPI: "swarms_cloud/fastapi_deploy.md"
- More About Us:
- Swarms Ecosystem: "swarms/ecosystem.md"
- Technical Support: "swarms/support.md"
- Examples: - Examples:
- Overview: "examples/index.md" - Overview: "examples/index.md"
@ -491,7 +491,7 @@ nav:
- Understanding Swarms Architecture: "swarms/concept/framework_architecture.md" - Understanding Swarms Architecture: "swarms/concept/framework_architecture.md"
- Development Philosophy & Principles: "swarms/concept/philosophy.md" - Development Philosophy & Principles: "swarms/concept/philosophy.md"
- About Swarms: # - About Swarms:
- Vision & Mission: "swarms/concept/vision.md" # - Vision & Mission: "swarms/concept/vision.md"
- Swarm Ecosystem: "swarms/concept/swarm_ecosystem.md" # - Swarm Ecosystem: "swarms/concept/swarm_ecosystem.md"
- Products: "swarms/products.md" # - Products: "swarms/products.md"

@ -25,16 +25,12 @@ The Swarms protocol is organized into several key layers, each responsible for a
- Agents can be specialized for different tasks (e.g., reasoning agents, tool agents, judge agents, etc.). - Agents can be specialized for different tasks (e.g., reasoning agents, tool agents, judge agents, etc.).
- Example: A `ReasoningAgent` that can analyze data and make decisions, or a `ToolAgent` that wraps external APIs. - Example: A `ReasoningAgent` that can analyze data and make decisions, or a `ToolAgent` that wraps external APIs.
- [Quickstart for Agents](https://docs.swarms.world/en/latest/swarms/agents/) - [Quickstart for Agents](https://docs.swarms.world/en/latest/swarms/agents/)
- [Agent API Reference](https://docs.swarms.world/en/latest/swarms/structs/agent/) - [Agent API Reference](https://docs.swarms.world/en/latest/swarms/structs/agent/)
2. **Tools with Memory (`swarms/tools`, `swarms/utils`)** 2. **Tools with Memory (`swarms/tools`, `swarms/utils`)**
- Tools are modular components that agents use to interact with the outside world, perform computations, or access resources (APIs, - Tools are modular components that agents use to interact with the outside world, perform computations, or access resources (APIs,
databases, files, etc.). databases, files, etc.).
@ -47,7 +43,6 @@ The Swarms protocol is organized into several key layers, each responsible for a
- [BaseTool Reference](https://docs.swarms.world/en/latest/swarms/tools/base_tool/) - [BaseTool Reference](https://docs.swarms.world/en/latest/swarms/tools/base_tool/)
3. **Reasoning & Specialized Agents (`swarms/agents`)** 3. **Reasoning & Specialized Agents (`swarms/agents`)**
- These agents build on the base agent class, adding advanced reasoning, self-consistency, and specialized logic for tasks like - These agents build on the base agent class, adding advanced reasoning, self-consistency, and specialized logic for tasks like
planning, evaluation, or multi-step workflows. planning, evaluation, or multi-step workflows.
@ -63,7 +58,6 @@ The Swarms protocol is organized into several key layers, each responsible for a
- [Agent Judge](https://docs.swarms.world/en/latest/swarms/agents/agent_judge/) - [Agent Judge](https://docs.swarms.world/en/latest/swarms/agents/agent_judge/)
4. **Multi-Agent Structures (`swarms/structs`)** 4. **Multi-Agent Structures (`swarms/structs`)**
- Agents are composed into higher-order structures for collaboration, voting, parallelism, and workflow orchestration. - Agents are composed into higher-order structures for collaboration, voting, parallelism, and workflow orchestration.
@ -82,7 +76,6 @@ The Swarms protocol is organized into several key layers, each responsible for a
- [Concurrent Workflow](https://docs.swarms.world/en/latest/swarms/structs/concurrentworkflow/) - [Concurrent Workflow](https://docs.swarms.world/en/latest/swarms/structs/concurrentworkflow/)
5. **Supporting Components** 5. **Supporting Components**
- **Communication (`swarms/communication`)**: Provides wrappers for inter-agent communication, database access, message passing, and - **Communication (`swarms/communication`)**: Provides wrappers for inter-agent communication, database access, message passing, and
@ -104,6 +97,34 @@ The Swarms protocol is organized into several key layers, each responsible for a
--- ---
## Proposing Large Improvements or Enhancements: Swarms Improvement Proposals (SIPs)
For significant changes, new agent architectures, or radical new features, Swarms uses a formal process called **Swarms Improvement Proposals (SIPs)**. SIPs are design documents that describe new features, enhancements, or changes to the Swarms framework. They ensure that major changes are well-documented, discussed, and reviewed by the community before implementation.
**When to use a SIP:**
- Proposing new agent types, swarm patterns, or coordination mechanisms
- Core framework changes or breaking changes
- New integrations (LLM providers, tools, external services)
- Any complex or multi-component feature
**SIP Process Overview:**
1. Discuss your idea in [GitHub Discussions](https://github.com/kyegomez/swarms/discussions)
2. Submit a SIP as a GitHub Issue using the SIP template
3. Engage with the community and iterate on your proposal
4. Undergo review and, if accepted, proceed to implementation
**Learn more:** See the full [SIP Guidelines and Template](https://docs.swarms.world/en/latest/protocol/sip/)
---
## Detailed Architecture Diagram ## Detailed Architecture Diagram
The following Mermaid diagram visualizes the protocol flow and the relationship between the main folders in the `swarms/` package: The following Mermaid diagram visualizes the protocol flow and the relationship between the main folders in the `swarms/` package:
@ -409,6 +430,8 @@ For more on the philosophy and architecture, see [Development Philosophy & Princ
- [Understanding Swarms Architecture](https://docs.swarms.world/en/latest/swarms/concept/framework_architecture/) - [Understanding Swarms Architecture](https://docs.swarms.world/en/latest/swarms/concept/framework_architecture/)
- [SIP Guidelines and Template](https://docs.swarms.world/en/latest/protocol/sip/)
# Conclusion # Conclusion

@ -0,0 +1,62 @@
from swarms import Agent, ConcurrentWorkflow, SwarmRouter
# Initialize market research agent
market_researcher = Agent(
agent_name="Market-Researcher",
system_prompt="""You are a market research specialist. Your tasks include:
1. Analyzing market trends and patterns
2. Identifying market opportunities and threats
3. Evaluating competitor strategies
4. Assessing customer needs and preferences
5. Providing actionable market insights""",
model_name="claude-3-5-sonnet-20240620",
max_loops=1,
streaming_on=True,
print_on=False,
)
# Initialize financial analyst agent
financial_analyst = Agent(
agent_name="Financial-Analyst",
system_prompt="""You are a financial analysis expert. Your responsibilities include:
1. Analyzing financial statements
2. Evaluating investment opportunities
3. Assessing risk factors
4. Providing financial forecasts
5. Recommending financial strategies""",
model_name="claude-3-5-sonnet-20240620",
max_loops=1,
streaming_on=True,
print_on=False,
)
# Initialize technical analyst agent
technical_analyst = Agent(
agent_name="Technical-Analyst",
system_prompt="""You are a technical analysis specialist. Your focus areas include:
1. Analyzing price patterns and trends
2. Evaluating technical indicators
3. Identifying support and resistance levels
4. Assessing market momentum
5. Providing trading recommendations""",
model_name="claude-3-5-sonnet-20240620",
max_loops=1,
streaming_on=True,
print_on=False,
)
# Create list of agents
agents = [market_researcher, financial_analyst, technical_analyst]
# Initialize the concurrent workflow
workflow = ConcurrentWorkflow(
name="market-analysis-workflow",
agents=agents,
max_loops=1,
show_dashboard=True,
)
# Run the workflow
result = workflow.run(
"Analyze Tesla (TSLA) stock from market, financial, and technical perspectives"
)

@ -996,6 +996,7 @@ class Agent:
self, self,
task: Optional[Union[str, Any]] = None, task: Optional[Union[str, Any]] = None,
img: Optional[str] = None, img: Optional[str] = None,
streaming_callback: Optional[Callable[[str], None]] = None,
*args, *args,
**kwargs, **kwargs,
) -> Any: ) -> Any:
@ -1077,6 +1078,7 @@ class Agent:
task=task_prompt, task=task_prompt,
img=img, img=img,
current_loop=loop_count, current_loop=loop_count,
streaming_callback=streaming_callback,
*args, *args,
**kwargs, **kwargs,
) )
@ -1084,6 +1086,7 @@ class Agent:
response = self.call_llm( response = self.call_llm(
task=task_prompt, task=task_prompt,
current_loop=loop_count, current_loop=loop_count,
streaming_callback=streaming_callback,
*args, *args,
**kwargs, **kwargs,
) )
@ -2470,6 +2473,7 @@ class Agent:
task: str, task: str,
img: Optional[str] = None, img: Optional[str] = None,
current_loop: int = 0, current_loop: int = 0,
streaming_callback: Optional[Callable[[str], None]] = None,
*args, *args,
**kwargs, **kwargs,
) -> str: ) -> str:
@ -2480,6 +2484,7 @@ class Agent:
task (str): The task to be performed by the `llm` object. task (str): The task to be performed by the `llm` object.
img (str, optional): Path or URL to an image file. img (str, optional): Path or URL to an image file.
audio (str, optional): Path or URL to an audio file. audio (str, optional): Path or URL to an audio file.
streaming_callback (Optional[Callable[[str], None]]): Callback function to receive streaming tokens in real-time.
*args: Variable length argument list. *args: Variable length argument list.
**kwargs: Arbitrary keyword arguments. **kwargs: Arbitrary keyword arguments.
@ -2515,8 +2520,24 @@ class Agent:
if hasattr( if hasattr(
streaming_response, "__iter__" streaming_response, "__iter__"
) and not isinstance(streaming_response, str): ) and not isinstance(streaming_response, str):
# Check if streaming_callback is provided (for ConcurrentWorkflow dashboard integration)
if streaming_callback is not None:
# Real-time callback streaming for dashboard integration
chunks = []
for chunk in streaming_response:
if (
hasattr(chunk, "choices")
and chunk.choices[0].delta.content
):
content = chunk.choices[
0
].delta.content
chunks.append(content)
# Call the streaming callback with the new chunk
streaming_callback(content)
complete_response = "".join(chunks)
# Check print_on parameter for different streaming behaviors # Check print_on parameter for different streaming behaviors
if self.print_on is False: elif self.print_on is False:
# Silent streaming - no printing, just collect chunks # Silent streaming - no printing, just collect chunks
chunks = [] chunks = []
for chunk in streaming_response: for chunk in streaming_response:
@ -2599,6 +2620,7 @@ class Agent:
img: Optional[str] = None, img: Optional[str] = None,
imgs: Optional[List[str]] = None, imgs: Optional[List[str]] = None,
correct_answer: Optional[str] = None, correct_answer: Optional[str] = None,
streaming_callback: Optional[Callable[[str], None]] = None,
*args, *args,
**kwargs, **kwargs,
) -> Any: ) -> Any:
@ -2613,6 +2635,7 @@ class Agent:
task (Optional[str], optional): The task to be executed. Defaults to None. task (Optional[str], optional): The task to be executed. Defaults to None.
img (Optional[str], optional): The image to be processed. Defaults to None. img (Optional[str], optional): The image to be processed. Defaults to None.
imgs (Optional[List[str]], optional): The list of images to be processed. Defaults to None. imgs (Optional[List[str]], optional): The list of images to be processed. Defaults to None.
streaming_callback (Optional[Callable[[str], None]], optional): Callback function to receive streaming tokens in real-time. Defaults to None.
*args: Additional positional arguments to be passed to the execution method. *args: Additional positional arguments to be passed to the execution method.
**kwargs: Additional keyword arguments to be passed to the execution method. **kwargs: Additional keyword arguments to be passed to the execution method.
@ -2644,6 +2667,7 @@ class Agent:
output = self._run( output = self._run(
task=task, task=task,
img=img, img=img,
streaming_callback=streaming_callback,
*args, *args,
**kwargs, **kwargs,
) )

@ -1,5 +1,6 @@
import concurrent.futures import concurrent.futures
import os import os
import time
from typing import Callable, List, Optional, Union from typing import Callable, List, Optional, Union
from swarms.structs.agent import Agent from swarms.structs.agent import Agent
@ -450,8 +451,25 @@ class ConcurrentWorkflow(BaseSwarm):
if self.show_dashboard: if self.show_dashboard:
self.display_agent_dashboard() self.display_agent_dashboard()
# Run the agent # Create a streaming callback for this agent with throttling
output = agent.run(task=task, img=img, imgs=imgs) last_update_time = [0] # Use list to allow modification in nested function
update_interval = 0.1 # Update dashboard every 100ms for smooth streaming
def streaming_callback(chunk: str):
"""Update dashboard with streaming content"""
if self.show_dashboard:
# Append the chunk to the agent's current output
current_output = self.agent_statuses[agent.agent_name]["output"]
self.agent_statuses[agent.agent_name]["output"] = current_output + chunk
# Throttle dashboard updates for better performance
current_time = time.time()
if current_time - last_update_time[0] >= update_interval:
self.display_agent_dashboard()
last_update_time[0] = current_time
# Run the agent with streaming callback
output = agent.run(task=task, img=img, imgs=imgs, streaming_callback=streaming_callback)
# Update status to completed # Update status to completed
self.agent_statuses[agent.agent_name][ self.agent_statuses[agent.agent_name][

@ -963,10 +963,16 @@ Remember: You are part of a team. Your response should reflect that you've read,
to respond to the user query. to respond to the user query.
""" """
# Filter out invalid agents # Filter out invalid agents
valid_agents = [name for name in mentioned_agents if name in self.agent_map] valid_agents = [
name
for name in mentioned_agents
if name in self.agent_map
]
if not valid_agents: if not valid_agents:
raise AgentNotFoundError("No valid agents found in the conversation") raise AgentNotFoundError(
"No valid agents found in the conversation"
)
# Randomly select exactly one agent to respond # Randomly select exactly one agent to respond
random_agent = random.choice(valid_agents) random_agent = random.choice(valid_agents)

Loading…
Cancel
Save