Skip to content

trading_agent.tools.skill_patch_tool

The skill_patch tool: corrects one of the desk's own skills.

Typical usage example:

tool = SkillPatchTool(writer)

SkillPatchArguments

Bases: BaseModel

The arguments of skill_patch.

Attributes:

Name Type Description
name str

The skill to change, which must be one of your own.

old_text str

The exact text to replace, copied from the skill; it must appear once.

new_text str

The replacement.

reason str

What was wrong, for the skill ledger.

SkillPatchTool

SkillPatchTool(writer)

Bases: Tool

Replaces text in one of the desk's own skills.

Creates the tool.

Parameters:

Name Type Description Default
writer SkillWriter

Writes the desk's skills.

required
Source code in src/trading_agent/tools/skill_patch_tool.py
def __init__(self, writer: skill_writer_module.SkillWriter):
    """Creates the tool.

    Args:
        writer (skill_writer_module.SkillWriter): Writes the desk's skills.
    """
    self._writer = writer

run async

run(arguments)

Makes the replacement in a worker thread.

Parameters:

Name Type Description Default
arguments SkillPatchArguments

The skill and the replacement.

required

Returns:

Type Description
ToolResult

A confirmation, or why nothing changed.

Source code in src/trading_agent/tools/skill_patch_tool.py
async def run(self, arguments: SkillPatchArguments) -> tool.ToolResult:
    """Makes the replacement in a worker thread.

    Args:
        arguments (SkillPatchArguments): The skill and the replacement.

    Returns:
        tool.ToolResult: A confirmation, or why nothing changed.
    """
    try:
        await asyncio.to_thread(
            self._writer.patch,
            arguments.name,
            arguments.old_text,
            arguments.new_text,
            arguments.reason,
        )
    except skill_writer_module.SkillWriteError as error:
        return tool.ToolResult.error(str(error))
    return tool.ToolResult.success(f'Patched skill {arguments.name}.')