Quickstart

Agent SDK Quickstart

Getting Agents

To start, you can initialize the RedbirdAgentSDK object with your Redbird user_id and project_folder_id. These can be obtained from the Redbird platform. Once the SDK is loaded, you can retrieve the list of available Agents using the get_agent_list function.

IMPORTANT

Note You must run the sdk.get_agent_list() function before attempting to get any agents to ensure the agent is up-to-date.

sdk = RedbirdAgentSDK(<<user_id>>, <<project_folder_id>>)
sdk.get_agent_list()

This should return something like the following for each agent. This is using the Redbird Autotagging Agent as an example, but you may see a long list of all available agents:

{
    'id': 19,
    'name': 'Autotagger Agent',
    'description': 'Agent that can run AI-based Autotagging',
    'requirements': [{'name': 'Dataset to be Tagged',
                'object': None,
                'raw_text': None,
                'required': True,
                'class_type': 'Dataset',
                'dependency': None,
                'graph_name': 'base_dataset_id',
                'graph_type': 'int',
                'description': 'Select the input data dataset for the agent',
                'field_options': None,
                'validation_requirement': None},
                {'name': 'Column to be Tagged',
                'object': None,
                'raw_text': None,
                'required': True,
                'class_type': 'Column',
                'dependency': 'Dataset to be Tagged',
                'graph_name': 'column_name',
                'graph_type': 'str',
                'description': 'Select the input data column for the agent',
                'field_options': None,
                'validation_requirement': None}
    }]
}

You can then reference the agent by name or by ID. Both of the following lines do the same thing:

>>> agent = sdk.get_agent(19)
>>> agent = sdk.get_agent_by_name('Autotagger Agent')

Getting and Setting Requirements

We can quickly generate a sample dataset to demonstrating setting agent requirements. Using the following console command, create a file called “test_input.csv”:

echo "Call,Type of Call\nHello,Greeting\nGoodbye,Farewell\nAloha,Greeting\nKonnichiwa,Greeting\n" > test_input.csv

Now we need to see what kinds of requirements the Autotagger Agent expects. A convenient way to list all mandatory requirements for an agent would be something like:

>>> agent = sdk.get_agent_by_name('Autotagger Agent')
>>> [(x['name'], x['class_type']) for x in agent.get_requirements() if x['required']]
[('Dataset to be Tagged', 'Dataset'), ('Column to be Tagged', 'Column'), ('Tagging Instructions', None), ('Number of Tags', 'Numeric')]

In the output above, we have four mandatory requirements to set, with the following type requirements: : * Dataset to be Tagged [Dataset]

  • Column to be Tagged [Column]
  • Tagging Instructions [None]
  • Number of Tags [Numeric]

The dataset type can be provided as files or csv-like strings, while the Column type expects a string, None has no requirement on the input, and the Numeric type expects a numeric value. The full breakdown of type requirements can be found in the requirement types section.

Then, we can set our requirements for the agent using the following structure:

>>> my_requirements = [
    {'name': 'Dataset to be Tagged', 'files': 'test_input.csv'},
    {'name': 'Column to be Tagged', 'value': 'Call'},
    {'name': 'Tagging Instructions', 'value': 'Tag all rows with either "Arriving" or "Leaving" depending on the context of the provided keyword'},
    {'name': 'Number of Tags', 'value': 2}]
>>> agent.populate_requirements(requirements=my_requirements)
{'Dataset to be Tagged': 304, 'Column to be Tagged': 'Call', 'Tagging Instructions': 'Tag all rows with either "Arriving" or "Leaving" depending on the context of the provided keyword', 'Number of Tags': 2}
True

You can see the agent responded with the approved and validated values for each requirement. For example, the filepath was automatically converted into a Redbird Dataset, with a Dataset ID of 304, whereas the other input requirements were left as-is.

Running the Agents

From here, we can run the agent:

>>> agent.run()
True

The agent responds with True if it successfully initiates the Agent task on the Redbird platform, else it responds with a Warning or Error.

In order to retrieve the job outputs, you’ll need to poll the Redbird server until the job is finished. You can do this with a simple while loop:

>>> while not agent.retrieve_results():
        time.sleep(10)

Once this returns True, your data will be loaded into the agent object automatically for use downstream.

Finally, we can extract our output. The Autotagger Agent generates a dataset that we can parse in a variety of ways. Here’s an example of retrieving a Pandas dataframe:

>>> df = agent.output_objects[0].get_dataframe()
>>> df
        Call Type of Call              Level 1 Tag
0       Hello     Greeting             ['arriving']
1     Goodbye     Farewell              ['leaving']
2       Aloha     Greeting  ['arriving', 'leaving']
3  Konnichiwa     Greeting             ['arriving']

The Level 1 Tag has been applied to the dataset row by row.

From here, the same strategies can be applied to other agents, or chained together into custom scripts that leverage a series of Redbird Agents to accomplish more complicated tasks.


What’s Next