Skip to content

Commit 75e1287

Browse files
committed
[feat][grep-tool][add grep search tool to autonomous
loop][improvement][autonomous-loop][fix execution prompt written once per subtask][bugf][streaming-thinking][prevent thinking panel corruption inside live context][improvement][arun-stream][use get_running_loop and propagate exceptions][bugf][final-summary][thread streaming callback through generate final summary][improvement][think-tool][exclude think tool when thinking tokens enabled][bugf][license][correct license from MIT to Apache-2.0][improvement][sensor-assembly][remove deprecated senator assembly module]
1 parent 2c5660f commit 75e1287

16 files changed

Lines changed: 2648 additions & 3775 deletions

README.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -366,8 +366,7 @@ The `SwarmRouter` simplifies building complex workflows by providing a single in
366366
This makes your code cleaner and more flexible, allowing you to switch between different multi-agent strategies with ease. Here's a complete example that shows how to define agents and then use `SwarmRouter` to execute the same task using different collaborative strategies.
367367

368368
```python
369-
from swarms import Agent
370-
from swarms.structs.swarm_router import SwarmRouter, SwarmType
369+
from swarms import Agent, SwarmRouter, SwarmType
371370

372371
# Define a few generic agents
373372
writer = Agent(agent_name="Writer", system_prompt="You are a creative writer.", model_name="gpt-5.4")
@@ -421,7 +420,7 @@ The `SwarmRouter` is a powerful tool for simplifying multi-agent orchestration.
421420
The `AutoSwarmBuilder` automatically generates specialized agents and their workflows based on your task description. Simply describe what you need, and it will create a complete multi-agent system with detailed prompts and optimal agent configurations. [Learn more about AutoSwarmBuilder](https://docs.swarms.world/en/latest/swarms/structs/auto_swarm_builder/)
422421

423422
```python
424-
from swarms.structs.auto_swarm_builder import AutoSwarmBuilder
423+
from swarms import AutoSwarmBuilder
425424
import json
426425

427426
# Initialize the AutoSwarmBuilder
@@ -692,8 +691,7 @@ Perfect for implementing complex multi-agent workflows, collaborative problem-so
692691
The **Agent Orchestration Protocol (AOP)** is a powerful framework for deploying and managing agents as distributed services. AOP enables agents to be discovered, managed, and executed through a standardized protocol, making it perfect for building scalable multi-agent systems. [Learn more about AOP](https://docs.swarms.world/en/latest/swarms/structs/aop/)
693692

694693
```python
695-
from swarms import Agent
696-
from swarms.structs.aop import AOP
694+
from swarms import Agent, AOP
697695

698696
# Create specialized agents
699697
research_agent = Agent(

docs/mkdocs.yml

Lines changed: 0 additions & 156 deletions
Original file line numberDiff line numberDiff line change
@@ -347,162 +347,6 @@ nav:
347347
- AOP Server Setup: "swarms/examples/aop_server_example.md"
348348
- AOP Cluster Example: "swarms/examples/aop_cluster_example.md"
349349

350-
351-
- Examples:
352-
- Overview: "examples/index.md"
353-
- CookBook Index: "examples/cookbook_index.md"
354-
- Paper Implementations: "examples/paper_implementations.md"
355-
- Templates & Applications: "examples/templates.md"
356-
- Community Resources: "examples/community_resources.md"
357-
358-
- CLI Guides:
359-
- Overview: "examples/cli_guides_overview.md"
360-
- CLI Quickstart: "swarms/cli/cli_quickstart.md"
361-
- Creating Agents from CLI: "swarms/cli/cli_agent_guide.md"
362-
- YAML Configuration: "swarms/cli/cli_yaml_guide.md"
363-
- LLM Council CLI: "swarms/cli/cli_llm_council_guide.md"
364-
- Heavy Swarm CLI: "swarms/cli/cli_heavy_swarm_guide.md"
365-
- CLI Multi-Agent Commands: "examples/cli_multi_agent_quickstart.md"
366-
- CLI Examples: "swarms/cli/cli_examples.md"
367-
- Chat Command Usage: "examples/chat_command_usage.md"
368-
369-
- Agent Examples:
370-
- Overview: "examples/basic_examples_overview.md"
371-
- Basic Agent: "swarms/examples/basic_agent.md"
372-
- ReAct Agent Tutorial: "swarms/examples/react_agent_tutorial.md"
373-
- Agent Skills: "swarms/examples/agent_skills_overview.md"
374-
- Autonomous Agent: "swarms/examples/autonomous_agent_tutorial.md"
375-
- Agent Handoff: "swarms/examples/agent_handoff_tutorial.md"
376-
- Sub-Agent Delegation: "swarms/examples/sub_agent_tutorial.md"
377-
- Autosave: "swarms/examples/autosave_tutorial.md"
378-
- Tool Usage:
379-
- Agents with Vision and Tool Usage: "swarms/examples/vision_tools.md"
380-
- Callable Tools: "swarms/examples/agent_with_tools.md"
381-
- Structured Outputs: "swarms/examples/agent_structured_outputs.md"
382-
- Pydantic Structured Outputs Tutorial: "swarms/examples/pydantic_structured_outputs_tutorial.md"
383-
- Message Transforms for Context Management: "swarms/structs/transforms.md"
384-
- Selecting PreConfigured Tools: "examples/autonomous_looper_tools.md"
385-
- Vision:
386-
- Agents with Vision: "swarms/examples/vision_processing.md"
387-
- Base64 Image Handling: "swarms/examples/base64_image.md"
388-
- Agent with Multiple Images: "swarms/examples/multiple_images.md"
389-
- Utils:
390-
- Agent with Streaming: "examples/agent_stream.md"
391-
- Agent Output Types: "swarms/examples/agent_output_types.md"
392-
- Gradio Chat Interface: "swarms/ui/main.md"
393-
- LLM Providers:
394-
- Language Models:
395-
- Overview: "swarms/examples/model_providers.md"
396-
- LiteLLM: "swarms/examples/litellm.md"
397-
- OpenAI: "swarms/examples/openai_example.md"
398-
- Anthropic: "swarms/examples/claude.md"
399-
- Groq: "swarms/examples/groq.md"
400-
- Cohere: "swarms/examples/cohere.md"
401-
- DeepSeek: "swarms/examples/deepseek.md"
402-
- Ollama: "swarms/examples/ollama.md"
403-
- OpenRouter: "swarms/examples/openrouter.md"
404-
- XAI: "swarms/examples/xai.md"
405-
- Azure OpenAI: "swarms/examples/azure.md"
406-
- Llama4: "swarms/examples/llama4.md"
407-
- Custom Base URL & API Keys: "swarms/examples/custom_base_url_example.md"
408-
- vLLM Custom Wrapper: "swarms/examples/vllm_custom_wrapper.md"
409-
410-
- Multi-Agent Examples:
411-
- Overview: "examples/multi_agent_architectures_overview.md"
412-
- Guide to Choosing Multi-Agent Architectures: "swarms/concept/how_to_choose_swarms.md"
413-
414-
- Hierarchical & Orchestration:
415-
- HierarchicalSwarm: "swarms/examples/hierarchical_swarm_example.md"
416-
- PlannerWorkerSwarm: "swarms/examples/planner_worker_swarm_example.md"
417-
- Hybrid Hierarchical-Cluster Swarm: "swarms/examples/hhcs_examples.md"
418-
- AutoSwarmBuilder: "swarms/examples/auto_swarm_builder_example.md"
419-
- SwarmRouter: "swarms/examples/swarm_router.md"
420-
- MultiAgentRouter: "swarms/examples/multi_agent_router_minimal.md"
421-
- ModelRouter: "swarms/examples/model_router_example.md"
422-
- AgentRearrange: "swarms/examples/agent_rearrange_example.md"
423-
- SwarmRearrange: "swarms/examples/swarm_rearrange_example.md"
424-
- SkillOrchestra: "swarms/examples/skill_orchestra_example.md"
425-
426-
- Voting & Consensus:
427-
- MajorityVoting: "swarms/examples/majority_voting_example.md"
428-
- CouncilAsAJudge: "swarms/examples/council_as_judge_example.md"
429-
- LLM Council: "swarms/examples/llm_council_examples.md"
430-
- DebateWithJudge Quickstart: "examples/debate_quickstart.md"
431-
- Mixture of Agents: "swarms/examples/moa_example.md"
432-
- SelfMoASeq: "swarms/examples/self_moa_seq_example.md"
433-
434-
- Workflow Patterns:
435-
- Sequential Workflow: "swarms/examples/sequential_example.md"
436-
- Concurrent Workflow: "swarms/examples/concurrent_workflow.md"
437-
- GraphWorkflow: "swarms/examples/graphworkflow_example.md"
438-
- BatchedGridWorkflow: "swarms/examples/batched_grid_simple_example.md"
439-
440-
- Group Communication:
441-
- GroupChat: "swarms/examples/groupchat_comprehensive_examples.md"
442-
- RoundRobinSwarm: "swarms/examples/roundrobin_example.md"
443-
- SocialAlgorithms: "swarms/examples/social_algorithms_example.md"
444-
445-
- Communication Patterns:
446-
- Circular Swarm: "swarms/examples/circular_swarm_example.md"
447-
- Grid Swarm: "swarms/examples/grid_swarm_example.md"
448-
- Star Swarm: "swarms/examples/star_swarm_example.md"
449-
- Mesh Swarm: "swarms/examples/mesh_swarm_example.md"
450-
- Pyramid Swarm: "swarms/examples/pyramid_swarm_example.md"
451-
- One-to-One Communication: "swarms/examples/one_to_one_example.md"
452-
- Broadcast Communication: "swarms/examples/broadcast_example.md"
453-
454-
- Utilities:
455-
- Unique Swarms: "swarms/examples/unique_swarms.md"
456-
- Agents as Tools: "swarms/examples/agents_as_tools.md"
457-
- Aggregate Responses: "swarms/examples/aggregate.md"
458-
- SpreadSheetSwarm: "swarms/examples/spreadsheet_swarm_example.md"
459-
460-
- Applications:
461-
- Overview: "examples/applications_overview.md"
462-
- Swarms of Browser Agents: "swarms/examples/swarms_of_browser_agents.md"
463-
- Hiearchical Marketing Team: "examples/marketing_team.md"
464-
- Gold ETF Research with HeavySwarm: "examples/gold_etf_research.md"
465-
- Hiring Swarm: "examples/hiring_swarm.md"
466-
- Advanced Research: "examples/av.md"
467-
- Real Estate Swarm: "examples/realestate_swarm.md"
468-
- Job Finding Swarm: "examples/job_finding.md"
469-
- Mergers & Aquisition (M&A) Advisory Swarm: "examples/ma_swarm.md"
470-
471-
- Voice Agents:
472-
- Overview: "swarms/examples/voice_agents_overview.md"
473-
- Single Speech Agent: "swarms/examples/single_agent_speech.md"
474-
- Multi-Agent Speech Debate: "swarms/examples/multi_agent_speech_debate.md"
475-
- Hierarchical Speech Swarm: "swarms/examples/hierarchical_speech_swarm.md"
476-
477-
- Tools & Integrations:
478-
- Overview: "examples/tools_integrations_overview.md"
479-
- Web Search with Exa: "examples/exa_search.md"
480-
- Browser Use: "examples/browser_use.md"
481-
- Yahoo Finance: "swarms/examples/yahoo_finance.md"
482-
- Firecrawl: "developer_guides/firecrawl.md"
483-
484-
- MCP:
485-
- Multi-MCP Agent Integration: "swarms/examples/multi_mcp_agent.md"
486-
487-
- RAG:
488-
- Overview: "examples/rag_examples_overview.md"
489-
- RAG with Qdrant: "swarms/RAG/qdrant_rag.md"
490-
491-
- Apps:
492-
- Overview: "examples/apps_examples_overview.md"
493-
- Web Scraper Agents: "developer_guides/web_scraper.md"
494-
- Smart Database: "examples/smart_database.md"
495-
496-
- AOP:
497-
- Overview: "examples/aop_examples_overview.md"
498-
- Medical AOP Example: "examples/aop_medical.md"
499-
500-
- X402:
501-
- x402 Quickstart Example: "examples/x402_payment_integration.md"
502-
- X402 Discovery Query Agent: "examples/x402_discovery_query.md"
503-
- X402 Tools Agent: "swarms/examples/x402_tools_agent.md"
504-
505-
506350
- Swarms Rust:
507351
- Overview: "swarms_rs/overview.md"
508352
- Agents: "swarms_rs/agents.md"

example.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,21 @@
22

33
# Initialize the agent
44
agent = Agent(
5-
agent_name="Quantitative-Trading-Agent",
5+
agent_name="Quantitative-Trading-Agent--new",
66
agent_description="Advanced quantitative trading and algorithmic analysis agent",
77
system_prompt="You are a helpful assistant that can answer questions and help with tasks and your name is Quantitative-Trading-Agent",
8-
model_name="gpt-5.4",
8+
model_name="claude-sonnet-4-6",
99
dynamic_temperature_enabled=True,
1010
max_loops=1,
1111
dynamic_context_window=True,
1212
top_p=None,
13+
thinking_tokens=1024,
14+
reasoning_effort="high",
15+
streaming_on=True,
1316
)
1417

1518
out = agent.run(
16-
task="What are the top five best energy stocks across nuclear, solar, gas, and other energy sources?",
19+
task="Do a deep dive into just one of your choices",
1720
)
1821

1922
print(out)

example_streaming_tools.py

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
import json
2+
3+
from swarms import Agent
4+
5+
6+
# ---------------------------------------------------------------------------
7+
# Tools
8+
# ---------------------------------------------------------------------------
9+
10+
11+
def get_stock_price(ticker: str) -> str:
12+
"""Return a mock current price for a stock ticker."""
13+
prices = {
14+
"AAPL": 213.45,
15+
"MSFT": 415.20,
16+
"NVDA": 875.30,
17+
"CEG": 192.60,
18+
}
19+
price = prices.get(ticker.upper(), 100.00)
20+
return json.dumps(
21+
{"ticker": ticker.upper(), "price": price, "currency": "USD"}
22+
)
23+
24+
25+
def get_market_news(topic: str) -> str:
26+
"""Return mock market headlines for a topic."""
27+
headlines = {
28+
"energy": "Nuclear power demand surges as data-center operators sign long-term PPAs.",
29+
"semiconductors": "NVDA posts record revenue driven by AI accelerator shipments.",
30+
}
31+
text = headlines.get(
32+
topic.lower(), f"Markets steady; awaiting data on {topic}."
33+
)
34+
return json.dumps({"topic": topic, "headline": text})
35+
36+
37+
def calculate_pe_ratio(price: float, eps: float) -> str:
38+
"""Calculate price-to-earnings ratio."""
39+
if eps <= 0:
40+
return json.dumps({"error": "EPS must be positive"})
41+
return json.dumps(
42+
{
43+
"price": price,
44+
"eps": eps,
45+
"pe_ratio": round(price / eps, 2),
46+
}
47+
)
48+
49+
50+
TASK = (
51+
"Analyse Constellation Energy (CEG): fetch the current price, "
52+
"check the latest energy market news, and compute the P/E ratio assuming "
53+
"EPS of $8.40. Give me a buy / hold / sell recommendation."
54+
)
55+
56+
57+
def make_agent() -> Agent:
58+
return Agent(
59+
agent_name="Streaming-Trading-Agent",
60+
agent_description="Quantitative trading analyst",
61+
system_prompt=(
62+
"You are a quantitative trading analyst. "
63+
"Use the available tools to fetch live data before forming your view."
64+
),
65+
model_name="claude-sonnet-4-6",
66+
max_loops="auto",
67+
thinking_tokens=2048,
68+
tools=[get_stock_price, get_market_news, calculate_pe_ratio],
69+
top_p=None,
70+
streaming_on=True,
71+
reasoning_effort="high",
72+
temperature=1,
73+
)
74+
75+
76+
# ---------------------------------------------------------------------------
77+
# 1. Sync generator — run_stream()
78+
# ---------------------------------------------------------------------------
79+
80+
81+
def demo_sync():
82+
print("\n" + "=" * 60)
83+
print("SYNC STREAMING (run_stream)")
84+
print("=" * 60 + "\n")
85+
86+
agent = make_agent()
87+
88+
out = agent.run(TASK)
89+
print(out)
90+
91+
92+
# ---------------------------------------------------------------------------
93+
# 2. Async generator — arun_stream()
94+
# ---------------------------------------------------------------------------
95+
96+
97+
async def demo_async():
98+
print("\n" + "=" * 60)
99+
print("ASYNC STREAMING (arun_stream)")
100+
print("=" * 60 + "\n")
101+
102+
agent = make_agent()
103+
104+
async for token in agent.arun_stream(TASK):
105+
print(token, end="", flush=True)
106+
107+
print("\n")
108+
109+
110+
# ---------------------------------------------------------------------------
111+
# 3. Original blocking call — run() (for comparison)
112+
# ---------------------------------------------------------------------------
113+
114+
115+
def demo_blocking():
116+
print("\n" + "=" * 60)
117+
print("BLOCKING (run)")
118+
print("=" * 60 + "\n")
119+
120+
agent = make_agent()
121+
agent.print_on = True # let the agent render its own panels
122+
123+
result = agent.run(TASK)
124+
print(result)
125+
126+
127+
# ---------------------------------------------------------------------------
128+
# Entry point
129+
# ---------------------------------------------------------------------------
130+
131+
if __name__ == "__main__":
132+
mode = "async"
133+
134+
# if mode == "async":
135+
# asyncio.run(demo_async())
136+
# elif mode == "blocking":
137+
# demo_blocking()
138+
# else:
139+
demo_sync()

examples/multi_agent/simulations/senator_assembly/simulation_vote_example.py

Lines changed: 0 additions & 23 deletions
This file was deleted.

0 commit comments

Comments
 (0)