Skip to content

trading_agent.tools.add_note_tool

The add_note tool: records one to three short lessons in the desk's notes for today.

Notes go to notes/YYYY-MM-DD.md in the desk folder, one bullet per note with the India time. When a session ends, the desk folds the day's notes into Memory.md. The notes file is snapshotted before every change, so a note can be undone.

Typical usage example:

tool = AddNoteTool(notes_directory, checkpoints)

AddNoteArguments

Bases: BaseModel

The arguments of add_note.

Attributes:

Name Type Description
notes list[str]

One to three short notes, each a single lesson.

AddNoteTool

AddNoteTool(notes_directory, checkpoints, clock=None)

Bases: Tool

Appends notes to today's notes file.

Creates the tool.

Parameters:

Name Type Description Default
notes_directory Path

The desk's notes folder.

required
checkpoints Checkpoints | None

Snapshots the desk's files before the note is written, or None to take none.

required
clock Callable[[], datetime] | None

Returns the current India time; None uses the system clock. Tests replace it.

None
Source code in src/trading_agent/tools/add_note_tool.py
def __init__(
    self,
    notes_directory: Path,
    checkpoints: checkpoints_module.Checkpoints | None,
    clock: Callable[[], datetime.datetime] | None = None,
):
    """Creates the tool.

    Args:
        notes_directory (Path): The desk's notes folder.
        checkpoints (checkpoints_module.Checkpoints | None): Snapshots the desk's files before the note is written, or None to take none.
        clock (Callable[[], datetime.datetime] | None): Returns the current India time; None uses the system clock. Tests replace it.
    """
    self._notes_directory = notes_directory
    self._checkpoints = checkpoints
    self._clock = clock

run async

run(arguments)

Appends the notes, starting today's file when needed.

Parameters:

Name Type Description Default
arguments AddNoteArguments

The notes.

required

Returns:

Type Description
ToolResult

Where the notes went.

Source code in src/trading_agent/tools/add_note_tool.py
async def run(self, arguments: AddNoteArguments) -> tool.ToolResult:
    """Appends the notes, starting today's file when needed.

    Args:
        arguments (AddNoteArguments): The notes.

    Returns:
        tool.ToolResult: Where the notes went.
    """
    now = self._now()
    path = self._notes_directory / f'{now.date().isoformat()}.md'
    if self._checkpoints is not None:
        try:
            await asyncio.to_thread(
                self._checkpoints.snapshot,
                f'before add_note notes/{path.name}',
            )
        except checkpoints_module.CheckpointError:
            _LOGGER.exception('Could not snapshot before add_note')
    lines = []
    if not path.exists():
        lines.append(f'# Notes for {now.date().isoformat()}')
        lines.append('')
    for note in arguments.notes:
        lines.append(f'- {now:%H:%M} {note}')
    path.parent.mkdir(parents=True, exist_ok=True)
    with path.open('a', encoding='utf-8') as notes_file:
        notes_file.write('\n'.join(lines) + '\n')
    return tool.ToolResult.success(
        f'Added {len(arguments.notes)} note(s) to notes/{path.name}.'
    )