View Source Agens.Tool behaviour (agens v0.1.2)

The Tool behaviour.

A Tool is a module that implements the Agens.Tool behaviour. It is used to define the functionality of a tool that can be used by an Agens.Agent.

A Tool defines the following callbacks:

  • pre/1 - pre-processes the input from the previous step before it is added to the LM prompt.
  • instructions/0 - returns the tool-specific instructions for the LM.
  • to_args/1 - parses the LM result into arguments to be used by execute/1.
  • execute/1 - executes the tool with the given arguments.
  • post/1 - handles the various outputs of execute/1, whether a map or error tuple, and returns a string for the next Step of the Job.

Summary

Callbacks

Execute the tool with the given arguments. LM is responsible for generating arguments for the Tool based on Tool instructions, input from previous Step, Agent config and any additional context.

Instructions for the LM, combined with the input from previous Step (and optionally pre-processed using pre/1) as well as the prompt from the Agent config.

Handles the various outputs of execute/1, whether a map or error tuple, and returns a string for the next Step of the Job.

Pre-process the input from previous Step before it is added to the LM prompt.

Parse the LM result into arguments to be used by execute/1.

Callbacks

@callback execute(args :: keyword()) :: map() | {:error, atom()}

Execute the tool with the given arguments. LM is responsible for generating arguments for the Tool based on Tool instructions, input from previous Step, Agent config and any additional context.

@callback instructions() :: String.t()

Instructions for the LM, combined with the input from previous Step (and optionally pre-processed using pre/1) as well as the prompt from the Agent config.

@callback post(map() | {:error, atom()}) :: String.t()

Handles the various outputs of execute/1, whether a map or error tuple, and returns a string for the next Step of the Job.

@callback pre(input :: String.t()) :: String.t()

Pre-process the input from previous Step before it is added to the LM prompt.

@callback to_args(result :: binary()) :: keyword()

Parse the LM result into arguments to be used by execute/1.