Skip to main content

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 require SWARMS_API_KEY. Get one at swarms.world/platform/api-keys.

check_api_key

Return the key from the environment, raising 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.
Returns 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

Like fetch, but requires the prompt to exist — raises ValueError with a helpful message on 404.

load_prompt

Fetch a prompt and fold it into the owning agent:
  • appends the prompt body to agent.system_prompt
  • sets agent_name / name only if the agent is still at the default swarm-worker-01
  • sets agent_description / description only if it is None
Defaults to the agent’s configured 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

Publish the owning agent’s prompt and metadata. Raises AgentInitializationError when use_cases was not provided.

build_tags

Merge the agent’s 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.
Each missing required field raises ValueError naming that field.

Agent integration

Standalone use

Migration

This class absorbed two modules that have been removed:

Marketplace

Marketplace integration guide

Agent

The class that owns the handler