swarms 7.7.9__py3-none-any.whl → 7.8.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,40 @@
1
+ from typing import Callable
2
+ from swarms.schemas.agent_class_schema import AgentConfiguration
3
+ from swarms.tools.create_agent_tool import create_agent_tool
4
+ from swarms.prompts.agent_self_builder_prompt import (
5
+ generate_agent_system_prompt,
6
+ )
7
+ from swarms.tools.base_tool import BaseTool
8
+ from swarms.structs.agent import Agent
9
+ import json
10
+
11
+
12
+ def self_agent_builder(
13
+ task: str,
14
+ ) -> Callable:
15
+ schema = BaseTool().base_model_to_dict(AgentConfiguration)
16
+ schema = [schema]
17
+
18
+ print(json.dumps(schema, indent=4))
19
+
20
+ prompt = generate_agent_system_prompt(task)
21
+
22
+ agent = Agent(
23
+ agent_name="Agent-Builder",
24
+ agent_description="Autonomous agent builder",
25
+ system_prompt=prompt,
26
+ tools_list_dictionary=schema,
27
+ output_type="final",
28
+ max_loops=1,
29
+ model_name="gpt-4o-mini",
30
+ )
31
+
32
+ agent_configuration = agent.run(
33
+ f"Create the agent configuration for the task: {task}"
34
+ )
35
+ print(agent_configuration)
36
+ print(type(agent_configuration))
37
+
38
+ build_new_agent = create_agent_tool(agent_configuration)
39
+
40
+ return build_new_agent
@@ -0,0 +1,103 @@
1
+ def generate_agent_system_prompt(task: str) -> str:
2
+ """
3
+ Returns an extremely detailed and production-level system prompt that guides an LLM
4
+ in generating a complete AgentConfiguration schema based on the input task.
5
+
6
+ This prompt is structured to elicit rigorous architectural decisions, precise language,
7
+ and well-justified parameter values. It reflects best practices in AI agent design.
8
+ """
9
+ return f"""
10
+ You are a deeply capable, autonomous agent architect tasked with generating a production-ready agent configuration. Your objective is to fully instantiate the `AgentConfiguration` schema for a highly specialized, purpose-driven AI agent tailored to the task outlined below.
11
+
12
+ --- TASK CONTEXT ---
13
+ You are to design an intelligent, self-sufficient agent whose behavior, cognitive capabilities, safety parameters, and operational bounds are entirely derived from the following user-provided task description:
14
+
15
+ **Task:** "{task}"
16
+
17
+ --- ROLE AND OBJECTIVE ---
18
+ You are not just a responder — you are an autonomous **system designer**, **architect**, and **strategist** responsible for building intelligent agents that will be deployed in real-world applications. Your responsibility includes choosing the most optimal behaviors, cognitive limits, resource settings, and safety thresholds to match the task requirements with precision and foresight.
19
+
20
+ You must instantiate **all fields** of the `AgentConfiguration` schema, as defined below. These configurations will be used directly by AI systems without human review — therefore, accuracy, reliability, and safety are paramount.
21
+
22
+ --- DESIGN PRINCIPLES ---
23
+ Follow these core principles in your agent design:
24
+ 1. **Fitness for Purpose**: Tailor all parameters to optimize performance for the provided task. Understand the underlying problem domain deeply before configuring.
25
+ 2. **Explainability**: The `agent_description` and `system_prompt` should clearly articulate what the agent does, how it behaves, and its guiding heuristics or ethics.
26
+ 3. **Safety and Control**: Err on the side of caution. Enable guardrails unless you have clear justification to disable them.
27
+ 4. **Modularity**: Your design should allow for adaptation and scaling. Prefer clear constraints over rigidly hard-coded behaviors.
28
+ 5. **Dynamic Reasoning**: Allow adaptive behaviors only when warranted by the task complexity.
29
+ 6. **Balance Creativity and Determinism**: Tune `temperature` and `top_p` appropriately. Analytical tasks should be conservative; generative or design tasks may tolerate more creative freedom.
30
+
31
+ --- FIELD-BY-FIELD DESIGN GUIDE ---
32
+
33
+ • **agent_name (str)**
34
+ - Provide a short, expressive, and meaningful name.
35
+ - It should reflect domain expertise and purpose, e.g., `"ContractAnalyzerAI"`, `"BioNLPResearcher"`, `"CreativeUXWriter"`.
36
+
37
+ • **agent_description (str)**
38
+ - Write a long, technically rich description.
39
+ - Include the agent’s purpose, operational style, areas of knowledge, and example outputs or use cases.
40
+ - Clarify what *not* to expect as well.
41
+
42
+ • **system_prompt (str)**
43
+ - This is the most critical component.
44
+ - Write a 5–15 sentence instructional guide that defines the agent’s tone, behavioral principles, scope of authority, and personality.
45
+ - Include both positive (what to do) and negative (what to avoid) behavioral constraints.
46
+ - Use role alignment (“You are an expert...”) and inject grounding in real-world context or professional best practices.
47
+
48
+ • **max_loops (int)**
49
+ - Choose a number of reasoning iterations. Use higher values (6–10) for exploratory, multi-hop, or inferential tasks.
50
+ - Keep it at 1–2 for simple retrieval or summarization tasks.
51
+
52
+ • **dynamic_temperature_enabled (bool)**
53
+ - Enable this for agents that must shift modes between creative and factual sub-tasks.
54
+ - Disable for deterministic, verifiable reasoning chains (e.g., compliance auditing, code validation).
55
+
56
+ • **model_name (str)**
57
+ - Choose the most appropriate model family: `"gpt-4"`, `"gpt-4-turbo"`, `"gpt-3.5-turbo"`, etc.
58
+ - Use lightweight models only if latency, cost, or compute efficiency is a hard constraint.
59
+
60
+ • **safety_prompt_on (bool)**
61
+ - Always `True` unless the agent is for internal, sandboxed research.
62
+ - This ensures harmful, biased, or otherwise inappropriate outputs are blocked or filtered.
63
+
64
+ • **temperature (float)**
65
+ - For factual, analytical, or legal tasks: `0.2–0.5`
66
+ - For content generation or creative exploration: `0.6–0.9`
67
+ - Avoid values >1.0. They reduce coherence.
68
+
69
+ • **max_tokens (int)**
70
+ - Reflect the expected size of the output per call.
71
+ - Use 500–1500 for concise tools, 3000–5000 for exploratory or report-generating agents.
72
+ - Never exceed the model limit (e.g., 8192 for GPT-4 Turbo).
73
+
74
+ • **context_length (int)**
75
+ - Set based on how much previous conversation or document context the agent needs to retain.
76
+ - Typical range: 6000–16000 tokens. Use lower bounds to optimize performance if context retention isn't crucial.
77
+
78
+ --- EXAMPLES OF STRONG SYSTEM PROMPTS ---
79
+
80
+ Bad example:
81
+ > "You are a helpful assistant that provides answers about contracts."
82
+
83
+ ✅ Good example:
84
+ > "You are a professional legal analyst specializing in international corporate law. Your role is to evaluate contracts for risks, ambiguous clauses, and compliance issues. You speak in precise legal terminology and justify every assessment using applicable legal frameworks. Avoid casual language. Always flag high-risk clauses and suggest improvements based on best practices."
85
+
86
+ --- FINAL OUTPUT FORMAT ---
87
+
88
+ Output **only** the JSON object corresponding to the `AgentConfiguration` schema:
89
+
90
+ ```json
91
+ {{
92
+ "agent_name": "...",
93
+ "agent_description": "...",
94
+ "system_prompt": "...",
95
+ "max_loops": ...,
96
+ "dynamic_temperature_enabled": ...,
97
+ "model_name": "...",
98
+ "safety_prompt_on": ...,
99
+ "temperature": ...,
100
+ "max_tokens": ...,
101
+ "context_length": ...
102
+ }}
103
+ """
@@ -1,7 +1,12 @@
1
1
  from swarms.schemas.agent_step_schemas import Step, ManySteps
2
-
2
+ from swarms.schemas.mcp_schemas import (
3
+ MCPConnection,
4
+ MultipleMCPConnections,
5
+ )
3
6
 
4
7
  __all__ = [
5
8
  "Step",
6
9
  "ManySteps",
10
+ "MCPConnection",
11
+ "MultipleMCPConnections",
7
12
  ]
@@ -0,0 +1,91 @@
1
+ """
2
+ This is a schema that enables the agent to generate it's self.
3
+
4
+
5
+ """
6
+
7
+ from pydantic import BaseModel, Field
8
+ from typing import Optional
9
+
10
+
11
+ class AgentConfiguration(BaseModel):
12
+ """
13
+ Comprehensive configuration schema for autonomous agent creation and management.
14
+
15
+ This Pydantic model defines all the necessary parameters to create, configure,
16
+ and manage an autonomous agent with specific behaviors, capabilities, and constraints.
17
+ It enables dynamic agent generation with customizable properties and allows
18
+ arbitrary additional fields for extensibility.
19
+
20
+ All fields are required with no defaults, forcing explicit configuration of the agent.
21
+ The schema supports arbitrary additional parameters through the extra='allow' configuration.
22
+
23
+ Attributes:
24
+ agent_name: Unique identifier name for the agent
25
+ agent_description: Detailed description of the agent's purpose and capabilities
26
+ system_prompt: Core system prompt that defines the agent's behavior and personality
27
+ max_loops: Maximum number of reasoning loops the agent can perform
28
+ dynamic_temperature_enabled: Whether to enable dynamic temperature adjustment
29
+ model_name: The specific LLM model to use for the agent
30
+ safety_prompt_on: Whether to enable safety prompts and guardrails
31
+ temperature: Controls response randomness and creativity
32
+ max_tokens: Maximum tokens in a single response
33
+ context_length: Maximum conversation context length
34
+ frequency_penalty: Penalty for token frequency to reduce repetition
35
+ presence_penalty: Penalty for token presence to encourage diverse topics
36
+ top_p: Nucleus sampling parameter for token selection
37
+ tools: List of tools/functions available to the agent
38
+ """
39
+
40
+ agent_name: Optional[str] = Field(
41
+ description="Unique and descriptive name for the agent. Should be clear, concise, and indicative of the agent's purpose or domain expertise.",
42
+ )
43
+
44
+ agent_description: Optional[str] = Field(
45
+ description="Comprehensive description of the agent's purpose, capabilities, expertise area, and intended use cases. This helps users understand what the agent can do and when to use it.",
46
+ )
47
+
48
+ system_prompt: Optional[str] = Field(
49
+ description="The core system prompt that defines the agent's personality, behavior, expertise, and response style. This is the foundational instruction that shapes how the agent interacts and processes information.",
50
+ )
51
+
52
+ max_loops: Optional[int] = Field(
53
+ description="Maximum number of reasoning loops or iterations the agent can perform when processing complex tasks. Higher values allow for more thorough analysis but consume more resources.",
54
+ )
55
+
56
+ dynamic_temperature_enabled: Optional[bool] = Field(
57
+ description="Whether to enable dynamic temperature adjustment during conversations. When enabled, the agent can adjust its creativity/randomness based on the task context - lower for factual tasks, higher for creative tasks.",
58
+ )
59
+
60
+ model_name: Optional[str] = Field(
61
+ description="The specific language model to use for this agent. Should be a valid model identifier that corresponds to available LLM models in the system.",
62
+ )
63
+
64
+ safety_prompt_on: Optional[bool] = Field(
65
+ description="Whether to enable safety prompts and content guardrails. When enabled, the agent will have additional safety checks to prevent harmful, biased, or inappropriate responses.",
66
+ )
67
+
68
+ temperature: Optional[float] = Field(
69
+ description="Controls the randomness and creativity of the agent's responses. Lower values (0.0-0.3) for more focused and deterministic responses, higher values (0.7-1.0) for more creative and varied outputs.",
70
+ )
71
+
72
+ max_tokens: Optional[int] = Field(
73
+ description="Maximum number of tokens the agent can generate in a single response. Controls the length and detail of agent outputs.",
74
+ )
75
+
76
+ context_length: Optional[int] = Field(
77
+ description="Maximum context length the agent can maintain in its conversation memory. Affects how much conversation history the agent can reference.",
78
+ )
79
+
80
+ task: Optional[str] = Field(
81
+ description="The task that the agent will perform.",
82
+ )
83
+
84
+ class Config:
85
+ """Pydantic model configuration."""
86
+
87
+ extra = "allow" # Allow arbitrary additional fields
88
+ allow_population_by_field_name = True
89
+ validate_assignment = True
90
+ use_enum_values = True
91
+ arbitrary_types_allowed = True # Allow arbitrary types
@@ -0,0 +1,18 @@
1
+ class AgentMCPError(Exception):
2
+ pass
3
+
4
+
5
+ class AgentMCPConnectionError(AgentMCPError):
6
+ pass
7
+
8
+
9
+ class AgentMCPToolError(AgentMCPError):
10
+ pass
11
+
12
+
13
+ class AgentMCPToolNotFoundError(AgentMCPError):
14
+ pass
15
+
16
+
17
+ class AgentMCPToolInvalidError(AgentMCPError):
18
+ pass
@@ -0,0 +1,13 @@
1
+ from pydantic import BaseModel
2
+ from typing import List, Dict, Any, Optional, Callable
3
+ from swarms.schemas.mcp_schemas import MCPConnection
4
+
5
+
6
+ class AgentToolTypes(BaseModel):
7
+ tool_schema: List[Dict[str, Any]]
8
+ mcp_connection: MCPConnection
9
+ tool_model: Optional[BaseModel]
10
+ tool_functions: Optional[List[Callable]]
11
+
12
+ class Config:
13
+ arbitrary_types_allowed = True
@@ -0,0 +1,92 @@
1
+ from pydantic import BaseModel, Field
2
+ from typing import List, Optional, Union, Any, Literal
3
+ from litellm.types import (
4
+ ChatCompletionPredictionContentParam,
5
+ )
6
+
7
+
8
+ class LLMCompletionRequest(BaseModel):
9
+ """Schema for LLM completion request parameters."""
10
+
11
+ model: Optional[str] = Field(
12
+ default=None,
13
+ description="The name of the language model to use for text completion",
14
+ )
15
+ temperature: Optional[float] = Field(
16
+ default=0.5,
17
+ description="Controls randomness of the output (0.0 to 1.0)",
18
+ )
19
+ top_p: Optional[float] = Field(
20
+ default=None,
21
+ description="Controls diversity via nucleus sampling",
22
+ )
23
+ n: Optional[int] = Field(
24
+ default=None, description="Number of completions to generate"
25
+ )
26
+ stream: Optional[bool] = Field(
27
+ default=None, description="Whether to stream the response"
28
+ )
29
+ stream_options: Optional[dict] = Field(
30
+ default=None, description="Options for streaming response"
31
+ )
32
+ stop: Optional[Any] = Field(
33
+ default=None,
34
+ description="Up to 4 sequences where the API will stop generating",
35
+ )
36
+ max_completion_tokens: Optional[int] = Field(
37
+ default=None,
38
+ description="Maximum tokens for completion including reasoning",
39
+ )
40
+ max_tokens: Optional[int] = Field(
41
+ default=None,
42
+ description="Maximum tokens in generated completion",
43
+ )
44
+ prediction: Optional[ChatCompletionPredictionContentParam] = (
45
+ Field(
46
+ default=None,
47
+ description="Configuration for predicted output",
48
+ )
49
+ )
50
+ presence_penalty: Optional[float] = Field(
51
+ default=None,
52
+ description="Penalizes new tokens based on existence in text",
53
+ )
54
+ frequency_penalty: Optional[float] = Field(
55
+ default=None,
56
+ description="Penalizes new tokens based on frequency in text",
57
+ )
58
+ logit_bias: Optional[dict] = Field(
59
+ default=None,
60
+ description="Modifies probability of specific tokens",
61
+ )
62
+ reasoning_effort: Optional[Literal["low", "medium", "high"]] = (
63
+ Field(
64
+ default=None,
65
+ description="Level of reasoning effort for the model",
66
+ )
67
+ )
68
+ seed: Optional[int] = Field(
69
+ default=None, description="Random seed for reproducibility"
70
+ )
71
+ tools: Optional[List] = Field(
72
+ default=None,
73
+ description="List of tools available to the model",
74
+ )
75
+ tool_choice: Optional[Union[str, dict]] = Field(
76
+ default=None, description="Choice of tool to use"
77
+ )
78
+ logprobs: Optional[bool] = Field(
79
+ default=None,
80
+ description="Whether to return log probabilities",
81
+ )
82
+ top_logprobs: Optional[int] = Field(
83
+ default=None,
84
+ description="Number of most likely tokens to return",
85
+ )
86
+ parallel_tool_calls: Optional[bool] = Field(
87
+ default=None,
88
+ description="Whether to allow parallel tool calls",
89
+ )
90
+
91
+ class Config:
92
+ allow_arbitrary_types = True
@@ -0,0 +1,43 @@
1
+ from pydantic import BaseModel, Field
2
+ from typing import Dict, List, Any, Optional
3
+
4
+
5
+ class MCPConnection(BaseModel):
6
+ type: Optional[str] = Field(
7
+ default="mcp",
8
+ description="The type of connection, defaults to 'mcp'",
9
+ )
10
+ url: Optional[str] = Field(
11
+ default="localhost:8000/sse",
12
+ description="The URL endpoint for the MCP server",
13
+ )
14
+ tool_configurations: Optional[Dict[Any, Any]] = Field(
15
+ default=None,
16
+ description="Dictionary containing configuration settings for MCP tools",
17
+ )
18
+ authorization_token: Optional[str] = Field(
19
+ default=None,
20
+ description="Authentication token for accessing the MCP server",
21
+ )
22
+ transport: Optional[str] = Field(
23
+ default="sse",
24
+ description="The transport protocol to use for the MCP server",
25
+ )
26
+ headers: Optional[Dict[str, str]] = Field(
27
+ default=None, description="Headers to send to the MCP server"
28
+ )
29
+ timeout: Optional[int] = Field(
30
+ default=5, description="Timeout for the MCP server"
31
+ )
32
+
33
+ class Config:
34
+ arbitrary_types_allowed = True
35
+
36
+
37
+ class MultipleMCPConnections(BaseModel):
38
+ connections: List[MCPConnection] = Field(
39
+ default=[], description="List of MCP connections"
40
+ )
41
+
42
+ class Config:
43
+ arbitrary_types_allowed = True
@@ -78,6 +78,8 @@ from swarms.structs.swarming_architectures import (
78
78
  star_swarm,
79
79
  )
80
80
  from swarms.structs.auto_swarm_builder import AutoSwarmBuilder
81
+ from swarms.structs.council_judge import CouncilAsAJudge
82
+ from swarms.structs.batch_agent_execution import batch_agent_execution
81
83
 
82
84
  __all__ = [
83
85
  "Agent",
@@ -146,4 +148,6 @@ __all__ = [
146
148
  "get_agents_info",
147
149
  "get_swarms_info",
148
150
  "AutoSwarmBuilder",
151
+ "CouncilAsAJudge",
152
+ "batch_agent_execution",
149
153
  ]