Action

What are Actions?

Actions form the critical bridge between an agent’s internal decision-making processes and the external world. They allow the system to effect change, adapt to varying circumstances, and achieve specific objectives by responding to observed conditions. This interplay between action selection and environmental feedback is fundamental in developing adaptive, intelligent systems capable of learning from experience and improving their performance over time.

Actions are currently interchangeable with the concept of tools. However, there are plans to expand the concept of actions beyond tools.

Using Actions

There are 2 main ways to use actions:

  1. Directly through the agent - actions are linked to a specific agent

  2. Standalone - actions can be reused by multiple agents.

Agent-Based Actions

You can define agent-based actions using the SwiftAgent.action decorator on a function. Different example cases are shown below.

python
@agent.action(description="action to get weather")
async def get_weather(location: str, unit: str = "celsius"):
    return f"The weather in {location} is sunny and 22°{unit[0].upper()}"

Standalone Actions

Standalone actions are defined by the agent decorator, in the exact same way as agent-based actions are defined. The only additional step is that you need to call SwiftAgent.add_action on the standalone action to add it to an agent.

For example,

python
from swiftagent.actions import action

# define action
@action()
async def get_weather(location: str, unit: str = "celsius"):
    """
    action to get weather
    """
    return f"The weather in {location} is sunny and 22°{unit[0].upper()}"
    
# add action
agent.add_action(get_weather)

Action Attributes

Attribute
Parameter
Type
Description

Name

name

Optional[str]

Name of the action. Defaults to the name of the function.

Description

description

Optional[str]

Description of the function. Defaults to the docstring of the function if present. If no docstring, defaults to an empty string.

Parameters

params

Optional[dict]

Optional descriptions of the parameters.

Strict Mode

strict

bool

Whether or not all the parameters are required.

Last updated