-
-
Notifications
You must be signed in to change notification settings - Fork 674
Enhanced Configuration, Token Counting and Unified Output Formatting Schema for swarms Module #770
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
| return cls( | ||
| prompt_tokens=prompt_tokens, | ||
| completion_tokens=completion_tokens, | ||
| total_tokens=prompt_tokens + completion_tokens | ||
| ) |
Check failure
Code scanning / Pyre
Unexpected keyword Error
| @@ -0,0 +1,152 @@ | |||
| from typing import Any, Dict, List, Optional, Union | |||
| from pydantic import BaseModel, Field, validator | |||
Check failure
Code scanning / Pyre
Undefined import Error
| import uuid | ||
| import time | ||
|
|
||
| class AgentInputConfig(BaseModel): |
Check failure
Code scanning / Pyre
Undefined or invalid type Error
| Base schema for all swarm types. | ||
| """ | ||
| id: str = Field(default_factory=lambda: str(uuid.uuid4())) | ||
| name: str |
Check failure
Code scanning / Pyre
Uninitialized attribute Error
| """ | ||
| id: str = Field(default_factory=lambda: str(uuid.uuid4())) | ||
| name: str | ||
| description: str |
Check failure
Code scanning / Pyre
Uninitialized attribute Error
| description: str | ||
| agents: List[AgentInputConfig] # Using AgentInputConfig | ||
| max_loops: int = 1 | ||
| swarm_type: str # e.g., "SequentialWorkflow", "ConcurrentWorkflow", etc. |
Check failure
Code scanning / Pyre
Uninitialized attribute Error
| @@ -0,0 +1,90 @@ | |||
| from typing import Any, Dict, List, Optional | |||
| from pydantic import BaseModel, Field | |||
Check failure
Code scanning / Pyre
Undefined import Error
| import uuid | ||
| from swarms.utils.litellm_tokenizer import count_tokens | ||
|
|
||
| class Step(BaseModel): |
Check failure
Code scanning / Pyre
Undefined or invalid type Error
| output = OutputSchema( | ||
| swarm_id=swarm_id, | ||
| swarm_type=swarm_type, | ||
| task=task, | ||
| agent_outputs=agent_outputs, | ||
| swarm_specific_output=swarm_specific_output, | ||
| ) |
Check failure
Code scanning / Pyre
Unexpected keyword Error
| agent_outputs=agent_outputs, | ||
| swarm_specific_output=swarm_specific_output, | ||
| ) | ||
| return output.model_dump_json(indent=4) No newline at end of file |
Check failure
Code scanning / Pyre
Undefined attribute Error
This pull request introduces significant enhancements to the
swarmsmodule by adding new classes and methods for better handling of token counting, agent configuration, and output formatting. The most important changes include the addition of token counting capabilities, the introduction of new schemas for agent input and swarm configuration, and the creation of a unified output schema.Token Counting Enhancements:
swarms/schemas/base_schemas.py: Addedcount_tokensmethod toChatMessageInputclass to count tokens in message content.swarms/schemas/base_schemas.py: Addedcalculate_usageclass method toUsageInfoclass to calculate token usage for messages and completion.New Schemas for Agent and Swarm Configuration:
swarms/schemas/base_swarm_schemas.py: IntroducedAgentInputConfigclass for agent configuration andBaseSwarmSchemaclass for swarm configuration with detailed validation methods.Unified Output Schema:
swarms/schemas/output_schemas.py: AddedStep,AgentTaskOutput, andOutputSchemaclasses for representing and formatting the output of agent tasks and swarm executions.These changes collectively enhance the functionality and robustness of the
swarmsmodule, enabling more detailed tracking and configuration of agents and swarms.📚 Documentation preview 📚: https://swarms--770.org.readthedocs.build/en/770/