Overview
AgentMarketplaceHandler owns both directions of Swarms Marketplace integration: resolving a prompt UUID into an agent’s system prompt, and publishing an agent’s prompt with its metadata.
Every Agent builds one as agent.marketplace. The class also works with no agent at all — fetching and publishing are classmethods, so you can use it as a standalone marketplace client.
Import
Authentication
Both directions requireSWARMS_API_KEY. Get one at swarms.world/platform/api-keys.
check_api_key
ValueError when it is unset, empty, or whitespace-only.
The key is read fresh on every call — not cached. A key exported after import, or rotated mid-process, is picked up immediately.
Fetching
fetch
GET https://swarms.world/api/get-prompts/<uuid-or-url-encoded-name>
str
The prompt’s UUID. Takes precedence over
name when both are given.str
The prompt’s name, URL-encoded automatically.
float
default:"30.0"
Request timeout in seconds.
bool
default:"true"
True returns a (name, description, prompt) tuple; False returns the full JSON response.None when the prompt does not exist (404). Raises ValueError when neither argument is given, and httpx.HTTPStatusError for any other error status.
fetch_prompt
fetch, but requires the prompt to exist — raises ValueError with a helpful message on 404.
load_prompt
- appends the prompt body to
agent.system_prompt - sets
agent_name/nameonly if the agent is still at the defaultswarm-worker-01 - sets
agent_description/descriptiononly if it isNone
marketplace_prompt_id.
Agent.__init__ gives agent_description a generic default string rather than None, so the description back-fill only fires when you explicitly pass agent_description=None.Publishing
publish
AgentInitializationError when use_cases was not provided.
build_tags
tags and capabilities into one comma-separated string. Either list may be empty or unset; only what exists is included, and neither returns "".
add_prompt
POST https://swarms.world/api/add-prompt — the low-level publish, usable without an agent.
str
required
Prompt name.
str
required
The prompt text.
str
required
What the prompt does.
List[Dict[str, str]]
required
Dicts with
title and description keys. Sent to the API as useCases.str
Comma-separated tags.
None becomes "".bool
default:"true"
Whether the prompt is free.
float
default:"0.0"
Price, ignored when
is_free.ValueError naming that field.
Agent integration
Standalone use
Migration
This class absorbed two modules that have been removed:Related
Marketplace
Marketplace integration guide
Agent
The class that owns the handler