Skip to content

Commit ce32169

Browse files
committed
[FEAT][Agent with selected tools method name] [Examples][Improve examples section with update references]
1 parent 4d6301a commit ce32169

10 files changed

Lines changed: 292 additions & 47 deletions

File tree

docs/guides/launch_tokens_guide.py

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
import json
2+
import os
3+
from typing import Optional
4+
5+
import httpx
6+
from dotenv import load_dotenv
7+
8+
from swarms import Agent
9+
10+
load_dotenv()
11+
12+
BASE_URL = "https://swarms.world"
13+
14+
PRIVATE_KEY = os.getenv("PRIVATE_KEY")
15+
SWARMS_API_KEY = os.getenv("SWARMS_API_KEY")
16+
17+
# System prompt: specialize the agent as a meme-coin launch expert
18+
MEME_COIN_LAUNCH_SYSTEM_PROMPT = """
19+
You are an expert at launching meme coins. Your specialty is:
20+
21+
- **Naming & branding**: Create catchy, memorable token names and tickers (short, punchy, often 3–5 chars) that fit the meme or theme.
22+
- **Copy & narrative**: Write sharp, viral-ready descriptions and one-liners that explain the joke or community without sounding corporate.
23+
- **Creative direction**: Suggest or interpret image/logo ideas (URLs or base64) that match the meme aesthetic—bold, simple, recognizable.
24+
- **Launch strategy**: When asked, advise on timing, community hooks, and how to describe the token so it resonates with degens and normies alike.
25+
26+
You have tools: `launch_token(name, description, ticker, image)` to create a token on the Swarms launchpad, and `claim_fees_httpx(contract_address)` to claim fees. Use them when the user wants to launch a token or manage fees. Always confirm key details (name, ticker, description, image) with the user before calling launch_token unless they have already provided everything. Be concise, creative, and on-brand for meme coins.
27+
"""
28+
29+
30+
def launch_token(
31+
name: str,
32+
description: str,
33+
ticker: str,
34+
image: str,
35+
):
36+
"""
37+
Launches a new token on the Swarms platform via the Launchpad API.
38+
39+
This function sends a POST request to the Swarms API to create a new token with the specified parameters.
40+
It uses the API key and the configured private key for authentication and authorization.
41+
42+
Args:
43+
name (str): The name of the token to be launched (e.g., "My Cool Token").
44+
description (str): A brief description of the token's purpose or use-case.
45+
ticker (str): The ticker symbol for the token (e.g., "MCT").
46+
image (str): A URL or base64-encoded string representing the token image/logo.
47+
48+
Returns:
49+
dict: The parsed JSON response from the API containing token creation details
50+
or error information. Expected successful response keys may include:
51+
- "success" (bool): Whether the token was created successfully.
52+
- "token_id" (str or int): The ID of the created token.
53+
- "message" (str): Additional info or status messages.
54+
55+
Raises:
56+
httpx.RequestError: If there is a network problem or the API is unreachable.
57+
httpx.HTTPStatusError: If the server returns an error status code.
58+
(Note: these errors will not be caught here; callers should handle as needed.)
59+
60+
Example:
61+
>>> result = launch_token(
62+
... name="Test Token",
63+
... description="Token for demo purposes.",
64+
... ticker="TT",
65+
... image="https://example.com/img.png"
66+
... )
67+
>>> print(result["success"])
68+
True
69+
70+
Security Notes:
71+
- The `PRIVATE_KEY` is sent as part of the payload. Keep your keys secure and
72+
be careful not to expose them.
73+
- Ensure that SWARMS_API_KEY and PRIVATE_KEY are set in your environment variables.
74+
75+
"""
76+
url = f"{BASE_URL}/api/token/launch"
77+
headers = {
78+
"Authorization": f"Bearer {SWARMS_API_KEY}",
79+
"Content-Type": "application/json",
80+
}
81+
data = {
82+
"name": name,
83+
"description": description,
84+
"ticker": ticker,
85+
"image": image,
86+
"private_key": PRIVATE_KEY,
87+
}
88+
response = httpx.post(url, headers=headers, json=data)
89+
output = response.json()
90+
91+
return json.dumps(output, indent=4)
92+
93+
94+
def claim_fees_httpx(
95+
contract_address: Optional[str] = None,
96+
) -> str:
97+
"""
98+
Claims fees from the Swarms API using httpx.
99+
100+
Args:
101+
contract_address (Optional[str]): The contract address ("ca") to claim from.
102+
Defaults to a preset address if not provided.
103+
private_key (Optional[str]): The base58 private key for authorization.
104+
Must be provided by the caller for security.
105+
106+
Returns:
107+
dict: The parsed JSON response from the API containing signature, amount claimed,
108+
fees, or error information.
109+
"""
110+
url = "https://swarms.world/api/product/claimfees"
111+
private_key = PRIVATE_KEY
112+
113+
payload = {"ca": contract_address, "privateKey": private_key}
114+
115+
try:
116+
response = httpx.post(url, json=payload, timeout=10)
117+
response.raise_for_status()
118+
data = response.json()
119+
return json.dumps(data, indent=4)
120+
except httpx.HTTPStatusError as exc:
121+
# If error response is JSON, attempt to extract "error" or fall back to content string
122+
try:
123+
error_data = exc.response.json()
124+
print(
125+
"Error:", error_data.get("error", exc.response.text)
126+
)
127+
return error_data
128+
except Exception:
129+
print("Error:", exc.response.text)
130+
return {"error": exc.response.text}
131+
except httpx.RequestError as exc:
132+
print(
133+
f"Network error while requesting {exc.request.url!r}: {exc}"
134+
)
135+
return {"error": str(exc)}
136+
137+
138+
# Initialize the agent
139+
agent = Agent(
140+
agent_name="Meme-Coin-Launch-Pro",
141+
agent_description="Expert agent for launching and branding meme coins on the Swarms launchpad; specializes in naming, tickers, viral copy, and token creation.",
142+
system_prompt=MEME_COIN_LAUNCH_SYSTEM_PROMPT,
143+
model_name="anthropic/claude-sonnet-4-5",
144+
dynamic_temperature_enabled=True,
145+
max_loops=1,
146+
dynamic_context_window=True,
147+
streaming_on=True,
148+
interactive=False,
149+
top_p=None,
150+
tools=[claim_fees_httpx, launch_token],
151+
)
152+
153+
out = agent.run(
154+
task="I want to launch a meme coin about a cat that thinks it's a CEO. Suggest a name, ticker, short description, and what kind of image would work. If I say 'launch it', use the launch_token tool with those details (you can use a placeholder image URL if I don't provide one).",
155+
)
156+
157+
print(out)

example_autonomous_looper_run_bash.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@
2626
"list_directory",
2727
"run_bash",
2828
],
29-
top_p=None,
3029
)
3130

3231
if __name__ == "__main__":
33-
result = agent.run(
34-
task="Use the terminal to list the current directory, and see what files are in it."
35-
)
36-
print(result)
32+
# result = agent.run(
33+
# task="Use the terminal to list the current directory, and see what files are in it."
34+
# )
35+
# print(result)
36+
print(agent.get_all_selected_tools())

examples/README.md

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -185,22 +185,6 @@ This directory contains comprehensive examples demonstrating various capabilitie
185185
| [test_stagehand_integration.py](tools/stagehand/tests/test_stagehand_integration.py) | Stagehand integration test |
186186
| [test_stagehand_simple.py](tools/stagehand/tests/test_stagehand_simple.py) | Simple Stagehand test |
187187

188-
### Model Integrations
189-
190-
| Example | Description |
191-
|---------|-------------|
192-
| [models/](models/) | Various model integrations including Cerebras, GPT-5, GPT-OSS, Llama 4, Lumo, O3, Ollama, and vLLM implementations with concurrent processing examples and provider-specific configurations |
193-
| [README.md](models/README.md) | Model integration documentation |
194-
| [simple_example_ollama.py](models/simple_example_ollama.py) | Ollama integration example |
195-
| [cerebas_example.py](models/cerebas_example.py) | Cerebras model example |
196-
| [lumo_example.py](models/lumo_example.py) | Lumo model example |
197-
| [example_o3.py](models/example_o3.py) | O3 model example |
198-
| [gpt_5/](models/gpt_5/) | GPT-5 model examples |
199-
| [gpt_oss_examples/](models/gpt_oss_examples/) | GPT-OSS examples |
200-
| [llama4_examples/](models/llama4_examples/) | Llama 4 examples |
201-
| [main_providers/](models/main_providers/) | Main provider configurations |
202-
| [vllm/](models/vllm/) | vLLM integration examples |
203-
204188
### API & Protocols
205189

206190
#### Swarms API
@@ -301,12 +285,14 @@ This directory contains comprehensive examples demonstrating various capabilitie
301285
| [reasoning_duo_example.py](reasoning_agents/reasoning_agent_router_examples/reasoning_duo_example.py) | Reasoning duo example |
302286
| [reflexion_agent_example.py](reasoning_agents/reasoning_agent_router_examples/reflexion_agent_example.py) | Reflexion agent example |
303287
| [self_consistency_example.py](reasoning_agents/reasoning_agent_router_examples/self_consistency_example.py) | Self-consistency example |
304-
| [voice_agents/](voice_agents/) | Voice and speech-enabled agent examples including agent speech, agent with speech, debate with speech, Google Calendar integration, and hierarchical speech swarm capabilities |
288+
| [voice_agents/](voice_agents/) | Voice and speech-enabled agent examples including agent speech, agent with speech, debate with speech, Google Calendar integration, hierarchical speech swarm, and autonomous agent with speech |
289+
| [README.md](voice_agents/README.md) | Voice agents documentation |
305290
| [agent_speech.py](voice_agents/agent_speech.py) | Agent with speech capabilities |
306291
| [agent_with_speech.py](voice_agents/agent_with_speech.py) | Speech-enabled agent implementation |
307292
| [debate_with_speech.py](voice_agents/debate_with_speech.py) | Multi-agent debate with speech capabilities |
308293
| [google_calendar_agent.py](voice_agents/google_calendar_agent.py) | Google Calendar integration with voice agent |
309294
| [hiearchical_speech_swarm.py](voice_agents/hiearchical_speech_swarm.py) | Hierarchical speech swarm implementation |
295+
| [run_auto_agent_with_speech.py](voice_agents/run_auto_agent_with_speech.py) | Autonomous agent with terminal access and streaming TTS |
310296

311297
### Marketplace
312298

@@ -508,13 +494,7 @@ This directory contains comprehensive examples demonstrating various capabilitie
508494
| [Mistral](single_agent/llms/mistral_example.py) | Mistral models |
509495
| [O3](single_agent/llms/o3_agent.py) | O3 model integration |
510496
| [Qwen](single_agent/llms/qwen_3_base.py) | Qwen model integration |
511-
| [Ollama](models/simple_example_ollama.py) | Local Ollama models |
512-
| [Cerebras](models/cerebas_example.py) | Cerebras model integration |
513-
| [Lumo](models/lumo_example.py) | Lumo model integration |
514-
| [GPT-5](models/gpt_5/) | GPT-5 model examples |
515-
| [GPT-OSS](models/gpt_oss_examples/) | GPT-OSS examples |
516-
| [Llama 4](models/llama4_examples/) | Llama 4 examples |
517-
| [vLLM](models/vllm/) | vLLM integration examples |
497+
| [Ollama](https://docs.swarms.world) | Local Ollama and other providers via LiteLLM—see docs and [single_agent/llms/](single_agent/llms/) |
518498

519499
### Marketplace Examples
520500

examples/multi_agent/README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,19 @@ This directory contains comprehensive examples demonstrating various multi-agent
4141
- [concurrent_example.py](concurrent_examples/concurrent_example.py) - Basic concurrent execution
4242
- [concurrent_mix.py](concurrent_examples/concurrent_mix.py) - Mixed concurrent patterns
4343
- [concurrent_swarm_example.py](concurrent_examples/concurrent_swarm_example.py) - Concurrent swarm execution
44+
- [concurrent_workflow_autosave_example.py](concurrent_examples/concurrent_workflow_autosave_example.py) - Concurrent workflow with autosave
45+
- [example_concurrent.py](concurrent_examples/example_concurrent.py) - Concurrent execution example
4446
- [streaming_concurrent_workflow.py](concurrent_examples/streaming_concurrent_workflow.py) - Streaming with concurrency
4547
- [streaming_callback/](concurrent_examples/streaming_callback/) - Streaming callback examples
4648
- [uvloop/](concurrent_examples/uvloop/) - UVLoop integration examples
4749

48-
## Council of Judges
50+
## Council
4951
- [council_judge_evaluation.py](council/council_judge_evaluation.py) - Judge evaluation system
5052
- [council_judge_example.py](council/council_judge_example.py) - Basic council example
5153
- [council_of_judges_eval.py](council/council_of_judges_eval.py) - Evaluation framework
54+
55+
## Council of Judges
56+
- [council_judge_example.py](council_of_judges/council_judge_example.py) - Basic council of judges
5257
- [council_judge_complex_example.py](council_of_judges/council_judge_complex_example.py) - Complex council setup
5358
- [council_judge_custom_example.py](council_of_judges/council_judge_custom_example.py) - Custom council configuration
5459

@@ -122,8 +127,7 @@ This directory contains comprehensive examples demonstrating various multi-agent
122127
- [moa_examples/](moa_examples/) - Multi-objective agent examples
123128

124129
## Spreadsheet Examples
125-
- [new_spreadsheet_new_examples/](new_spreadsheet_new_examples/) - Latest spreadsheet integrations
126-
- [new_spreadsheet_swarm_examples/](new_spreadsheet_swarm_examples/) - Spreadsheet swarm examples
130+
- [spreadsheet_examples/](spreadsheet_examples/) - Spreadsheet-based agent examples and swarm usage
127131

128132
## Orchestration
129133
- [orchestration_examples/](orchestration_examples/) - Workflow orchestration patterns

examples/single_agent/README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ This directory contains examples demonstrating single agent patterns, configurat
3333
### DeepSeek
3434
- [deepseek_r1.py](llms/deepseek_examples/deepseek_r1.py) - DeepSeek R1 model
3535
- [fast_r1_groq.py](llms/deepseek_examples/fast_r1_groq.py) - Fast R1 with Groq
36-
- [grok_deepseek_agent.py](llms/deepseek_examples/grok_deepseek_agent.py) - Grok DeepSeek integration
36+
- [groq_deepseek_agent.py](llms/deepseek_examples/groq_deepseek_agent.py) - Groq DeepSeek integration
3737

3838
### Mistral
3939
- [mistral_example.py](llms/mistral_example.py) - Mistral model integration
@@ -43,6 +43,9 @@ This directory contains examples demonstrating single agent patterns, configurat
4343
- [reasoning_duo_batched.py](llms/openai_examples/reasoning_duo_batched.py) - Batched reasoning with OpenAI
4444
- [test_async_litellm.py](llms/openai_examples/test_async_litellm.py) - Async LiteLLM testing
4545

46+
### O3
47+
- [o3_agent.py](llms/o3_agent.py) - O3 model integration
48+
4649
### Qwen
4750
- [qwen_3_base.py](llms/qwen_3_base.py) - Qwen 3 base model
4851

@@ -117,8 +120,15 @@ This directory contains examples demonstrating single agent patterns, configurat
117120
- [handoffs_example.py](utils/handoffs_example.py) - Agent handoff examples
118121
- [list_agent_output_types.py](utils/list_agent_output_types.py) - Output type listing
119122
- [markdown_agent.py](utils/markdown_agent.py) - Markdown processing agent
123+
- [medical_agent_add_to_marketplace.py](utils/medical_agent_add_to_marketplace.py) - Add medical agent to marketplace
120124
- [xml_output_example.py](utils/xml_output_example.py) - XML output example
121125

126+
### Autosaving
127+
- [autosave_basic_example.py](utils/autosaving_examples/autosave_basic_example.py) - Basic autosave
128+
- [autosave_config_access_example.py](utils/autosaving_examples/autosave_config_access_example.py) - Config access
129+
- [autosave_directory_structure_example.py](utils/autosaving_examples/autosave_directory_structure_example.py) - Directory structure
130+
- [autosave_recovery_example.py](utils/autosaving_examples/autosave_recovery_example.py) - Recovery example
131+
122132
### Transform Prompts
123133
- [transforms_agent_example.py](utils/transform_prompts/transforms_agent_example.py) - Prompt transformation agent
124134
- [transforms_examples.py](utils/transform_prompts/transforms_examples.py) - Prompt transformation examples

examples/voice_agents/README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Voice Agents Examples
2+
3+
This directory contains examples for building speech-enabled agents with the Swarms framework using the `voice-agents` package for streaming text-to-speech (TTS) and speech-to-text (STT) capabilities.
4+
5+
## Requirements
6+
7+
- Install the [voice-agents](https://pypi.org/project/voice-agents/) package: `pip install voice-agents`
8+
- OpenAI API key (for TTS/STT when using OpenAI models)
9+
10+
## Examples
11+
12+
| Example | Description |
13+
|---------|-------------|
14+
| [agent_speech.py](agent_speech.py) | Basic agent with speech output capabilities |
15+
| [agent_with_speech.py](agent_with_speech.py) | Speech-enabled agent with streaming TTS callback |
16+
| [debate_with_speech.py](debate_with_speech.py) | Multi-agent debate with voice output for each agent |
17+
| [google_calendar_agent.py](google_calendar_agent.py) | Voice agent integrated with Google Calendar |
18+
| [hiearchical_speech_swarm.py](hiearchical_speech_swarm.py) | Hierarchical swarm where each role has a distinct voice |
19+
| [run_auto_agent_with_speech.py](run_auto_agent_with_speech.py) | Autonomous agent with terminal (bash) access and streaming TTS |
20+
21+
## Usage
22+
23+
Use `StreamingTTSCallback` from the `voice_agents` package with any Swarms agent's `streaming_callback` parameter. You can choose voices such as `alloy`, `echo`, `fable`, `onyx`, `nova`, or `shimmer`.
24+
25+
```python
26+
from swarms import Agent
27+
from voice_agents import StreamingTTSCallback
28+
29+
agent = Agent(model_name="anthropic/claude-sonnet-4-5", ...)
30+
tts_callback = StreamingTTSCallback(voice="alloy", model="tts-1")
31+
result = agent.run(task="Hello!", streaming_callback=tts_callback)
32+
tts_callback.flush()
33+
```
34+
35+
## Related
36+
37+
- [Single agent speech](https://docs.swarms.world/en/latest/swarms/examples/single_agent_speech/) documentation
38+
- [Hierarchical speech swarm](https://docs.swarms.world/en/latest/swarms/examples/hierarchical_speech_swarm/) documentation
39+
- [guides/changelog_890/](../guides/changelog_890/) and [guides/880_update_changelog_examples/](../guides/880_update_changelog_examples/) for more voice examples
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
"""Autonomous agent with terminal access and streaming TTS. Requires: pip install voice-agents"""
2+
3+
from swarms import Agent
4+
from voice_agents import StreamingTTSCallback
5+
6+
# Agent with autonomous looping and terminal (bash) access
7+
agent = Agent(
8+
agent_name="Terminal-Agent",
9+
agent_description="Agent that can plan tasks and run bash commands on the terminal",
10+
model_name="anthropic/claude-sonnet-4-5",
11+
dynamic_temperature_enabled=True,
12+
max_loops="auto",
13+
dynamic_context_window=True,
14+
selected_tools="all",
15+
top_p=None,
16+
)
17+
18+
# Create the streaming TTS callback
19+
# voice: alloy, echo, fable, onyx, nova, shimmer
20+
tts_callback = StreamingTTSCallback(voice="alloy", model="tts-1")
21+
22+
23+
if __name__ == "__main__":
24+
result = agent.run(
25+
task="Use the terminal to list the current directory, and see what files are in it.",
26+
streaming_callback=tts_callback,
27+
)
28+
29+
# Flush any remaining text in the buffer to ensure the last sentence is spoken
30+
tts_callback.flush()
31+
32+
print(result)

pyproject.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ build-backend = "poetry.core.masonry.api"
55

66
[tool.poetry]
77
name = "swarms"
8-
version = "8.9.1"
8+
version = "9.0.0"
99
description = "Swarms - TGSC"
1010
license = "MIT"
1111
authors = ["Kye Gomez <kye@swarms.world>"]
@@ -99,7 +99,6 @@ pytest = ">=8.1.1,<10.0.0"
9999
black = "*"
100100
ruff = "*"
101101
pytest = "*"
102-
# pre-commit = "*"
103102

104103
[tool.ruff]
105104
line-length = 70

0 commit comments

Comments
 (0)