Skip to content

Tool bundle configuration

sweagent.tools.commands.Command pydantic-model

Bases: BaseModel

Represents an executable command with arguments and documentation.

A command can be either a simple bash command or a multi-line command terminated by an end marker.

Attributes:

Name Type Description
name str

The command name

docstring str | None

Human readable description of what the command does

signature str | None

Optional custom signature override

end_name str | None

For multi-line commands, the terminating marker

arguments list[Argument]

List of arguments accepted by the command

Properties

invoke_format: Format string for constructing the full command invocation

Fields:

Validators:

arguments pydantic-field

arguments: list[Argument] = []

docstring pydantic-field

docstring: str | None

end_name pydantic-field

end_name: str | None = None

invoke_format pydantic-field

invoke_format: str

Gets the format string for invoking this command with arguments.

Returns either the custom signature with argument placeholders replaced, or a default format of "command arg1 arg2 ...".

name pydantic-field

name: str

signature pydantic-field

signature: str | None = None

get_function_calling_tool

get_function_calling_tool() -> dict

Converts this command into an OpenAI function calling tool definition.

Returns:

Type Description
dict

Dict containing the OpenAI function schema for this command

Source code in sweagent/tools/commands.py
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
def get_function_calling_tool(self) -> dict:
    """Converts this command into an OpenAI function calling tool definition.

    Returns:
        Dict containing the OpenAI function schema for this command
    """
    tool = {
        "type": "function",
        "function": {
            "name": self.name,
            "description": self.docstring or "",
        },
    }
    properties = {}
    required = []
    if self.arguments:
        for arg in self.arguments:
            properties[arg.name] = {"type": arg.type, "description": arg.description}

            if arg.items:
                properties[arg.name]["items"] = arg.items

            if arg.required:
                required.append(arg.name)

            # Handle enum if present
            if arg.enum:
                properties[arg.name]["enum"] = arg.enum
    tool["function"]["parameters"] = {"type": "object", "properties": properties, "required": required}
    return tool

validate_arguments pydantic-validator

validate_arguments() -> Command

Validates command argument configuration.

Checks: - Required arguments come before optional ones - Argument names are unique - Argument names match the pattern - Arguments match the signature

Returns:

Type Description
Command

The validated Command instance

Raises:

Type Description
ValueError

If validation fails

Source code in sweagent/tools/commands.py
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
@model_validator(mode="after")
def validate_arguments(self) -> Command:
    """Validates command argument configuration.

    Checks:
    - Required arguments come before optional ones
    - Argument names are unique
    - Argument names match the pattern
    - Arguments match the signature

    Returns:
        The validated Command instance

    Raises:
        ValueError: If validation fails
    """
    if not self.arguments:
        return self
    found_optional = False
    for arg in self.arguments:
        if found_optional and arg.required:
            msg = f"Command '{self.name}': Required argument '{arg.name}' cannot come after optional arguments"
            raise ValueError(msg)
        if not arg.required:
            found_optional = True
    duplicates = {arg.name for arg in self.arguments if self.arguments.count(arg) > 1}
    if duplicates:
        msg = f"Command '{self.name}': Duplicate argument names: {duplicates}"
        raise ValueError(msg)
    for arg in self.arguments:
        if not re.match(ARGUMENT_NAME_PATTERN, arg.name):
            msg = f"Command '{self.name}': Invalid argument name: '{arg.name}'"
            raise ValueError(msg)
    if _extract_keys(self.invoke_format) != {arg.name for arg in self.arguments}:
        msg = f"Command '{self.name}': Argument names in signature / invoke_format do not match argument names"
        raise ValueError(msg)
    return self

sweagent.tools.commands.Argument pydantic-model

Bases: BaseModel

Fields:

Validators:

argument_format pydantic-field

argument_format: str = '{{value}}'

How to invoke the argument in the command. Make sure to use jinja syntax ({{value}}) instead of {value}).

description pydantic-field

description: str

enum pydantic-field

enum: list[str] | None = None

items pydantic-field

items: dict[str, str] | None = None

name pydantic-field

name: str

required pydantic-field

required: bool

type pydantic-field

type: str

validate_argument_format pydantic-validator

validate_argument_format(value: str) -> str
Source code in sweagent/tools/commands.py
72
73
74
75
@field_validator("argument_format")
def validate_argument_format(cls, value: str) -> str:
    _warn_probably_wrong_jinja_syntax(value)
    return value