Skip to content

Conversation

@harshalmore31
Copy link
Contributor

@harshalmore31 harshalmore31 commented Feb 7, 2025

This pull request introduces significant enhancements to the swarms module 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:

New Schemas for Agent and Swarm Configuration:

  • swarms/schemas/base_swarm_schemas.py: Introduced AgentInputConfig class for agent configuration and BaseSwarmSchema class for swarm configuration with detailed validation methods.

Unified Output Schema:

  • swarms/schemas/output_schemas.py: Added Step, AgentTaskOutput, and OutputSchema classes for representing and formatting the output of agent tasks and swarm executions.

These changes collectively enhance the functionality and robustness of the swarms module, enabling more detailed tracking and configuration of agents and swarms.


📚 Documentation preview 📚: https://swarms--770.org.readthedocs.build/en/770/

Comment on lines +118 to +122
return cls(
prompt_tokens=prompt_tokens,
completion_tokens=completion_tokens,
total_tokens=prompt_tokens + completion_tokens
)

Check failure

Code scanning / Pyre

Unexpected keyword Error

Unexpected keyword [28]: Unexpected keyword argument prompt_tokens to call object.__init__.
@@ -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

Undefined import [21]: Could not find a module corresponding to import pydantic.
import uuid
import time

class AgentInputConfig(BaseModel):

Check failure

Code scanning / Pyre

Undefined or invalid type Error

Undefined or invalid type [11]: Annotation BaseModel is not defined as a type.
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

Uninitialized attribute [13]: Attribute name is declared in class BaseSwarmSchema to have type str but is never initialized.
"""
id: str = Field(default_factory=lambda: str(uuid.uuid4()))
name: str
description: str

Check failure

Code scanning / Pyre

Uninitialized attribute Error

Uninitialized attribute [13]: Attribute description is declared in class BaseSwarmSchema to have type str but is never initialized.
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

Uninitialized attribute [13]: Attribute swarm_type is declared in class BaseSwarmSchema to have type str but is never initialized.
@@ -0,0 +1,90 @@
from typing import Any, Dict, List, Optional
from pydantic import BaseModel, Field

Check failure

Code scanning / Pyre

Undefined import Error

Undefined import [21]: Could not find a module corresponding to import pydantic.
import uuid
from swarms.utils.litellm_tokenizer import count_tokens

class Step(BaseModel):

Check failure

Code scanning / Pyre

Undefined or invalid type Error

Undefined or invalid type [11]: Annotation BaseModel is not defined as a type.
Comment on lines +83 to +89
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

Unexpected keyword [28]: Unexpected keyword argument swarm_id to call object.__init__.
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

Undefined attribute [16]: OutputSchema has no attribute model_dump_json.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant