Skip to main content

Metadata

Summary

info

The following is a short reminder of what was previously described in the Getting Started part.

The Agent Class features various metadata (attributes), used to identify and describe him.

By default, an Agent has 4 attributes, specified in the file base.py.

  • NAME: Agent Name
  • ACTIVATED: Whether this agent is enabled or not, False by default
  • VERSION: Version, used for Agent versionning
  • MISSION: Short description for its mission, its usage

Every Agent inherits the attributes of the Base Class. You can override these attributes by redefining them within the Agent Class.

agents/my-parser.py
class MyParserAgent(Base):
NAME = "MyParser"
ACTIVATED = True
VERSION = "1.0"
MISSION = "Yet another parser to parse awesome stuff"

Adding Metadata

To add metadata (attribute), you have two options: globally or within the Agent. This is about attribute's Scope.

To add an attribute globally, with repercussions in every Agent, add it to the Base Class, located on agents/base.py.

base.py
class Base(ABC):
NAME = "Base Agent"
ACTIVATED = False
VERSION = "0.0"
MISSION = "No description"
FILE = None
YOUR_ATTRIBUTE = "HELLO WORLD!" # New attribute

Access the attribute using self.YOUR_ATTRIBUTE in your Agent.

tip

As seen previously, you don't need to override an attribute if you just want its value.
For instance, you can access self.YOUR_ATTRIBUTE within your Agent without declaring it in its attributes.

agents/my-parser.py
class MyParserAgent(Base):
NAME = "MyParser"
ACTIVATED = True
VERSION = "1.0"
MISSION = "Yet another parser to parse awesome stuff"
FILE = None

def mission(self):
self.YOUR_ATTRIBUTE # You can access YOUR_ATTRIBUTE here, declared only in Base Class

You can however declare it within the Agent Class to override the value in the Base Class.

Real-World Example

In this real-world example, we will create a global attribute called EXTENSIONS.

warning

To introduce only concept at a time, we will filter within the Agent mission using the attribute.
Please refer to Captain Filtering Agents to optimize the filtering of Agents based on their attributes: Captain should do the filtering.


Add the attribute to the Base Class.

agents/base.py
class Base(ABC):
NAME = "Base Agent"
ACTIVATED = False
VERSION = "0.0"
MISSION = "No description"
EXTENSIONS = None

By default, Agent will inherits the attribute EXTENSIONS with value None, meaning they can parse any file type.
If an Agent can only process specific file type, we will override the EXTENSIONS attribute from within Agent.

If your Agent can process every file type, don't redeclare EXTENSIONS attribute.

agents/my-parser.py
class MyParserAgent(Base):
NAME = "MyParser"
ACTIVATED = True
VERSION = "1.0"
MISSION = "Yet another parser to parse awesome stuff"
FILE = None